Prepare New Release #11
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
name: Prepare New Release | |
on: | |
workflow_dispatch: | |
inputs: | |
current_version: | |
description: 'current version' | |
required: true | |
type: string | |
new_version: | |
description: 'new version' | |
required: true | |
type: string | |
base_ref: | |
description: 'the git ref to go against' | |
required: false | |
type: string | |
default: main | |
jobs: | |
run: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.base_ref }} | |
- name: Prepare random dir | |
id: random-dir | |
run: echo "path=$(mktemp -d)" >> "$GITHUB_OUTPUT" | |
- name: Find latest build | |
id: latest-build | |
run: | | |
set -euo pipefail | |
run_info="$(gh run list -b "$RUN_REF" -w build-release.yml --limit 1 --json status,conclusion,databaseId)" | |
run_id="$(echo "$run_info" | jq -re '.[].databaseId' )" | |
if [[ "$(echo "$run_info" | jq -r '.[].conclusion')" != success ]]; then | |
echo "::error ::Found run $run_id but its conclusion was $(echo "$run_info" | jq '.[].conclusion')" | |
exit 1 | |
fi | |
echo "run_id=$run_id" >> "$GITHUB_OUTPUT" | |
env: | |
RUN_REF: ${{ github.event.inputs.base_ref }} | |
- name: Download build artifacts | |
run: gh run download "$RUN_ID" -p 'mdq-*' --dir "$TMP_DIR" | |
env: | |
TMP_DIR: ${{ steps.random-dir.outputs.path }} | |
RUN_ID: ${{ steps.latest-build.outputs.run_id }} | |
- name: Re-zip build artifacts | |
run: | | |
set -euo pipefail | |
for artifact_name in $(ls -1) ; do | |
zip "${artifact_name}.zip" "$artifact_name"/* | |
rm -rf "$artifact_name"/ | |
done | |
working-directory: ${{ steps.random-dir.outputs.path }} | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
- name: Extract current version from Cargo.toml | |
run: | | |
set -euo pipefail | |
current_version=$(grep '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/') | |
if [[ "${{ github.event.inputs.current_version }}" != "$current_version" ]]; then | |
echo "::error title=bad version::Expected version ${{ github.event.inputs.current_version }} does not match current version $current_version." | |
exit 1 | |
fi | |
- name: Create new release | |
id: create_release | |
run: | | |
release_url="$(gh release create "v${{ github.event.inputs.new_version }}" --draft --title "v${{ github.event.inputs.new_version }}" --generate-notes --target "$TARGET_REF")" | |
echo "release_url=$release_url" >> "$GITHUB_OUTPUT" | |
env: | |
TARGET_REF: ${{ github.event.inputs.base_ref }} | |
- name: Upload artifacts | |
run: gh release upload "$RELEASE_TAG" "$TMP_DIR"/* | |
env: | |
TMP_DIR: ${{ steps.random-dir.outputs.path }} | |
RELEASE_TAG: "v${{ github.event.inputs.new_version }}" | |
- name: Update Cargo.toml | |
run: sed -i 's/^version = ".*"/version = "${{ github.event.inputs.new_version }}"/' Cargo.toml | |
- name: Update Cargo.lock | |
run: cargo metadata >/dev/null | |
- name: Commit changes | |
run: | | |
set -euo pipefail | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
git checkout -b release-prep-${{ github.event.inputs.new_version }} | |
git commit -am "Update version to ${{ github.event.inputs.new_version }}" | |
git push --set-upstream origin release-prep-${{ github.event.inputs.new_version }} | |
- name: Create Pull Request | |
run: | | |
gh pr create --title "Prepare v${{ github.event.inputs.new_version }}" --body "Bump version to ${{ github.event.inputs.new_version }}" --base "$TARGET_REF" | |
env: | |
TARGET_REF: ${{ github.event.inputs.base_ref }} |