|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +env: |
| 12 | + BIN_NAME: git-cmt-rs |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build and package (${{ matrix.os }} / ${{ runner.arch }}) |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Setup Rust toolchain (stable) |
| 28 | + uses: dtolnay/rust-toolchain@stable |
| 29 | + |
| 30 | + - name: Cache cargo registry + build |
| 31 | + uses: actions/cache@v4 |
| 32 | + with: |
| 33 | + path: | |
| 34 | + ~/.cargo/registry |
| 35 | + ~/.cargo/git |
| 36 | + target |
| 37 | + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
| 38 | + restore-keys: | |
| 39 | + ${{ runner.os }}-cargo- |
| 40 | +
|
| 41 | + - name: Build (release) |
| 42 | + run: cargo build --release |
| 43 | + |
| 44 | + - name: Prepare package |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + set -eu |
| 48 | + VER="${GITHUB_REF_NAME}" # e.g., v1.2.3 |
| 49 | + OS="${{ matrix.os }}" |
| 50 | + ARCH="${{ runner.arch }}" # X64, ARM64 |
| 51 | + NAME="${{ env.BIN_NAME }}-${VER}-${OS}-${ARCH}" |
| 52 | + DIST="dist" |
| 53 | + mkdir -p "${DIST}" |
| 54 | +
|
| 55 | + # Resolve binary path/name |
| 56 | + BIN="target/release/${{ env.BIN_NAME }}" |
| 57 | + if [ "$OS" = "windows-latest" ]; then |
| 58 | + BIN="target/release/${{ env.BIN_NAME }}.exe" |
| 59 | + fi |
| 60 | +
|
| 61 | + # Create a staging dir with files we want to ship |
| 62 | + STAGE="${DIST}/${NAME}" |
| 63 | + mkdir -p "${STAGE}" |
| 64 | + cp "${BIN}" "${STAGE}/" |
| 65 | + [ -f LICENSE ] && cp LICENSE "${STAGE}/" || true |
| 66 | + [ -f README.md ] && cp README.md "${STAGE}/" || true |
| 67 | +
|
| 68 | + if [ "$OS" = "windows-latest" ]; then |
| 69 | + 7z a "${DIST}/${NAME}.zip" "./${STAGE}/*" |
| 70 | + certutil -hashfile "${DIST}/${NAME}.zip" SHA256 | sed -n '2p' > "${DIST}/${NAME}.zip.sha256" |
| 71 | + else |
| 72 | + tar -C "${DIST}" -czf "${DIST}/${NAME}.tar.gz" "${NAME}" |
| 73 | + shasum -a 256 "${DIST}/${NAME}.tar.gz" | awk '{print $1}' > "${DIST}/${NAME}.tar.gz.sha256" |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Upload build artifacts |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: release-${{ matrix.os }}-${{ runner.arch }} |
| 80 | + path: dist/* |
| 81 | + if-no-files-found: error |
| 82 | + |
| 83 | + release: |
| 84 | + name: Create GitHub Release |
| 85 | + runs-on: ubuntu-latest |
| 86 | + needs: [build] |
| 87 | + |
| 88 | + steps: |
| 89 | + - name: Download all artifacts |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + pattern: release-* |
| 93 | + merge-multiple: true |
| 94 | + |
| 95 | + - name: List downloaded files |
| 96 | + run: ls -lah |
| 97 | + |
| 98 | + - name: Create/Update GitHub Release |
| 99 | + uses: softprops/action-gh-release@v2 |
| 100 | + with: |
| 101 | + tag_name: ${{ github.ref_name }} |
| 102 | + draft: false |
| 103 | + prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }} |
| 104 | + files: | |
| 105 | + *.tar.gz |
| 106 | + *.tar.gz.sha256 |
| 107 | + *.zip |
| 108 | + *.zip.sha256 |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments