Skip to content

Commit

Permalink
build: add a workflow to automatically open release PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmarc committed May 5, 2024
1 parent 4a21295 commit a030896
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/bump-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
on: push
name: Open a PR to bump the version
jobs:
open_pr:
strategy:
matrix:
component: ["server", "client"]
name: Open PR
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu
- uses: actions/checkout@v4

- uses: swatinem/rust-cache@v2
- run: cargo install git-cliff@^2.2 cargo-edit@^0.12

- name: determine version
run: |
echo "COMPONENT=${{ matrix.component }}" | tee "$GITHUB_ENV"
comp_dir="mm-${{ matrix.component }}"
echo "COMPONENT_DIR=$comp_dir" | tee "$GITHUB_ENV"
version=$( git cliff -c .github/workflows/cliff.toml \
--bumped-version --unreleased \
--tag-pattern "${{ matrix.component }}" \
--include-path "$comp_dir/**/*" )
echo "BUMPED_VERSION=$version" | tee "$GITHUB_ENV"
echo "BUMPED_VERSION_SHORT=$( echo $version | sed -E 's/^[a-z]+-v(.*)/\1/' )" | tee "$GITHUB_ENV"
- name: replace version in files
if: ${{ env.BUMPED_VERSION != '' }}
run: git ls-files | xargs sed -i -E 's/mmserver-v[0-9]+\.[0-9]+\.[0-9]+/mmserver-v0.2.0/'

- name: replace version in Cargo.toml
if: ${{ env.BUMPED_VERSION != '' }}
run: (cd $COMPONENT_DIR && cargo set-version --offline $BUMPED_VERSION_SHORT)

- name: update BUSL change date
if: ${{ env.BUMPED_VERSION != '' && matrix.component == 'server' }}
run: |
change_date=$(date -d "4 years hence" +%Y-%m-01) # Round down to the 1st of the month
sed -i -E "/Change/s/[0-9]{4}-[0-9]{2}-[0-9]{2}/$change_date" LICENSES/BUSL-1.1.txt
- name: update CHANGELOG.md
if: ${{ env.BUMPED_VERSION != '' }}
run: |
git cliff -c .github/workflows/cliff.toml \
--include-path "$COMPONENT_DIR/**/*" \
--tag-pattern "$COMPONENT" \
-t "$BUMPED_VERSION" -u \
-p CHANGELOG.md
- name: generate PR body
if: ${{ env.BUMPED_VERSION != '' }}
run: |
git cliff -c .github/workflows/cliff.toml \
--include-path "$COMPONENT_DIR/**/*" \
--tag-pattern "$COMPONENT" \
-t "$BUMPED_VERSION" -u > "$RUNNER_TEMP/pr-body.txt"
- name: open PR
if: ${{ env.BUMPED_VERSION != '' }}
id: cpr
uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e
with:
draft: true
branch: "auto-bump-${{ matrix.component }}"
commit: "chore: bump mm${{ matrix.component }} to ${{ env.BUMPED_VERSION }}"
body-path: "${{ env.RUNNER_TEMP }}/pr-body.txt"

- name: tag branch commit
if: ${{ steps.cpr.outputs.pull-request-head-sha }}
run: |
git tag --force "$BUMPED_VERSION" ${{ steps.cpr.outputs.pull-request-head-sha }}
git push --tags --force
4 changes: 4 additions & 0 deletions .github/workflows/cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ commit_parsers = [
{ body = ".*security", skip = true },
{ message = "^revert", skip = true },
]

[bump]
features_always_bump_minor = true
breaking_always_bump_major = false
Empty file added CHANGELOG.md
Empty file.

0 comments on commit a030896

Please sign in to comment.