|
| 1 | +# Copyright 2026 The Fuchsia Authors |
| 2 | +# |
| 3 | +# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 4 | +# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 5 | +# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 6 | +# This file may not be copied, modified, or distributed except according to |
| 7 | +# those terms. |
| 8 | + |
| 9 | +name: Anneal Release |
| 10 | + |
| 11 | +on: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + paths: |
| 16 | + - 'anneal/Cargo.toml' |
| 17 | + |
| 18 | +permissions: {} |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: anneal-release |
| 22 | + cancel-in-progress: false |
| 23 | + |
| 24 | +jobs: |
| 25 | + check-version: |
| 26 | + name: Check if version was updated |
| 27 | + runs-on: ubuntu-latest |
| 28 | + # Don't run this on forks. |
| 29 | + if: github.repository == 'google/zerocopy' |
| 30 | + outputs: |
| 31 | + changed: ${{ steps.check.outputs.changed }} |
| 32 | + version: ${{ steps.check.outputs.version }} |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 36 | + with: |
| 37 | + persist-credentials: false |
| 38 | + fetch-depth: 0 |
| 39 | + |
| 40 | + - name: Determine if version was updated |
| 41 | + id: check |
| 42 | + run: | |
| 43 | + set -eo pipefail |
| 44 | + cd anneal |
| 45 | + |
| 46 | + CUR_VER=$(cargo metadata -q --format-version 1 | jq -r '.packages[] | select(.name == "cargo-anneal").version') |
| 47 | + |
| 48 | + git checkout -q HEAD^ |
| 49 | + PREV_VER=$(cargo metadata -q --format-version 1 | jq -r '.packages[] | select(.name == "cargo-anneal").version') |
| 50 | + git checkout -q - |
| 51 | + |
| 52 | + if [ "$CUR_VER" != "$PREV_VER" ]; then |
| 53 | + echo "Version change detected." |
| 54 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 55 | + echo "version=$CUR_VER" >> $GITHUB_OUTPUT |
| 56 | + else |
| 57 | + echo "Version unchanged." |
| 58 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 59 | + fi |
| 60 | +
|
| 61 | + release: |
| 62 | + name: Release to crates.io and GitHub |
| 63 | + needs: check-version |
| 64 | + if: needs.check-version.outputs.changed == 'true' |
| 65 | + runs-on: ubuntu-latest |
| 66 | + environment: release |
| 67 | + permissions: |
| 68 | + contents: write # required to create a git tag and a GitHub Release |
| 69 | + id-token: write # required to publish to crates.io using OIDC |
| 70 | + steps: |
| 71 | + - name: Checkout |
| 72 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 73 | + with: |
| 74 | + persist-credentials: false |
| 75 | + fetch-depth: 0 |
| 76 | + |
| 77 | + - name: Publish cargo-anneal |
| 78 | + run: | |
| 79 | + set -eo pipefail |
| 80 | + cd anneal |
| 81 | + # Temporarily disable vendoring |
| 82 | + mv .cargo/config.toml .cargo/config.toml.bak |
| 83 | + cargo publish --allow-dirty --registry crates-io |
| 84 | + mv .cargo/config.toml.bak .cargo/config.toml |
| 85 | +
|
| 86 | + - name: Create git tag |
| 87 | + env: |
| 88 | + VERSION: ${{ needs.check-version.outputs.version }} |
| 89 | + GH_TOKEN: ${{ github.token }} |
| 90 | + GH_REPO: ${{ github.repository }} |
| 91 | + run: | |
| 92 | + set -eo pipefail |
| 93 | + TAG="anneal-v$VERSION" |
| 94 | + git config user.name "Google PR Creation Bot" |
| 95 | + git config user.email "[email protected]" |
| 96 | + git tag -a "$TAG" -m "Release $TAG" |
| 97 | + git push https://x-access-token:[email protected]/$GH_REPO.git "$TAG" |
| 98 | +
|
| 99 | + - name: Create GitHub Release |
| 100 | + env: |
| 101 | + VERSION: ${{ needs.check-version.outputs.version }} |
| 102 | + GH_TOKEN: ${{ github.token }} |
| 103 | + run: | |
| 104 | + set -eo pipefail |
| 105 | + TAG="anneal-v$VERSION" |
| 106 | + gh release create "$TAG" --generate-notes |
0 commit comments