Release #9
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
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
semver-bump: | |
description: Semver bump release type | |
required: true | |
type: choice | |
default: patch | |
options: | |
- major | |
- minor | |
- patch | |
concurrency: publish | |
jobs: | |
verified: | |
uses: ./.github/workflows/verify.yml | |
release: | |
runs-on: ubuntu-latest | |
needs: verified | |
name: Publish to crates.io | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- name: Cargo semver bump | |
id: semver | |
env: | |
SEMVER_BUMP: ${{github.event.inputs.semver-bump}} | |
run: | | |
cargo install cargo-release | |
cargo release version $SEMVER_BUMP --no-confirm --execute | |
VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' Cargo.toml) | |
echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
- name: Cargo publish | |
env: | |
CARGO_REGISTRY_TOKEN: ${{secrets.CRATES_IO_API_TOKEN}} | |
run: | | |
cargo publish --allow-dirty | |
- name: Bump ver > git | |
env: | |
GH_TOKEN: ${{secrets.GH_TOKEN}} | |
run: | | |
git config --global user.name "Adam McKee" | |
git config --global user.email "[email protected]" | |
VERSION=${{steps.semver.outputs.version}} | |
BRANCH_NAME=bump-semver-$VERSION | |
git checkout -b $BRANCH_NAME | |
git commit -am "increment Cargo.toml version to $VERSION" | |
git push origin $BRANCH_NAME | |
gh pr create --base main --title "cargo publish $VERSION" --body "cargo publish $VERSION" | |
gh pr merge $BRANCH_NAME --auto --rebase | |
outputs: | |
version: ${{steps.semver.outputs.version}} | |
docker: | |
name: Docker build and push | |
needs: release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: docker/login-action@v2 | |
with: | |
username: 84tech | |
password: ${{secrets.DOCKERHUB_TOKEN}} | |
- name: docker | |
env: | |
VERSION: ${{needs.release.outputs.version}} | |
run: | | |
docker build -t 84tech/cquill --build-arg CQUILL_VERSION=$VERSION -f cquill.install.Dockerfile . | |
docker tag 84tech/cquill 84tech/cquill:$VERSION | |
docker push -a 84tech/cquill | |
create-gh-release: | |
runs-on: ubuntu-22.04 | |
needs: release | |
steps: | |
- name: Create release | |
id: create | |
env: | |
VERSION: ${{needs.release.outputs.version}} | |
run: | | |
CREATED_RELEASE=$(gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/eighty4/maestro/releases \ | |
-f tag_name="$VERSION" \ | |
-f name="$VERSION" \ | |
-f body="$VERSION release" \ | |
-F draft=false \ | |
-F prerelease=false \ | |
-F generate_release_notes=false) | |
echo "release_id=$(echo $CREATED_RELEASE | jq '.id')" >> "$GITHUB_OUTPUT" | |
echo "upload_hostname=$(echo $CREATED_RELEASE | jq '.upload_url' | cut -d'/' -f3)" >> "$GITHUB_OUTPUT" | |
publish-gh-artifacts: | |
runs-on: ubuntu-22.04 | |
needs: create-gh-release | |
strategy: | |
matrix: | |
include: | |
- target: aarch64-apple-darwin | |
- target: x86_64-apple-darwin | |
- target: aarch64-unknown-linux-gnu | |
- target: x86_64-unknown-linux-gnu | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: swatinem/rust-cache@v2 | |
- name: build | |
env: | |
RELEASE_ID: ${{needs.create-gh-release.outputs.release_id}} | |
UPLOAD_HOSTNAME: ${{needs.create-gh-release.outputs.upload_hostname}} | |
GH_TOKEN: ${{secrets.GH_TOKEN}} | |
run: | | |
rustup target add ${{matrix.target}} | |
cargo build --release --target ${{matrix.target}} | |
curl --fail --silent -L -X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GH_TOKEN"\ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
-H "Content-Type: $(file target/release/cquill -b --mime-type)" \ | |
https://$UPLOAD_HOSTNAME/repos/eighty4/maestro/releases/$RELEASE_ID/assets?name=cquill \ | |
--data-binary "@target/release/cquill" | |
publish-gh-artifacts-windows: | |
runs-on: windows-2022 | |
needs: create-gh-release | |
strategy: | |
matrix: | |
include: | |
- target: aarch64-pc-windows-msvc | |
- target: x86_64-pc-windows-msvc | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@stable | |
- uses: swatinem/rust-cache@v2 | |
- name: build | |
env: | |
RELEASE_ID: ${{needs.create-gh-release.outputs.release_id}} | |
UPLOAD_HOSTNAME: ${{needs.create-gh-release.outputs.upload_hostname}} | |
GH_TOKEN: ${{secrets.GH_TOKEN}} | |
run: | | |
rustup target add ${{matrix.target}} | |
cargo build --release --target ${{matrix.target}} | |
curl --fail --silent -L -X POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $GH_TOKEN"\ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
-H "Content-Type: $(file target/release/cquill.exe -b --mime-type)" \ | |
https://$UPLOAD_HOSTNAME/repos/eighty4/maestro/releases/$RELEASE_ID/assets?name=cquill.exe \ | |
--data-binary "@target/release/cquill.exe" | |
delete-failed-gh-release: | |
runs-on: ubuntu-22.04 | |
needs: | |
- publish-gh-artifacts | |
- publish-gh-artifacts-windows | |
if: ${{always() && (contains(needs.publish-gh-artifacts.result, 'failure') || contains(needs.publish-gh-artifacts-windows.result, 'failure'))}} | |
steps: | |
- name: delete failed release | |
env: | |
RELEASE_ID: ${{needs.create-gh-release.outputs.release_id}} | |
GH_TOKEN: ${{secrets.GH_TOKEN}} | |
run: | | |
gh api \ | |
--method DELETE \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/eighty4/maestro/releases/$RELEASE_ID |