Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature | git-flow release actions #53

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/scripts/bump-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if [ "$#" -ne 2 ]; then
echo "Usage: $0 <old version> <new version>"
exit 1
fi

OLD_VERSION=$1
NEW_VERSION=$2
ERROR_CODE=0

if [[ "$OSTYPE" == "darwin"* ]]; then
SED_CMD=("sed" "-i" "")
else
SED_CMD=("sed" "-i")
fi

cat .github/scripts/files-with-current-version-string | xargs -I % "${SED_CMD[@]}" s/$OLD_VERSION/$NEW_VERSION/g % || ERROR_CODE=2

if [ "$ERROR_CODE" -ne 0 ]; then
echo "Error: An error while replacing version strings."
exit $ERROR_CODE
fi

echo "Version bumped from $OLD_VERSION to $NEW_VERSION"
4 changes: 4 additions & 0 deletions .github/scripts/files-with-current-version-string
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
README.md
midi2/Cargo.toml
midi2_proc/Cargo.toml

1 change: 1 addition & 0 deletions .github/scripts/last-released-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git tag --sort=committerdate | grep -E "^[0-9]+\.[0-9]+\.[0-9]$" | tail -n 1
21 changes: 21 additions & 0 deletions .github/scripts/setup-git-flow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

sudo apt-get update
sudo apt-get install -y git-flow

git fetch origin
git switch --track origin/main
git switch --track origin/develop

git config --global user.email "[email protected]"
git config --global user.name "CI"

git config gitflow.branch.master main
git config gitflow.branch.develop develop
git config gitflow.prefix.feature feature/
git config gitflow.prefix.bugfix bugfix/
git config gitflow.prefix.release release/
git config gitflow.prefix.hotfix hotfix/
git config gitflow.prefix.support support/
git config gitflow.prefix.versiontag ""
git config gitflow.path.hooks ""
46 changes: 46 additions & 0 deletions .github/workflows/finish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Finish release

on:
workflow_dispatch:
inputs:
version:
description: Semver version to release
required: true
type:
description: What type of release
required: true
default: release
options:
- release
- hotfix

jobs:
release-start:
name: Finish release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.type }}/${{ github.event.inputs.version }}
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
with:
verbose: true
- name: Setup git-flow
run: ./.github/scripts/setup-git-flow.sh
- name: Finish release
run: git flow ${{ github.event.inputs.type }} finish ${{ github.event.inputs.version }} -m ${{ github.event.inputs.version }} --push
- name: Publish midi2_proc
uses: ryohidaka/[email protected]
with:
path: midi2_proc
token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
dry-run: true
- name: Publish midi2
uses: ryohidaka/[email protected]
with:
path: midi2
token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
dry-run: true
49 changes: 49 additions & 0 deletions .github/workflows/start-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Start release

on:
workflow_dispatch:
inputs:
version:
description: Semver version to release
required: true
type:
description: What type of release
required: true
default: release
options:
- release
- hotfix

jobs:
release-start:
name: Release start
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup git-flow
run: ./.github/scripts/setup-git-flow.sh
- name: Start release
run: git flow ${{ github.event.inputs.type }} start ${{ github.event.inputs.version }}
- name: Determine last release
run: echo "LAST_RELEASE=$(./.github/scripts/last-released-version.sh)" >> $GITHUB_ENV
- name: Bump version
run: ./.github/scripts/bump-version.sh $LAST_RELEASE ${{ github.event.inputs.version }}
- name: Update changelog
if: ${{ github.event.inputs.type == 'release' }}
uses: orhun/git-cliff-action@v4
with:
args: --unreleased --prepend CHANGELOG.md --tag ${{ github.event.inputs.version }} --github-token ${{ secrets.GITHUB_TOKEN }}
- name: Commit release prep changes
run: |
git add CHANGELOG.md
cat .github/scripts/files-with-current-version-string | xargs -I % git add %
git commit -m "chore(release): prepare ${{ github.event.inputs.version }}"
- name: Push branch
run: git push origin HEAD
- name: Create Pull Request
run: gh pr create --base main --head release/${{ github.event.inputs.version }} --title "Release | ${{ github.event.inputs.version }}" --body "Prepare release of version ${{ github.event.inputs.version }}."
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 0 additions & 3 deletions cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,3 @@ commit_parsers = [

tag_pattern = "^[0-9]+\\.[0-9]+\\.[0-9]+$"
sort_commits = "newest"

# command for appending the latest changes to the changelog
# git cliff --prepend CHANGELOG.md --tag <new version> --github-token <token> <old version>..<new version>