diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4626f42..74cd571 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,66 +1,72 @@ name: Release on: - push: - tags: - - "v[0-9]+.[0-9]+.[0-9]+" + pull_request: + types: [closed] + branches: [main] + workflow_dispatch: permissions: contents: read concurrency: - group: release-${{ github.ref_name }} + group: release cancel-in-progress: false env: CARGO_TERM_COLOR: always jobs: - test: - name: Test - uses: ./.github/workflows/ci.yml - - validate: - name: Validate tag + get-tag: + name: Find draft release + if: (github.event_name == 'pull_request' && github.head_ref == 'knope/release' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch' runs-on: ubuntu-24.04 + permissions: + contents: write outputs: - version: ${{ steps.version.outputs.version }} + tag: ${{ steps.find.outputs.tag }} + version: ${{ steps.find.outputs.version }} steps: - uses: actions/checkout@v7 with: - fetch-depth: 0 - - uses: dtolnay/rust-toolchain@stable - - name: Verify version and main branch - id: version + ref: main + - name: Find Knope draft release + id: find shell: bash + env: + GH_TOKEN: ${{ github.token }} run: | set -euo pipefail - tag="${GITHUB_REF_NAME}" - if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Tag $tag is not a stable semantic version (vX.Y.Z)." >&2 - exit 1 - fi + package_version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)" - version="${tag#v}" - package_version="$(cargo metadata --no-deps --format-version 1 \ - | jq -r '.packages[] | select(.name == "android-cli-gui") | .version')" - if [[ "$package_version" != "$version" ]]; then - echo "Tag $tag does not match Cargo.toml version $package_version." >&2 - exit 1 - fi + for attempt in $(seq 1 30); do + tag="$(gh release list --repo "$GITHUB_REPOSITORY" --limit 20 \ + --json isDraft,tagName \ + --jq '[.[] | select(.isDraft and (.tagName | startswith("v")))][0].tagName // ""')" - git fetch --no-tags origin main - if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then - echo "Tag $tag is not on main." >&2 - exit 1 - fi + if [[ -n "$tag" ]]; then + if [[ "${tag#v}" == "$package_version" ]]; then + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "version=${tag#v}" >> "$GITHUB_OUTPUT" + echo "Found draft release $tag." + exit 0 + fi + echo "Draft release $tag does not match Cargo.toml version $package_version; waiting..." + else + echo "No draft release yet (attempt $attempt/30); waiting 10s..." + fi + + sleep 10 + done - echo "version=$version" >> "$GITHUB_OUTPUT" + echo "No draft release found. Install Knope Bot and merge its release PR first." >&2 + exit 1 build: name: Build (${{ matrix.target }}) - needs: validate + needs: get-tag + if: needs.get-tag.outputs.tag != '' strategy: fail-fast: false matrix: @@ -79,9 +85,12 @@ jobs: artifact: windows-x86_64 runs-on: ${{ matrix.os }} env: + VERSION: ${{ needs.get-tag.outputs.version }} MACOSX_DEPLOYMENT_TARGET: "15.0" steps: - uses: actions/checkout@v7 + with: + ref: ${{ needs.get-tag.outputs.tag }} - name: Install Linux dependencies if: runner.os == 'Linux' uses: ./.github/actions/linux-deps @@ -99,16 +108,14 @@ jobs: shell: bash run: | set -euo pipefail - version="${GITHUB_REF_NAME#v}" - asset="android-cli-gui-v${version}-${{ matrix.target }}.tar.gz" + asset="android-cli-gui-v${VERSION}-${{ matrix.target }}.tar.gz" mkdir -p dist tar -C "target/${{ matrix.target }}/release" -czf "dist/${asset}" android-cli-gui - name: Package (Windows) if: runner.os == 'Windows' shell: pwsh run: | - $version = $env:GITHUB_REF_NAME -replace '^v', '' - $asset = "android-cli-gui-v$version-${{ matrix.target }}.zip" + $asset = "android-cli-gui-v$($env:VERSION)-${{ matrix.target }}.zip" New-Item -ItemType Directory -Force -Path dist | Out-Null Compress-Archive -Path "target/${{ matrix.target }}/release/android-cli-gui.exe" -DestinationPath "dist/$asset" - uses: actions/upload-artifact@v7 @@ -117,9 +124,10 @@ jobs: path: dist/* if-no-files-found: error - release: - name: Publish GitHub release - needs: [test, build] + publish: + name: Upload assets and publish + needs: [get-tag, build] + if: needs.get-tag.outputs.tag != '' runs-on: ubuntu-24.04 permissions: contents: write @@ -128,27 +136,31 @@ jobs: with: path: dist merge-multiple: true - - name: Write checksums + - name: Upload assets and publish shell: bash + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TAG: ${{ needs.get-tag.outputs.tag }} run: | set -euo pipefail cd dist sha256sum -- * > SHA256SUMS.txt cat SHA256SUMS.txt - - uses: softprops/action-gh-release@v3 - with: - files: dist/* - fail_on_unmatched_files: true - generate_release_notes: true + gh release upload "$TAG" --clobber ./* + gh release edit "$TAG" --draft=false --latest homebrew: name: Update Homebrew tap - needs: [release, validate] + needs: [publish, get-tag] + if: needs.get-tag.outputs.tag != '' runs-on: ubuntu-24.04 permissions: contents: read steps: - uses: actions/checkout@v7 + with: + ref: ${{ needs.get-tag.outputs.tag }} - uses: actions/download-artifact@v8 with: path: dist @@ -156,7 +168,7 @@ jobs: - name: Render formula shell: bash env: - VERSION: ${{ needs.validate.outputs.version }} + VERSION: ${{ needs.get-tag.outputs.version }} run: | set -euo pipefail @@ -175,6 +187,7 @@ jobs: - name: Push formula to tap shell: bash env: + TAG: ${{ needs.get-tag.outputs.tag }} HOMEBREW_TAP_DEPLOY_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }} run: | set -euo pipefail @@ -198,6 +211,6 @@ jobs: if git -C tap diff --cached --quiet; then echo "Formula is already up to date." else - git -C tap commit -m "android-cli-gui ${GITHUB_REF_NAME}" + git -C tap commit -m "android-cli-gui ${TAG}" git -C tap push origin HEAD:main fi diff --git a/README.md b/README.md index b46f928..107fbd0 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,10 @@ Requires Rust stable and the [GPUI platform dependencies](https://gpui-kit.com/d ```sh cargo run --release ``` + +## Releases + +Releases are managed by [Knope Bot](https://knope.tech/tutorials/bot-workflow/). +Install the bot for this repository; it keeps a `knope/release` PR up to date. +Merging that PR creates a draft GitHub release, and the Release workflow builds +the binaries, uploads them, publishes the release, and updates the Homebrew tap. diff --git a/knope.toml b/knope.toml new file mode 100644 index 0000000..65d123f --- /dev/null +++ b/knope.toml @@ -0,0 +1,16 @@ +[package] +versioned_files = [ + "Cargo.toml", + { path = "Cargo.lock", dependency = "android-cli-gui" }, +] +changelog = "CHANGELOG.md" +# Knope Bot creates a draft release when assets are configured. The Release +# workflow attaches the binaries and publishes it. +assets = "marker" + +[bot.releases] +enabled = true + +[github] +owner = "RayhanHamada" +repo = "android-cli-gui"