fix(ci): fix release race condition, remove softprops action #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: write | |
| jobs: | |
| create-release: | |
| name: Create release | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Create draft release | |
| run: | | |
| gh release create "$GITHUB_REF_NAME" \ | |
| --title "$GITHUB_REF_NAME" \ | |
| --draft \ | |
| --generate-notes | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build: | |
| name: Build ${{ matrix.target }} | |
| needs: create-release | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: macos-14 | |
| target: aarch64-apple-darwin | |
| use_cross: false | |
| - os: macos-15 | |
| target: x86_64-apple-darwin | |
| use_cross: false | |
| - os: ubuntu-22.04 | |
| target: x86_64-unknown-linux-gnu | |
| use_cross: false | |
| - os: ubuntu-22.04 | |
| target: aarch64-unknown-linux-gnu | |
| use_cross: true | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Cache cargo registry | |
| uses: actions/cache@v5 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target/ | |
| key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ matrix.target }}-cargo- | |
| - name: Install cross | |
| if: matrix.use_cross | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Build (native) | |
| if: "!matrix.use_cross" | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Build (cross) | |
| if: matrix.use_cross | |
| run: cross build --release --target ${{ matrix.target }} | |
| - name: Package binary | |
| shell: bash | |
| run: | | |
| ARCHIVE="krait-${{ matrix.target }}.tar.gz" | |
| tar czf "$ARCHIVE" -C "target/${{ matrix.target }}/release" krait | |
| echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: krait-${{ matrix.target }} | |
| path: ${{ env.ARCHIVE }} | |
| retention-days: 1 | |
| upload-release: | |
| name: Upload release assets | |
| needs: build | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| merge-multiple: true | |
| - name: Upload binaries and publish release | |
| run: | | |
| gh release upload "$GITHUB_REF_NAME" artifacts/*.tar.gz \ | |
| --repo "$GITHUB_REPOSITORY" | |
| gh release edit "$GITHUB_REF_NAME" \ | |
| --draft=false \ | |
| --prerelease=${{ contains(github.ref_name, '-') }} \ | |
| --repo "$GITHUB_REPOSITORY" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| publish: | |
| name: Publish to crates.io | |
| needs: upload-release | |
| runs-on: ubuntu-22.04 | |
| if: "!contains(github.ref_name, '-')" | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Publish | |
| run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| homebrew: | |
| name: Update Homebrew formula | |
| needs: upload-release | |
| runs-on: ubuntu-22.04 | |
| if: "!contains(github.ref_name, '-')" | |
| steps: | |
| - name: Download release assets and compute SHAs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${GITHUB_REF_NAME#v}" | |
| echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
| for target in aarch64-apple-darwin x86_64-apple-darwin aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu; do | |
| ASSET="krait-${target}.tar.gz" | |
| gh release download "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --pattern "$ASSET" --dir /tmp/dl | |
| SHA=$(sha256sum "/tmp/dl/$ASSET" | awk '{print $1}') | |
| ENV_NAME="SHA_$(echo "$target" | tr '[:lower:]-' '[:upper:]_')" | |
| echo "${ENV_NAME}=${SHA}" >> "$GITHUB_ENV" | |
| done | |
| - name: Generate formula | |
| run: | | |
| cat > /tmp/krait.rb <<FORMULA | |
| class Krait < Formula | |
| desc "Code intelligence CLI for AI agents — LSP-backed symbol search and semantic editing" | |
| homepage "https://github.com/Codestz/krait" | |
| version "${VERSION}" | |
| license "MIT" | |
| on_macos do | |
| if Hardware::CPU.arm? | |
| url "https://github.com/Codestz/krait/releases/download/v#{version}/krait-aarch64-apple-darwin.tar.gz" | |
| sha256 "${SHA_AARCH64_APPLE_DARWIN}" | |
| else | |
| url "https://github.com/Codestz/krait/releases/download/v#{version}/krait-x86_64-apple-darwin.tar.gz" | |
| sha256 "${SHA_X86_64_APPLE_DARWIN}" | |
| end | |
| end | |
| on_linux do | |
| if Hardware::CPU.arm? | |
| url "https://github.com/Codestz/krait/releases/download/v#{version}/krait-aarch64-unknown-linux-gnu.tar.gz" | |
| sha256 "${SHA_AARCH64_UNKNOWN_LINUX_GNU}" | |
| else | |
| url "https://github.com/Codestz/krait/releases/download/v#{version}/krait-x86_64-unknown-linux-gnu.tar.gz" | |
| sha256 "${SHA_X86_64_UNKNOWN_LINUX_GNU}" | |
| end | |
| end | |
| def install | |
| bin.install "krait" | |
| end | |
| def caveats | |
| <<~EOS | |
| krait auto-installs language servers on first use. | |
| Run `krait init` in your project to generate a workspace config. | |
| TypeScript: npm install -g @vtsls/language-server | |
| Go: go install golang.org/x/tools/gopls@latest | |
| Rust: rustup component add rust-analyzer | |
| EOS | |
| end | |
| test do | |
| assert_match version.to_s, shell_output("#{bin}/krait --version") | |
| end | |
| end | |
| FORMULA | |
| sed -i 's/^ //' /tmp/krait.rb | |
| - name: Push formula to homebrew tap | |
| env: | |
| TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| run: | | |
| set -e | |
| CONTENT=$(base64 -w 0 /tmp/krait.rb) | |
| FILE_SHA=$(curl -s \ | |
| -H "Authorization: token $TAP_TOKEN" \ | |
| "https://api.github.com/repos/Codestz/homebrew-krait/contents/Formula/krait.rb" \ | |
| | jq -r '.sha // empty') | |
| if [ -n "$FILE_SHA" ]; then | |
| PAYLOAD="{\"message\":\"chore: bump to v${VERSION}\",\"content\":\"${CONTENT}\",\"sha\":\"${FILE_SHA}\"}" | |
| else | |
| PAYLOAD="{\"message\":\"chore: add formula for v${VERSION}\",\"content\":\"${CONTENT}\"}" | |
| fi | |
| curl -sf -X PUT \ | |
| -H "Authorization: token $TAP_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| "https://api.github.com/repos/Codestz/homebrew-krait/contents/Formula/krait.rb" \ | |
| -d "$PAYLOAD" | |
| echo "Homebrew tap updated to v${VERSION}" |