diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ffb9e10 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,123 @@ +name: Release +on: + push: + tags: + - 'v*' +permissions: + contents: write +jobs: + build: + name: Build (${{ matrix.target }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + use_cross: false + archive_ext: tar.gz + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + use_cross: true + archive_ext: tar.gz + - os: macos-latest + target: x86_64-apple-darwin + use_cross: false + archive_ext: tar.gz + - os: macos-latest + target: aarch64-apple-darwin + use_cross: false + archive_ext: tar.gz + - os: windows-latest + target: x86_64-pc-windows-msvc + use_cross: false + archive_ext: zip + - os: windows-latest + target: aarch64-pc-windows-msvc + use_cross: false + archive_ext: zip + steps: + - name: Checkout code + uses: actions/checkout@v7 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - name: Install cross + if: matrix.use_cross + uses: taiki-e/install-action@cross + - name: Build binary + shell: bash + run: | + if [ "${{ matrix.use_cross }}" = "true" ]; then + cross build --release --target ${{ matrix.target }} + else + cargo build --release --target ${{ matrix.target }} + fi + - name: Package archive (Unix) + if: matrix.archive_ext == 'tar.gz' + shell: bash + run: | + ARCHIVE_NAME="onx-${{ github.ref_name }}-${{ matrix.target }}" + STAGE_DIR="staging/${ARCHIVE_NAME}" + mkdir -p "${STAGE_DIR}" + + cp "target/${{ matrix.target }}/release/onx" "${STAGE_DIR}/" + cp README.md LICENSE.md "${STAGE_DIR}/" + + tar -czf "${ARCHIVE_NAME}.tar.gz" -C staging "${ARCHIVE_NAME}" + sha256sum "${ARCHIVE_NAME}.tar.gz" > "${ARCHIVE_NAME}.tar.gz.sha256" + + mkdir dist + mv "${ARCHIVE_NAME}.tar.gz" "${ARCHIVE_NAME}.tar.gz.sha256" dist/ + - name: Package archive (Windows) + if: matrix.archive_ext == 'zip' + shell: pwsh + run: | + $ArchiveName = "onx-${{ github.ref_name }}-${{ matrix.target }}" + $StageDir = "staging/$ArchiveName" + New-Item -ItemType Directory -Force -Path $StageDir | Out-Null + + Copy-Item "target/${{ matrix.target }}/release/onx.exe" -Destination $StageDir + Copy-Item "README.md", "LICENSE.md" -Destination $StageDir + + Compress-Archive -Path $StageDir -DestinationPath "$ArchiveName.zip" + $Hash = (Get-FileHash -Path "$ArchiveName.zip" -Algorithm SHA256).Hash.ToLower() + "$Hash $ArchiveName.zip" | Out-File -Encoding ascii "$ArchiveName.zip.sha256" + + New-Item -ItemType Directory -Force -Path dist | Out-Null + Move-Item "$ArchiveName.zip", "$ArchiveName.zip.sha256" -Destination dist/ + - name: Upload build artifacts + uses: actions/upload-artifact@v7 + with: + name: assets-${{ matrix.target }} + path: dist/* + archive: false + publish-release: + name: Publish Release + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v7 + - name: Download all artifacts + uses: actions/download-artifact@v8 + with: + path: all-assets + pattern: assets-* + merge-multiple: true + - name: Generate SHA256SUMS.txt + working-directory: all-assets + run: | + cat *.sha256 > SHA256SUMS.txt + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + name: Release ${{ github.ref_name }} + generate_release_notes: true + files: | + all-assets/*.tar.gz + all-assets/*.zip + all-assets/*.sha256 + all-assets/SHA256SUMS.txt