|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + name: Build ${{ matrix.target }} |
| 17 | + runs-on: ${{ matrix.os }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - os: ubuntu-24.04 |
| 23 | + target: x86_64-unknown-linux-gnu |
| 24 | + archive_ext: tar.gz |
| 25 | + binary_name: langcodec |
| 26 | + - os: macos-13 |
| 27 | + target: x86_64-apple-darwin |
| 28 | + archive_ext: tar.gz |
| 29 | + binary_name: langcodec |
| 30 | + - os: macos-14 |
| 31 | + target: aarch64-apple-darwin |
| 32 | + archive_ext: tar.gz |
| 33 | + binary_name: langcodec |
| 34 | + - os: windows-2022 |
| 35 | + target: x86_64-pc-windows-msvc |
| 36 | + archive_ext: zip |
| 37 | + binary_name: langcodec.exe |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Install Rust (stable) |
| 43 | + uses: dtolnay/rust-toolchain@stable |
| 44 | + with: |
| 45 | + toolchain: stable |
| 46 | + targets: ${{ matrix.target }} |
| 47 | + |
| 48 | + - name: Build release binary |
| 49 | + run: cargo build --release -p langcodec-cli --target ${{ matrix.target }} |
| 50 | + |
| 51 | + - name: Package artifact (Unix) |
| 52 | + if: runner.os != 'Windows' |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + version="${GITHUB_REF_NAME}" |
| 57 | + archive="langcodec-${version}-${{ matrix.target }}.${{ matrix.archive_ext }}" |
| 58 | + binary_dir="dist/langcodec-${version}-${{ matrix.target }}" |
| 59 | + mkdir -p "${binary_dir}" |
| 60 | + cp "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "${binary_dir}/langcodec" |
| 61 | + tar -C dist -czf "${archive}" "langcodec-${version}-${{ matrix.target }}" |
| 62 | + shasum -a 256 "${archive}" > "${archive}.sha256" |
| 63 | +
|
| 64 | + - name: Package artifact (Windows) |
| 65 | + if: runner.os == 'Windows' |
| 66 | + shell: pwsh |
| 67 | + run: | |
| 68 | + $version = $env:GITHUB_REF_NAME |
| 69 | + $folder = "langcodec-$version-${{ matrix.target }}" |
| 70 | + $archive = "$folder.${{ matrix.archive_ext }}" |
| 71 | + New-Item -ItemType Directory -Force -Path "dist/$folder" | Out-Null |
| 72 | + Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" "dist/$folder/langcodec.exe" |
| 73 | + Compress-Archive -Path "dist/$folder" -DestinationPath $archive |
| 74 | + $hash = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLower() |
| 75 | + "$hash $archive" | Out-File -Encoding ascii "$archive.sha256" |
| 76 | +
|
| 77 | + - name: Upload packaged artifacts |
| 78 | + uses: actions/upload-artifact@v4 |
| 79 | + with: |
| 80 | + name: release-${{ matrix.target }} |
| 81 | + path: | |
| 82 | + langcodec-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive_ext }} |
| 83 | + langcodec-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive_ext }}.sha256 |
| 84 | +
|
| 85 | + release: |
| 86 | + name: Publish GitHub Release |
| 87 | + runs-on: ubuntu-24.04 |
| 88 | + needs: build |
| 89 | + |
| 90 | + steps: |
| 91 | + - name: Download packaged artifacts |
| 92 | + uses: actions/download-artifact@v4 |
| 93 | + with: |
| 94 | + path: dist |
| 95 | + merge-multiple: true |
| 96 | + |
| 97 | + - name: Publish release and upload binaries |
| 98 | + uses: softprops/action-gh-release@v2 |
| 99 | + with: |
| 100 | + generate_release_notes: true |
| 101 | + files: dist/* |
0 commit comments