better release body #12
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 Cargo-bazel | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - scuffle-fork | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| builds: | |
| strategy: | |
| matrix: | |
| include: | |
| - runner: ubuntu-22.04 | |
| os: linux | |
| arch: x86_64 | |
| - runner: ubuntu-22.04-arm | |
| os: linux | |
| arch: aarch64 | |
| - runner: windows-2022 | |
| os: windows | |
| arch: x86_64 | |
| - runner: windows-11-arm | |
| os: windows | |
| arch: aarch64 | |
| - runner: macos-13 | |
| os: darwin | |
| arch: x86_64 | |
| - runner: macos-14 | |
| os: darwin | |
| arch: aarch64 | |
| runs-on: ${{ matrix.runner }} | |
| env: | |
| NAME: "cargo-bazel-${{ matrix.os }}-${{ matrix.arch }}" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install zstd | |
| if: ${{ runner.os == 'Windows' }} | |
| uses: MinoruSekine/setup-scoop@v4.0.2 | |
| with: | |
| buckets: main | |
| apps: zstd | |
| - name: Install rust toolchains for host | |
| run: | | |
| version="$(grep 'DEFAULT_RUST_VERSION =' ./rust/private/common.bzl | grep -o '[[:digit:].]\+')" | |
| rustup install "${version}" | |
| rustup override set "${version}" | |
| - name: Build cargo-bazel | |
| run: cargo build -r -p cargo-bazel | |
| working-directory: ./crate_universe | |
| - name: Generate archive with BUILD | |
| run: | | |
| mkdir -p artifacts-archive | |
| BIN_NAME="cargo-bazel${{ runner.os == 'Windows' && '.exe' || '' }}" | |
| mkdir -p "${NAME}" | |
| cp "./crate_universe/target/release/$BIN_NAME" "${NAME}/" | |
| cat > "${NAME}/BUILD" <<EOF | |
| exports_files(["${BIN_NAME}"]) | |
| load("@rules_shell//shell:sh_binary.bzl", "sh_binary") | |
| sh_binary( | |
| name = "bin", | |
| srcs = ["${BIN_NAME}"], | |
| visibility = ["//visibility:public"], | |
| ) | |
| EOF | |
| tar -cf - "${NAME}" | zstd --ultra -22 -o "artifacts-archive/$NAME.tar.zst" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.NAME }} | |
| path: artifacts-archive/${{ env.NAME }}.tar.zst | |
| release: | |
| needs: builds | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: write | |
| env: | |
| TAG_NAME: commit-${{ github.sha }} | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ./artifacts | |
| - name: Generate release body | |
| run: | | |
| set -euo pipefail | |
| shopt -s globstar # enable recursive globbing | |
| echo '```bazel' > release_body.txt | |
| cat >> release_body.txt <<EOF | |
| bazel_dep(name = "rules_rust") | |
| git_override( | |
| module_name = "rules_rust", | |
| commit = "${{ github.sha }}", | |
| remote = "https://github.com/${{ github.repository }}.git", | |
| ) | |
| http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | |
| cargo_bazel_url = "https://github.com/${{ github.repository }}/releases/download/${{ env.TAG_NAME }}/" | |
| EOF | |
| echo '' >> release_body.txt | |
| for archive in ./artifacts/**/*.tar.zst; do | |
| FILE_NAME=$(basename "$archive") | |
| SHA=$(sha256sum "$archive" | awk '{print $1}') | |
| NAME="${FILE_NAME%.tar.zst}" | |
| cat >> release_body.txt <<EOF | |
| http_archive( | |
| name = "$NAME", | |
| sha256 = "$SHA", | |
| strip_prefix = "$NAME", | |
| url = cargo_bazel_url + "$FILE_NAME", | |
| ) | |
| EOF | |
| echo '' >> release_body.txt | |
| done | |
| echo '```' >> release_body.txt | |
| cat release_body.txt | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.TAG_NAME }} | |
| name: "cargo-bazel build for ${{ github.sha }}" | |
| body_path: release_body.txt | |
| files: ./artifacts/**/*.tar.zst | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |