Create release #5
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: Create release | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseType: | |
description: 'Release type' | |
required: true | |
default: 'patch' | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
create_release: | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
env: | |
GH_TOKEN: ${{ github.token }} | |
outputs: | |
new_version: ${{ steps.determine_new_version.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: determine new version | |
id: determine_new_version | |
run: | | |
last_release=`gh release list | head -n 1 | awk '{print $3}'` | |
release_type=${{ inputs.releaseType }} | |
echo "Creating new $release_type release after $last_release" | |
major=`echo $last_release | cut -d v -f 2 | cut -d . -f 1` | |
minor=`echo $last_release | cut -d . -f 2` | |
patch=`echo $last_release | cut -d . -f 3` | |
case $release_type in | |
major) | |
major=`expr $major + 1` | |
minor=0 | |
patch=0 | |
;; | |
minor) | |
minor=`expr $minor + 1` | |
patch=0 | |
;; | |
patch) | |
patch=`expr $patch + 1` | |
;; | |
esac | |
new_version=$major.$minor.$patch | |
echo "New release is $new_version" | |
echo "new_version=$new_version" >> "$GITHUB_OUTPUT" | |
- name: Bump composer.json version | |
env: | |
new_version: ${{ steps.determine_new_version.outputs.new_version }} | |
run: | | |
echo "New version: $new_version" | |
jq '.version = $version' --arg version $new_version composer.json > composer.new.json | |
mv composer.new.json composer.json | |
git config --global user.email 'github-ci@boldcommerce.com' | |
git config --global user.name 'bold-github-ci' | |
branch_exists=`git ls-remote --heads origin refs/heads/release-$new_version | wc -l` | |
if [[ $branch_exist -eq 0 ]]; | |
then | |
git checkout -b release-$new_version | |
git add composer.json | |
git commit -m 'Bump version number for release' | |
git push --set-upstream origin release-$new_version | |
else | |
git fetch origin | |
git checkout release-$new_version | |
fi | |
pr_exists=`gh pr list -H release-$new_version | wc -l` | |
if [[ $pr_exists -eq 0 ]]; | |
then | |
gh pr create --title "Create release $new_version" --body "Create new release from workflow" | |
fi | |
gh pr merge --admin --squash | |
- name: Create github release | |
env: | |
new_version: v${{ steps.determine_new_version.outputs.new_version }} | |
run: | | |
gh release create --generate-notes --latest $new_version | |