|
1 | | -name: Auto Tag |
| 1 | +name: Release |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: [main] |
6 | 6 |
|
| 7 | +env: |
| 8 | + CARGO_TERM_COLOR: always |
| 9 | + |
7 | 10 | jobs: |
8 | | - tag-if-bumped: |
9 | | - name: Create tag on version bump |
| 11 | + detect-version: |
| 12 | + name: Detect version bump |
10 | 13 | runs-on: ubuntu-latest |
11 | | - permissions: |
12 | | - contents: write |
| 14 | + outputs: |
| 15 | + tag: ${{ steps.check.outputs.tag }} |
| 16 | + bumped: ${{ steps.check.outputs.bumped }} |
13 | 17 | steps: |
14 | 18 | - uses: actions/checkout@v4 |
15 | 19 | with: |
16 | 20 | fetch-depth: 0 |
17 | 21 |
|
18 | | - - name: Detect version bump and tag |
| 22 | + - name: Check for version bump |
| 23 | + id: check |
19 | 24 | run: | |
20 | 25 | version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1) |
21 | 26 | tag="v${version}" |
| 27 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
22 | 28 |
|
23 | 29 | if git rev-parse "$tag" >/dev/null 2>&1; then |
24 | | - echo "Tag $tag already exists — no version bump detected." |
| 30 | + echo "Tag $tag already exists — no version bump." |
| 31 | + echo "bumped=false" >> "$GITHUB_OUTPUT" |
25 | 32 | else |
26 | 33 | echo "New version detected: $tag" |
27 | | - git tag "$tag" |
28 | | - git push origin "$tag" |
| 34 | + echo "bumped=true" >> "$GITHUB_OUTPUT" |
29 | 35 | fi |
| 36 | +
|
| 37 | + build-binaries: |
| 38 | + name: Binary (${{ matrix.name }}) |
| 39 | + needs: [detect-version] |
| 40 | + if: needs.detect-version.outputs.bumped == 'true' |
| 41 | + runs-on: ${{ matrix.os }} |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + include: |
| 45 | + - target: x86_64-unknown-linux-gnu |
| 46 | + os: ubuntu-latest |
| 47 | + cross: false |
| 48 | + name: exapump-linux-x86_64 |
| 49 | + - target: aarch64-unknown-linux-gnu |
| 50 | + os: ubuntu-latest |
| 51 | + cross: true |
| 52 | + name: exapump-linux-aarch64 |
| 53 | + - target: x86_64-apple-darwin |
| 54 | + os: macos-latest |
| 55 | + cross: false |
| 56 | + name: exapump-macos-x86_64 |
| 57 | + - target: aarch64-apple-darwin |
| 58 | + os: macos-latest |
| 59 | + cross: false |
| 60 | + name: exapump-macos-aarch64 |
| 61 | + - target: x86_64-pc-windows-msvc |
| 62 | + os: windows-latest |
| 63 | + cross: false |
| 64 | + name: exapump-windows-x86_64 |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Install Rust toolchain |
| 69 | + uses: dtolnay/rust-toolchain@stable |
| 70 | + with: |
| 71 | + targets: ${{ matrix.target }} |
| 72 | + |
| 73 | + - name: Install cross |
| 74 | + if: matrix.cross |
| 75 | + run: cargo install cross --locked |
| 76 | + |
| 77 | + - name: Build (cross) |
| 78 | + if: matrix.cross |
| 79 | + run: cross build --release --target ${{ matrix.target }} |
| 80 | + |
| 81 | + - name: Build (native) |
| 82 | + if: ${{ !matrix.cross }} |
| 83 | + run: cargo build --release --target ${{ matrix.target }} |
| 84 | + |
| 85 | + - name: Upload binary (unix) |
| 86 | + if: runner.os != 'Windows' |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: ${{ matrix.name }} |
| 90 | + path: target/${{ matrix.target }}/release/exapump |
| 91 | + |
| 92 | + - name: Upload binary (windows) |
| 93 | + if: runner.os == 'Windows' |
| 94 | + uses: actions/upload-artifact@v4 |
| 95 | + with: |
| 96 | + name: ${{ matrix.name }} |
| 97 | + path: target/${{ matrix.target }}/release/exapump.exe |
| 98 | + |
| 99 | + release: |
| 100 | + name: Release |
| 101 | + needs: [detect-version, build-binaries] |
| 102 | + if: needs.detect-version.outputs.bumped == 'true' |
| 103 | + runs-on: ubuntu-latest |
| 104 | + permissions: |
| 105 | + contents: write |
| 106 | + steps: |
| 107 | + - uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + fetch-depth: 0 |
| 110 | + |
| 111 | + - name: Create and push tag |
| 112 | + run: | |
| 113 | + tag="${{ needs.detect-version.outputs.tag }}" |
| 114 | + git tag "$tag" |
| 115 | + git push origin "$tag" |
| 116 | +
|
| 117 | + - name: Download all artifacts |
| 118 | + uses: actions/download-artifact@v4 |
| 119 | + with: |
| 120 | + path: artifacts |
| 121 | + |
| 122 | + - name: Prepare release assets |
| 123 | + run: | |
| 124 | + version="${{ needs.detect-version.outputs.tag }}" |
| 125 | + version="${version#v}" |
| 126 | + mkdir release-assets |
| 127 | + for dir in artifacts/exapump-*/; do |
| 128 | + name="$(basename "$dir")" |
| 129 | + versioned="${name/exapump-/exapump-${version}-}" |
| 130 | + if [ "$name" = "exapump-windows-x86_64" ]; then |
| 131 | + cp "$dir/exapump.exe" "release-assets/${versioned}.exe" |
| 132 | + else |
| 133 | + cp "$dir/exapump" "release-assets/${versioned}" |
| 134 | + chmod +x "release-assets/${versioned}" |
| 135 | + fi |
| 136 | + done |
| 137 | +
|
| 138 | + - name: Install cargo-about |
| 139 | + uses: taiki-e/install-action@v2 |
| 140 | + with: |
| 141 | + tool: cargo-about |
| 142 | + |
| 143 | + - name: Generate third-party licenses |
| 144 | + run: ./scripts/generate-licenses.sh > release-assets/third-party-licenses.txt |
| 145 | + |
| 146 | + - name: Create GitHub release |
| 147 | + uses: softprops/action-gh-release@v2 |
| 148 | + with: |
| 149 | + tag_name: ${{ needs.detect-version.outputs.tag }} |
| 150 | + generate_release_notes: true |
| 151 | + files: release-assets/* |
0 commit comments