Release Packages #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When a release is created, distribute the packages to the appropriate registries. Also builds the binaries to attach them to the release. | |
name: Release Packages | |
on: | |
release: | |
types: [published] | |
jobs: | |
# Extract the release information from the tag | |
parse-release: | |
name: Parse Release | |
runs-on: ubuntu-latest | |
outputs: | |
release_name: ${{ env.RELEASE_NAME }} | |
package: ${{ env.PACKAGE }} | |
release_version: ${{ env.VERSION }} | |
steps: | |
- name: Get the release version from the tag | |
shell: bash | |
if: env.RELEASE_NAME == '' | |
run: | | |
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 | |
RELEASE_NAME=${GITHUB_REF#refs/tags/} | |
echo "RELEASE_NAME=${RELEASE_NAME}" >> $GITHUB_ENV | |
echo "PACKAGE=${RELEASE_NAME%-*}" >> $GITHUB_ENV | |
echo "VERSION=${RELEASE_NAME##*-}" >> $GITHUB_ENV | |
echo "release_name: ${RELEASE_NAME}" | |
echo "package: ${RELEASE_NAME%-*}" | |
echo "version: ${RELEASE_NAME##*-}" | |
publish-package: | |
name: Publish to Registry | |
needs: parse-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
- name: Install cargo-hack | |
uses: taiki-e/install-action@v2 | |
with: | |
tool: cargo-hack | |
- name: Publish to crates.io | |
if: ${{ contains(needs.parse-release.outputs.package, 'pumpkin-solver') || contains(needs.parse-release.outputs.package, 'drcp-format') }} | |
run: cargo hack publish --no-dev-deps --allow-dirty --package ${{ needs.parse-release.outputs.package }} --token ${CRATES_TOKEN} | |
env: | |
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }} | |
attach-artifacts: | |
name: Build Pumpkin Artifacts and Upload | |
needs: parse-release | |
if: ${{ contains(needs.parse-release.outputs.package, 'pumpkin-solver') }} | |
strategy: | |
fail-fast: false | |
matrix: | |
build: [linux, macos, win-msvc] | |
include: | |
- build: linux | |
os: ubuntu-20.04 | |
rust: stable | |
target: x86_64-unknown-linux-gnu | |
- build: macos | |
os: macos-latest | |
rust: stable | |
target: aarch64-apple-darwin | |
- build: win-msvc | |
os: windows-2019 | |
rust: stable | |
target: x86_64-pc-windows-msvc | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: ${{ matrix.rust }} | |
targets: ${{ matrix.target }} | |
- name: Build release binary | |
run: cargo build --package pumpkin-solver --target ${{ matrix.target }} --verbose --release | |
- name: Build archive | |
shell: bash | |
run: | | |
out_bin_name="${{ needs.parse-release.outputs.release_name }}-${{ matrix.target }}" | |
if [ "${{ matrix.os }}" = "windows-2019" ]; then | |
cp "target/${{ matrix.target }}/release/pumpkin-solver.exe" "$out_bin_name.exe" | |
echo "ASSET=$out_bin_name.exe" >> $GITHUB_ENV | |
else | |
cp "target/${{ matrix.target }}/release/pumpkin-solver" "$out_bin_name" | |
echo "ASSET=$out_bin_name" >> $GITHUB_ENV | |
fi | |
- name: Upload release archive | |
run: gh release upload ${{ needs.parse-release.outputs.release_name }} ${{ env.ASSET }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |