Skip to content

Commit

Permalink
tech: improve prerelease action
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamoss committed Feb 18, 2024
1 parent b117c18 commit c355c20
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ name: prerelease

on:
# Run Every Wednesday at 01:00 AM UTC
schedule:
- cron: '0 2 * * 3'
# schedule:
# - cron: '0 2 * * 3'
workflow_dispatch:
inputs:
release-as-minor:
description: "Minor Release (default: Patch)"
type: boolean
default: false
release-tag:
description: "Choose a release type"
required: true
type: choice
default: 'patch'
options:
- patch
- minor
- major

skip-release:
description: "Skip the tag creation step (default: false)"
type: boolean
Expand All @@ -27,6 +33,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.RELEASE_TOKEN }}

- name: Setup Go
Expand Down Expand Up @@ -63,19 +70,22 @@ jobs:
- name: Prepare Release
if: steps.changes.outputs.HAS_CHANGES == 'true'
env:
IS_MINOR: ${{ contains(inputs.release-as-minor, 'true') }}
RELEASE_TAG: ${{ inputs.release-tag }}
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ })
MAJOR=${CURRENT_VERSION_PARTS[0]}
MINOR=${CURRENT_VERSION_PARTS[1]}
PATCH=${CURRENT_VERSION_PARTS[2]}
if [[ $IS_MINOR == "true" ]]
then
if [[ $RELEASE_TAG == "major" ]]; then
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
elif [[ $RELEASE_TAG == "minor" ]]; then
MINOR=$((MINOR+1))
PATCH=0
else
elif [[ $RELEASE_TAG == "patch" ]]; then
PATCH=$((PATCH+1))
fi
Expand All @@ -84,11 +94,21 @@ jobs:
echo "Current Version is: $CURRENT_VERSION"
echo "New Version will be: $NEW_VERSION"
echo "Commits since last release:"
COMMITS=$(git --no-pager log --pretty=format:"- %h %s" ${CURRENT_VERSION}...origin/master)
echo "$COMMITS"
echo "## Updating ${CURRENT_VERSION} to ${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY
echo "## Commits that will be added to the release" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "$COMMITS" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
- name: Release New Version
if: ${{ success() && github.ref_name == 'master' && steps.changes.outputs.HAS_CHANGES == 'true' && !inputs.skip-release }}
env:
# Github actions need special tokens to be able to trigger other workflows
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
git tag -a ${NEW_VERSION} -m "New version ${NEW_VERSION}"
Expand Down

0 comments on commit c355c20

Please sign in to comment.