diff --git a/.gitea/workflows/release-app.yaml b/.gitea/workflows/release-app.yaml new file mode 100644 index 0000000..05f31c1 --- /dev/null +++ b/.gitea/workflows/release-app.yaml @@ -0,0 +1,144 @@ +name: Release App + +on: + workflow_dispatch: + push: + branches: + - main + +permissions: + contents: write + +jobs: + release-app: + runs-on: ubuntu-latest + env: + RELEASE_TAG: latest + ARCHIVE_NAME: shinoa-linux-x86_64.tar.gz + CHECKSUM_NAME: shinoa-linux-x86_64.tar.gz.sha256 + steps: + - name: Check out repository + uses: https://github.com/actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install build dependencies + run: | + if command -v sudo >/dev/null 2>&1; then + SUDO=sudo + else + SUDO= + fi + + $SUDO apt-get update + $SUDO apt-get install -y \ + build-essential \ + ca-certificates \ + cmake \ + curl \ + git \ + gperf \ + jq \ + libssl-dev \ + patchelf \ + pkg-config \ + zlib1g-dev + + - name: Build release bundle + run: | + set -euo pipefail + rm -rf build dist + + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build -j"$(nproc)" + + install -dm755 dist/usr/bin dist/usr/lib dist/usr/share/doc/shinoa + install -m755 build/shinoa dist/usr/bin/shinoa + install -m755 build/_deps/tdlib-build/libtdjson.so.1.8.63 \ + dist/usr/lib/libtdjson.so.1.8.63 + ln -sf libtdjson.so.1.8.63 dist/usr/lib/libtdjson.so + install -m644 README.md dist/usr/share/doc/shinoa/README.md + + patchelf --remove-rpath dist/usr/bin/shinoa + + tar -C dist -czf "$ARCHIVE_NAME" usr + sha256sum "$ARCHIVE_NAME" > "$CHECKSUM_NAME" + + - name: Create or update release + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + run: | + set -euo pipefail + api="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}" + commit_sha="${{ github.sha }}" + release_json="$(mktemp)" + body_file="$(mktemp)" + + cat > "$body_file" <&2 + cat "$release_json" >&2 + exit 1 + fi + + status="$(curl --silent --show-error \ + --output /dev/null \ + --write-out "%{http_code}" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -X DELETE \ + "$api/tags/$RELEASE_TAG")" + case "$status" in + 204|404) ;; + *) + echo "Failed to delete tag $RELEASE_TAG, HTTP $status" >&2 + exit 1 + ;; + esac + + curl --fail-with-body \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -X POST \ + -d @- \ + "$api/releases" > "$release_json" <