From c355c2065e76b0616e80201510ca89a75541d020 Mon Sep 17 00:00:00 2001 From: sylviamoss Date: Sun, 18 Feb 2024 12:07:59 +0100 Subject: [PATCH] tech: improve prerelease action --- .github/workflows/prerelease.yml | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index 2f34060..6459fce 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -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 @@ -27,6 +33,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + fetch-tags: true token: ${{ secrets.RELEASE_TOKEN }} - name: Setup Go @@ -63,7 +70,7 @@ 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//./ }) @@ -71,11 +78,14 @@ jobs: 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 @@ -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}"