Skip to content

Release

Release #110

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
dryRun:
description: 'Dry Run'
required: true
default: 'true'
releaseVersion:
description: 'Notation has to be major.minor.patch (leave empty for automatic determination)'
required: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.PAT_ME_REPO }} # use PAT to being able to push to protected branch later on
- name: Fetch tags
run: git fetch --tags
- name: Configure CI Git User
run: |
git config user.name "Marco Eidinger"
git config user.email "marco.eidinger@sap.com"
git config push.followTags true
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY
env:
GITHUB_TOKEN: ${{ secrets.PAT_ME_REPO }}
- name: Get changelog
id: get_changelog
run: |
changelog=''
if ( ${{ github.event.inputs.releaseVersion == null }} ); then
changelog=`npx standard-version --tag-prefix '' --dry-run | sed -n '/^---$/,/^---$/p' | grep -v '^---$'`
else
changelog=`npx standard-version --tag-prefix '' --release-as '${{ github.event.inputs.releaseVersion }}' --dry-run | sed -n '/^---$/,/^---$/p' | grep -v '^---$'`
fi
changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
changelog="${changelog//$'\r'/'%0D'}"
echo "$changelog"
echo "::set-output name=changelog::$changelog"
- name: Determine next version number
if: github.event.inputs.releaseVersion == null
run: |
nextVersion=`npx standard-version --tag-prefix '' --dry-run | sed -n '/^---$/,/^---$/p' | grep -P -o '(\d+\.)(\d+\.)(\d)' | head -n 1`
echo "$nextVersion"
echo "NEXT_VERSION=$nextVersion" >> $GITHUB_ENV
- name: Manually next version number
if: github.event.inputs.releaseVersion != null
run: |
echo "NEXT_VERSION=${{ github.event.inputs.releaseVersion }}" >> $GITHUB_ENV
echo "${{ env.NEXT_VERSION }}"
- name: bump version - DRY RUN
if: github.event.inputs.dryRun == 'true'
run: |
if ( ${{ github.event.inputs.releaseVersion == null }} ); then
npx standard-version --tag-prefix '' --dry-run
else
npx standard-version --tag-prefix '' --release-as '${{ github.event.inputs.releaseVersion }}' --dry-run
fi
- name: bump version - AUTOMATIC
if: github.event.inputs.dryRun == 'false' && github.event.inputs.releaseVersion == null
run: npx standard-version --tag-prefix ''
- name: bump version - MANUAL VERSION NO.
if: github.event.inputs.dryRun == 'false' && github.event.inputs.releaseVersion != null
run: npx standard-version --tag-prefix '' --release-as '${{ github.event.inputs.releaseVersion }}'
- name: Check if tag already exists
id: check_tag
run: |
if git rev-parse "refs/tags/${{ env.NEXT_VERSION }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Publish tag # only possible on main branch
if: github.event.inputs.dryRun == 'false' && steps.check_tag.outputs.exists == 'false'
run: |
git push --follow-tags origin
- name: Check if release already exists
id: check_release
run: |
release=$(gh release view ${{ env.NEXT_VERSION }} --json tagName --jq .tagName || true)
if [ "$release" = "${{ env.NEXT_VERSION }}" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.PAT_ME_REPO }}
- name: Publish GitHub release
uses: actions/create-release@v1.1.4
if: github.event.inputs.dryRun == 'false' && steps.check_release.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.PAT_ME_REPO }} # # use PAT to being able to push to protected branch later on
with:
tag_name: ${{ env.NEXT_VERSION }}
release_name: ${{ env.NEXT_VERSION }}
body: |
${{ steps.get_changelog.outputs.changelog }}