|
| 1 | +name: Build / Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + prepare: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + version: ${{ steps.version.outputs.version }} |
| 18 | + should_release: ${{ steps.check.outputs.should_release }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Read version from Cargo.toml |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + VERSION=$(grep '^version' Cargo.toml | sed 's/.*= "\(.*\)"/\1/') |
| 27 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 28 | +
|
| 29 | + - name: Check if release exists |
| 30 | + id: check |
| 31 | + env: |
| 32 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + run: | |
| 34 | + TAG="v${{ steps.version.outputs.version }}" |
| 35 | + if gh release view "$TAG" >/dev/null 2>&1; then |
| 36 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 37 | + else |
| 38 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Create and push tag |
| 42 | + if: steps.check.outputs.should_release == 'true' |
| 43 | + run: | |
| 44 | + TAG="v${{ steps.version.outputs.version }}" |
| 45 | + git tag "$TAG" |
| 46 | + git push origin "$TAG" |
| 47 | +
|
| 48 | + build-release: |
| 49 | + needs: prepare |
| 50 | + if: needs.prepare.outputs.should_release == 'true' |
| 51 | + name: ${{ matrix.targets.alias }} |
| 52 | + runs-on: ${{ matrix.targets.os }} |
| 53 | + |
| 54 | + strategy: |
| 55 | + fail-fast: false |
| 56 | + matrix: |
| 57 | + targets: |
| 58 | + - { os: macos-latest, target: aarch64-apple-darwin, alias: aarch64-apple-darwin } |
| 59 | + - { os: macos-latest, target: x86_64-apple-darwin, alias: x86_64-apple-darwin } |
| 60 | + - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, alias: x86_64-unknown-linux-gnu } |
| 61 | + - { os: ubuntu-latest, target: x86_64-unknown-linux-musl,alias: x86_64-unknown-linux-musl} |
| 62 | + - { os: windows-latest, target: x86_64-pc-windows-msvc, alias: x86_64-pc-windows-msvc } |
| 63 | + |
| 64 | + steps: |
| 65 | + - uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + fetch-depth: 0 |
| 68 | + |
| 69 | + - uses: dsherret/rust-toolchain-file@v1 |
| 70 | + |
| 71 | + - name: Setup musl-tools |
| 72 | + if: matrix.targets.target == 'x86_64-unknown-linux-musl' |
| 73 | + shell: bash |
| 74 | + run: sudo apt -y install musl-tools |
| 75 | + |
| 76 | + - name: Add target |
| 77 | + uses: ./.github/actions/add-target |
| 78 | + with: |
| 79 | + target: ${{ matrix.targets.target }} |
| 80 | + |
| 81 | + - name: Setup Rust cache |
| 82 | + uses: Swatinem/rust-cache@v2 |
| 83 | + with: |
| 84 | + prefix-key: ${{ matrix.targets.alias }} |
| 85 | + |
| 86 | + - name: Run build |
| 87 | + uses: ./.github/actions/build |
| 88 | + with: |
| 89 | + target: ${{ matrix.targets.target }} |
| 90 | + release: true |
| 91 | + |
| 92 | + - name: Archive binary |
| 93 | + uses: ./.github/actions/make-archive |
| 94 | + with: |
| 95 | + files: ./target/${{ matrix.targets.target }}/release/cnb${{ matrix.targets.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }} |
| 96 | + out: cnb-${{ needs.prepare.outputs.version }}-${{ matrix.targets.target }}.zip |
| 97 | + |
| 98 | + - name: Create GitHub release |
| 99 | + uses: softprops/action-gh-release@v2 |
| 100 | + with: |
| 101 | + tag_name: v${{ needs.prepare.outputs.version }} |
| 102 | + files: cnb-${{ needs.prepare.outputs.version }}-${{ matrix.targets.target }}.zip |
0 commit comments