|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [release] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +env: |
| 11 | + CARGO_TERM_COLOR: always |
| 12 | + |
| 13 | +jobs: |
| 14 | + changelog: |
| 15 | + name: Generate changelog |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + changelog: ${{ steps.cliff.outputs.content }} |
| 19 | + version: ${{ steps.version.outputs.version }} |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Get version from Cargo.toml |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/') |
| 30 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 31 | +
|
| 32 | + - name: Generate changelog |
| 33 | + id: cliff |
| 34 | + uses: orhun/git-cliff-action@v4 |
| 35 | + with: |
| 36 | + args: --latest --strip header |
| 37 | + env: |
| 38 | + GITHUB_REPO: ${{ github.repository }} |
| 39 | + |
| 40 | + build: |
| 41 | + name: Build (${{ matrix.target }}) |
| 42 | + runs-on: ${{ matrix.runner }} |
| 43 | + needs: [changelog] |
| 44 | + strategy: |
| 45 | + fail-fast: false |
| 46 | + matrix: |
| 47 | + include: |
| 48 | + - target: x86_64-unknown-linux-gnu |
| 49 | + runner: ubuntu-latest |
| 50 | + cross: false |
| 51 | + - target: aarch64-unknown-linux-gnu |
| 52 | + runner: ubuntu-latest |
| 53 | + cross: true |
| 54 | + - target: x86_64-apple-darwin |
| 55 | + runner: macos-latest |
| 56 | + cross: false |
| 57 | + - target: aarch64-apple-darwin |
| 58 | + runner: macos-latest |
| 59 | + cross: false |
| 60 | + - target: x86_64-pc-windows-msvc |
| 61 | + runner: windows-latest |
| 62 | + cross: false |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout |
| 66 | + uses: actions/checkout@v4 |
| 67 | + |
| 68 | + - name: Install Rust 1.93 stable |
| 69 | + uses: dtolnay/rust-toolchain@stable |
| 70 | + with: |
| 71 | + toolchain: "1.93" |
| 72 | + targets: ${{ matrix.target }} |
| 73 | + |
| 74 | + - name: Cache cargo registry |
| 75 | + uses: actions/cache@v4 |
| 76 | + with: |
| 77 | + path: | |
| 78 | + ~/.cargo/registry |
| 79 | + ~/.cargo/git |
| 80 | + key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 81 | + restore-keys: | |
| 82 | + ${{ runner.os }}-${{ matrix.target }}-cargo-registry- |
| 83 | +
|
| 84 | + - name: Install cross |
| 85 | + if: matrix.cross |
| 86 | + run: cargo install cross --locked |
| 87 | + |
| 88 | + - name: Build release binary (cross) |
| 89 | + if: matrix.cross |
| 90 | + run: cross build --release --target ${{ matrix.target }} |
| 91 | + |
| 92 | + - name: Build release binary (native) |
| 93 | + if: "!matrix.cross" |
| 94 | + run: cargo build --release --target ${{ matrix.target }} |
| 95 | + |
| 96 | + - name: Package binary (Unix) |
| 97 | + if: runner.os != 'Windows' |
| 98 | + run: | |
| 99 | + cd target/${{ matrix.target }}/release |
| 100 | + tar czf ../../../agcp-v${{ needs.changelog.outputs.version }}-${{ matrix.target }}.tar.gz agcp |
| 101 | + cd ../../.. |
| 102 | +
|
| 103 | + - name: Package binary (Windows) |
| 104 | + if: runner.os == 'Windows' |
| 105 | + shell: pwsh |
| 106 | + run: | |
| 107 | + Compress-Archive -Path "target/${{ matrix.target }}/release/agcp.exe" -DestinationPath "agcp-v${{ needs.changelog.outputs.version }}-${{ matrix.target }}.zip" |
| 108 | +
|
| 109 | + - name: Upload artifact (Unix) |
| 110 | + if: runner.os != 'Windows' |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: agcp-v${{ needs.changelog.outputs.version }}-${{ matrix.target }}.tar.gz |
| 114 | + path: agcp-v${{ needs.changelog.outputs.version }}-${{ matrix.target }}.tar.gz |
| 115 | + if-no-files-found: error |
| 116 | + |
| 117 | + - name: Upload artifact (Windows) |
| 118 | + if: runner.os == 'Windows' |
| 119 | + uses: actions/upload-artifact@v4 |
| 120 | + with: |
| 121 | + name: agcp-v${{ needs.changelog.outputs.version }}-${{ matrix.target }}.zip |
| 122 | + path: agcp-v${{ needs.changelog.outputs.version }}-${{ matrix.target }}.zip |
| 123 | + if-no-files-found: error |
| 124 | + |
| 125 | + release: |
| 126 | + name: Create GitHub release |
| 127 | + runs-on: ubuntu-latest |
| 128 | + needs: [changelog, build] |
| 129 | + steps: |
| 130 | + - name: Checkout |
| 131 | + uses: actions/checkout@v4 |
| 132 | + |
| 133 | + - name: Download all artifacts |
| 134 | + uses: actions/download-artifact@v4 |
| 135 | + with: |
| 136 | + path: artifacts |
| 137 | + merge-multiple: true |
| 138 | + |
| 139 | + - name: List artifacts |
| 140 | + run: ls -lR artifacts/ |
| 141 | + |
| 142 | + - name: Create draft release |
| 143 | + uses: softprops/action-gh-release@v2 |
| 144 | + with: |
| 145 | + tag_name: v${{ needs.changelog.outputs.version }} |
| 146 | + name: agcp v${{ needs.changelog.outputs.version }} |
| 147 | + body: ${{ needs.changelog.outputs.changelog }} |
| 148 | + draft: true |
| 149 | + files: | |
| 150 | + artifacts/agcp-v${{ needs.changelog.outputs.version }}-*.tar.gz |
| 151 | + artifacts/agcp-v${{ needs.changelog.outputs.version }}-*.zip |
| 152 | + env: |
| 153 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments