fix(release): add multi-arch/platform support #23
This file contains 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: "Testing" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- "**" | |
pull_request: | |
branches: | |
- "**" | |
permissions: | |
contents: write | |
defaults: | |
run: | |
shell: bash | |
concurrency: | |
group: "${{ github.workflow }}@${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" | |
jobs: | |
test: | |
name: Test | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
arch: [amd64, arm64] | |
runs-on: ${{ matrix.os }} | |
env: | |
CACHE_PATH: ${{ matrix.os == 'macos-latest' && '/private/var/tmp/_bazel_runner/' || '~/.cache/bazel' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Bazel | |
uses: bazel-contrib/setup-bazel@0.8.5 | |
with: | |
bazelisk-cache: true | |
disk-cache: ${{ github.workflow }} | |
repository-cache: true | |
- name: Cache Bazel | |
uses: actions/cache@v4 | |
with: | |
path: ${{ env.CACHE_PATH }} | |
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'MODULE.bazel') }} | |
restore-keys: | | |
${{ runner.os }}-bazel- | |
- name: Determine Bazel platform | |
id: platform | |
run: | | |
os="${{ runner.os }}" | |
platform="linux" | |
case "$os" in | |
Windows) platform="windows" ;; | |
macOS) platform="darwin" ;; | |
esac | |
final=$(printf "@io_bazel_rules_go//go/toolchain:%s_%s" "$platform" ${{ matrix.arch }}) | |
echo "platform=$final" >> "$GITHUB_OUTPUT" | |
- name: Build Bazel artifacts | |
run: | | |
bazel --output_user_root=${{ env.CACHE_PATH }} build --platforms=${{ steps.platform.outputs.platform }} //... | |
- name: Test Bazel artifacts | |
run: | | |
bazel --output_user_root=${{ env.CACHE_PATH }} test --platforms=${{ steps.platform.outputs.platform }} //... | |
# Fail here if tests didn't succeed | |
- name: Generate Release artifacts | |
if: ${{ success() }} | |
run: | | |
scripts/release.sh executables | |
scripts/release.sh tarballs | |
- name: Upload Release artifacts | |
if: ${{ success() }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: distributables | |
path: | | |
dist/*.tar.gz | |
dist/*.txt | |
dispatch: | |
runs-on: ubuntu-latest | |
needs: [test] | |
steps: | |
- name: Dispatch a release workflow run | |
if: ${{ !failure() }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const payload = { | |
run_id: "${{ github.run_id }}", | |
sha: "${{ github.sha }}" | |
} | |
console.log("Sending event payload", JSON.stringify(payload, null, 2)); | |
const { owner, repo } = context.repo; | |
await github.rest.repos.createDispatchEvent({ | |
owner, | |
repo, | |
event_type: 'release', | |
client_payload: payload | |
}); |