|
| 1 | +# |
| 2 | +# Copyright 2023 ABSA Group Limited |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | + |
| 17 | +name: Release - create draft release |
| 18 | +on: |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + tagName: |
| 22 | + description: 'Name of git tag to be created, and then draft release created. Syntax: "v[0-9]+.[0-9]+.[0-9]+".' |
| 23 | + required: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + tag: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + - name: Validate format of received tag |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const newTag = core.getInput('tag-name'); |
| 37 | + const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/; |
| 38 | + |
| 39 | + if (!regex.test(newTag)) { |
| 40 | + core.setFailed('Tag does not match the required format "v[0-9]+.[0-9]+.[0-9]+"'); |
| 41 | + return; |
| 42 | + } |
| 43 | + tag-name: ${{ github.event.inputs.tagName }} |
| 44 | + - name: Create and push tag |
| 45 | + uses: actions/github-script@v7 |
| 46 | + with: |
| 47 | + script: | |
| 48 | + const tag = core.getInput('tag-name') |
| 49 | + const ref = `refs/tags/${tag}`; |
| 50 | + const sha = context.sha; // The SHA of the commit to tag |
| 51 | + |
| 52 | + await github.rest.git.createRef({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + ref: ref, |
| 56 | + sha: sha |
| 57 | + }); |
| 58 | + |
| 59 | + console.log(`Tag created: ${tag}`); |
| 60 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + tag-name: ${{ github.event.inputs.tagName }} |
| 62 | + |
| 63 | + release: |
| 64 | + needs: tag |
| 65 | + runs-on: ubuntu-latest |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + fetch-depth: 0 |
| 70 | + ref: refs/tags/${{ github.event.inputs.tagName }} |
| 71 | + - name: Generate release notes |
| 72 | + id: generate_release_notes |
| 73 | + |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + with: |
| 77 | + chapters: | |
| 78 | + [ |
| 79 | + {"title": "Breaking Changes 💥", "label": "breaking-change"}, |
| 80 | + {"title": "New Features 🎉", "label": "enhancement"}, |
| 81 | + {"title": "Bugfixes 🛠", "label": "bug"} |
| 82 | + ] |
| 83 | + warnings: true |
| 84 | + - name: Create draft release |
| 85 | + uses: softprops/action-gh-release@v1 |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + with: |
| 89 | + name: ${{ github.event.inputs.tagName }} |
| 90 | + body: ${{ steps.generate_release_notes.outputs.releaseNotes }} |
| 91 | + draft: true |
| 92 | + prerelease: false |
0 commit comments