3️⃣ Publish: final release #11
This file contains hidden or 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: "3️⃣ Publish: final release" | |
| on: | |
| workflow_dispatch: | |
| branches: | |
| # allow dispatch only main branches -- only documentation, it is not tested on workflow_dispatch | |
| - "main" | |
| - "next" | |
| - "legacy" | |
| inputs: | |
| confirmation: | |
| description: "Create release tag and publish package" | |
| required: true | |
| default: false | |
| type: boolean | |
| jobs: | |
| publish-final-release: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.package-version.outputs.version }} | |
| sha: ${{ steps.tag-revision.outputs.sha }} | |
| steps: | |
| - name: Get branch name | |
| id: branch-name | |
| uses: tj-actions/branch-names@v8 | |
| - name: Allow only for feature/fix branches | |
| id: dispatched-branch | |
| run: | | |
| if [[ ! ${{ steps.branch-name.outputs.current_branch }} =~ ^(main|next|legacy)$ ]] ; | |
| then | |
| echo "Only allowed to get triggered on main branches!" | |
| echo "You started it on '${{ steps.branch-name.outputs.current_branch }}'." | |
| exit 1 | |
| fi | |
| echo "targetbranch=$(echo ${{ steps.branch-name.outputs.current_branch }} | sed 's=^main$=develop=')" >> $GITHUB_OUTPUT | |
| - uses: actions/checkout@main | |
| - name: Initialize mandatory git config | |
| # @see https://github.community/t/how-do-i-get-gh-username-based-on-actions-events/17882 | |
| run: | | |
| git config user.name "${{ github.actor }}" | |
| git config user.email "${{ github.actor }}@users.noreply.github.com" | |
| - uses: actions/setup-node@main | |
| with: | |
| node-version: "lts/krypton" | |
| - name: Get version | |
| id: package-version | |
| run: echo "version=$(node -p -e "require('./package.json').version.split('-').shift()")" >> $GITHUB_OUTPUT | |
| - name: Check if version already exists as package | |
| id: check-version-existence | |
| run: | | |
| if [ -n "$( npm view @eccenca/gui-elements versions | grep \'${{ steps.package-version.outputs.version }}\' )" ] ; then echo "Stop: v${{ steps.package-version.outputs.version }} is already published!" && false; else echo "Continue: v${{ steps.package-version.outputs.version }} is not published."; fi | |
| - name: Update version in repository | |
| run: | | |
| yarn version --no-git-tag-version --new-version ${{ steps.package-version.outputs.version }} | |
| sed -i "s/## \[Unreleased\]/## \[Unreleased\]\n\n## [${{ steps.package-version.outputs.version }}] - $(date -I)/g" ./CHANGELOG.md | |
| git commit package.json CHANGELOG.md --message "Update changelog section to ${{ steps.package-version.outputs.version }}" | |
| - name: Create version tag | |
| id: tag-revision | |
| run: | | |
| git tag -a v${{ steps.package-version.outputs.version }} -m "tag final release v${{ steps.package-version.outputs.version }}" | |
| echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
| - name: Push tag and changes | |
| run: | | |
| git checkout -b maintain/mergeReleaseTag-v${{ steps.package-version.outputs.version }} | |
| git push origin v${{ steps.package-version.outputs.version }} | |
| git push origin maintain/mergeReleaseTag-v${{ steps.package-version.outputs.version }} | |
| - name: Create pull request merge back release process changes | |
| uses: thomaseizinger/create-pull-request@master | |
| with: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| head: maintain/mergeReleaseTag-v${{ steps.package-version.outputs.version }} | |
| base: ${{ steps.dispatched-branch.outputs.targetbranch }} | |
| title: Release process changes from v${{ steps.package-version.outputs.version }} | |
| draft: true | |
| reviewers: ${{ github.actor }} | |
| body: | | |
| Created by Github workflow. | |
| Necessary to merge back all changes that had to be done during release process. | |
| publish-package: | |
| needs: publish-final-release | |
| uses: ./.github/workflows/push-tagged-release.yml | |
| with: | |
| ref: v${{ needs.publish-final-release.outputs.version }} | |
| sha: ${{ needs.publish-final-release.outputs.sha }} | |
| sectionChangelog: ${{ needs.publish-final-release.outputs.version }} | |
| onlyNpmPush: false | |
| secrets: | |
| chromaticToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} | |
| npmjsToken: ${{ secrets.NPMJS_REGISTRY_TOKEN }} |