surrealpatch/.github/workflows/beta.yml

137 lines
4.2 KiB
YAML
Raw Normal View History

2023-12-11 13:58:43 +00:00
# Use this workflow to trigger beta releases, both initial beta.1 and subsequent beta.x releases
name: Beta release
run-name: "Beta release (publish: ${{ inputs.publish }}, bump version: ${{ inputs.bump-version }})"
on:
workflow_dispatch:
inputs:
publish:
required: false
type: boolean
default: false
description: "Publish the beta release"
bump-version:
required: false
type: boolean
default: false
description: "Bump the version of the current beta if this is not the initial one"
defaults:
run:
shell: bash
2023-12-11 13:58:43 +00:00
permissions:
contents: write
jobs:
2023-12-11 13:58:43 +00:00
checks:
name: Pre-release checks
runs-on: ubuntu-latest
2023-12-11 13:58:43 +00:00
outputs:
branch: ${{ steps.outputs.outputs.branch }}
steps:
2023-12-11 13:58:43 +00:00
- uses: actions/checkout@v4
with:
2023-12-11 13:58:43 +00:00
fetch-depth: 0
2023-12-11 13:58:43 +00:00
- name: Determine the correct branch
id: outputs
run: |
set -x
2023-12-11 13:58:43 +00:00
if git branch -r | grep -w 'releases/beta'; then
echo "branch=releases/beta" >> $GITHUB_OUTPUT
else
echo "branch=main" >> $GITHUB_OUTPUT
fi
release:
name: Prepare beta release
needs: [checks]
uses: ./.github/workflows/reusable_publish_version.yml
with:
environment: beta
git-ref: ${{ needs.checks.outputs.branch }}
bump-version: ${{ inputs.bump-version }}
2023-12-11 13:58:43 +00:00
publish: ${{ inputs.publish }}
create-release: ${{ inputs.publish }}
secrets: inherit
bump-version:
name: Bump main version
if: ${{ needs.checks.outputs.branch == 'main' }}
needs: [checks, release]
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: releases/beta
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Install a TOML parser
run: cargo install --force --locked --version 0.8.1 taplo-cli
- name: Create version bump branch
id: bump
run: |
set -x
# Retrieve just released version
betaVersion=$(/home/runner/.cargo/bin/taplo get -f lib/Cargo.toml "package.version")
major=$(echo $betaVersion | tr "." "\n" | sed -n 1p)
minor=$(echo $betaVersion | tr "." "\n" | sed -n 2p)
nightlyVersion=${major}.$(($minor + 1)).0
echo "version=${nightlyVersion}" >> $GITHUB_OUTPUT
# Checkout the main branch
git fetch origin main
git checkout main
# Switch to version bump branch
git checkout -b version-bump/v${nightlyVersion}
# Bump the crate version
sed -i "s#^version = \".*\"#version = \"${nightlyVersion}\"#" Cargo.toml
sed -i "s#^version = \".*\"#version = \"${nightlyVersion}\"#" lib/Cargo.toml
sed -i "s#^version = \".*\"#version = \"${nightlyVersion}\"#" core/Cargo.toml
# Update Cargo.lock without updating dependency versions
cargo check --no-default-features --features storage-mem
- name: Push the branch
if: ${{ inputs.publish }}
run: |
# Configure git
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git config --add --bool push.autoSetupRemote true
# Commit changes
git commit -am "Bump version to v${{ steps.bump.outputs.version }}"
git push
- name: Create a PR
id: pr
if: ${{ inputs.publish }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -x
url=$(gh pr create --base main --title "Bump version to v${{ steps.bump.outputs.version }}" --body "Update main version")
echo "url=${url}" >> $GITHUB_OUTPUT
- name: Merge the PR
if: ${{ inputs.publish }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }} # Need the custom user token here so we can approve and merge the PR
run: |
set -x
gh pr review ${{ steps.pr.outputs.url }} --approve
gh pr merge ${{ steps.pr.outputs.url }} --delete-branch --admin --squash