|
| 1 | +name: "3️⃣ Publish: final release" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + branches: |
| 6 | + # allow dispatch only main branches -- only documentation, it is not tested on workflow_dispatch |
| 7 | + - "main" |
| 8 | + - "next" |
| 9 | + - "legacy" |
| 10 | + inputs: |
| 11 | + confirmation: |
| 12 | + description: "Create release tag and publish package" |
| 13 | + required: true |
| 14 | + default: false |
| 15 | + type: boolean |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish-final-release: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + version: ${{ steps.package-version.outputs.version }} |
| 22 | + sha: ${{ steps.tag-revision.outputs.sha }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Get branch name |
| 26 | + id: branch-name |
| 27 | + uses: tj-actions/branch-names@v8 |
| 28 | + - name: Allow only for feature/fix branches |
| 29 | + id: dispatched-branch |
| 30 | + run: | |
| 31 | + if [[ ! ${{ steps.branch-name.outputs.current_branch }} =~ ^(main|next|legacy)$ ]] ; |
| 32 | + then |
| 33 | + echo "Only allowed to get triggered on main branches!" |
| 34 | + echo "You started it on '${{ steps.branch-name.outputs.current_branch }}'." |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + echo "targetbranch=(echo ${{ steps.branch-name.outputs.current_branch }} | sed 's=^main$=develop=')" >> $GITHUB_OUTPUT |
| 38 | + - uses: actions/checkout@main |
| 39 | + - name: Initialize mandatory git config |
| 40 | + # @see https://github.community/t/how-do-i-get-gh-username-based-on-actions-events/17882 |
| 41 | + run: | |
| 42 | + git config user.name "${{ github.actor }}" |
| 43 | + git config user.email "${{ github.actor }}@users.noreply.github.com" |
| 44 | + - uses: actions/setup-node@main |
| 45 | + with: |
| 46 | + node-version: "18" |
| 47 | + - name: Get version |
| 48 | + id: package-version |
| 49 | + run: echo "version=$(node -p -e "require('./package.json').version.split('-').shift()")" >> $GITHUB_OUTPUT |
| 50 | + - name: Check if version already exists as package |
| 51 | + id: check-version-existence |
| 52 | + run: | |
| 53 | + 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 |
| 54 | + - name: Update version in repository |
| 55 | + run: | |
| 56 | + yarn version --no-git-tag-version --new-version ${{ steps.package-version.outputs.version }} |
| 57 | + sed -i "s/## \[Unreleased\]/## \[Unreleased\]\n\n## [${{ steps.package-version.outputs.version }}] - $(date -I)/g" ./CHANGELOG.md |
| 58 | + git commit package.json CHANGELOG.md --message "Update changelog section to ${{ steps.package-version.outputs.version }}" |
| 59 | + - name: Create version tag |
| 60 | + id: tag-revision |
| 61 | + run: | |
| 62 | + git tag -a v${{ steps.package-version.outputs.version }} -m "tag final release v${{ steps.package-version.outputs.version }}" |
| 63 | + echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 64 | + - name: Push tag and changes |
| 65 | + run: | |
| 66 | + git push origin v${{ steps.package-version.outputs.version }} |
| 67 | + git push origin maintain/mergeReleaseTag-v${{ steps.package-version.outputs.version }} |
| 68 | + - name: Create pull request merge back release process changes |
| 69 | + uses: thomaseizinger/create-pull-request@master |
| 70 | + with: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + head: maintain/mergeReleaseTag-v${{ steps.package-version.outputs.version }} |
| 73 | + base: ${{ steps.dispatched-branch.outputs.targetbranch }} |
| 74 | + title: Release process changes from v${{ steps.create-version.outputs.version }} |
| 75 | + draft: true |
| 76 | + reviewers: ${{ github.actor }} |
| 77 | + body: | |
| 78 | + Created by Github workflow. |
| 79 | + After merging this PR the "publish final release" action can be triggered on `${{ steps.dispatched-branch.outputs.targetbranch }}`. |
| 80 | +
|
| 81 | + publish-package: |
| 82 | + needs: publish-final-release |
| 83 | + uses: ./.github/workflows/push-tagged-release.yml |
| 84 | + with: |
| 85 | + ref: v${{ needs.publish-final-release.outputs.version }} |
| 86 | + sha: ${{ needs.publish-final-release.outputs.sha }} |
| 87 | + sectionChangelog: ${{ needs.publish-final-release.outputs.version }} |
| 88 | + onlyNpmPush: false |
| 89 | + secrets: |
| 90 | + chromaticToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} |
| 91 | + npmjsToken: ${{ secrets.NPMJS_REGISTRY_TOKEN }} |
0 commit comments