Prepare New Release #22
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 }} | |
TAG_NAME: "v${{ github.event.inputs.current_version }}" | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.base_ref }} | |
- name: Check that tag is available | |
run: | | |
if gh release view "$TAG_NAME" ; then | |
echo "::error ::tag $TAG_NAME already exists" | |
exit 1 | |
fi | |
- 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: Check Cargo.toml version | |
run: | | |
set -euo pipefail | |
toml_current_version=$(grep '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/') | |
expect_version="${CURRENT_VERSION}-dev" | |
if [[ "$toml_current_version" != "$expect_version" ]]; then | |
echo "::error title=bad version::Expected version $expect_version does not match current version $toml_current_version." | |
exit 1 | |
fi | |
env: | |
CURRENT_VERSION: ${{ github.event.inputs.current_version }} | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
- 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: Create new release | |
id: create_release | |
run: | | |
release_url="$(gh release create "$TAG_NAME" --draft --title "$TAG_NAME" --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 "$TAG_NAME" "$TMP_DIR"/* | |
env: | |
TMP_DIR: ${{ steps.random-dir.outputs.path }} | |
- 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 }} # TODO | |
git co release-experiment | |
git merge release-prep-${{ github.event.inputs.new_version }} | |
git push origin release-experiment | |
- name: early exit | |
run: exit 1 | |
- 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 }} |