|
| 1 | +name: github-release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - beta/v* |
| 7 | + tags: |
| 8 | + - v* |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + beta-branch-or-tag-name: |
| 12 | + description: The name of the beta branch or tag to release |
| 13 | + type: string |
| 14 | + required: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + github-release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Set tag name |
| 21 | + id: set-tag-name |
| 22 | + run: | |
| 23 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 24 | + REF_NAME="${{ github.event.inputs.beta-branch-or-tag-name }}" |
| 25 | + else |
| 26 | + REF_NAME="${{ github.ref_name }}" |
| 27 | + fi |
| 28 | +
|
| 29 | + echo "ref-name=$REF_NAME" >> $GITHUB_OUTPUT |
| 30 | + echo "tag-name=${REF_NAME#beta/}" >> $GITHUB_OUTPUT |
| 31 | +
|
| 32 | + - name: Check out repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + ref: ${{ steps.set-tag-name.outputs.ref-name }} |
| 37 | + |
| 38 | + - name: Set target name for beta branches |
| 39 | + id: set-target-name |
| 40 | + run: | |
| 41 | + if [[ "${{ steps.set-tag-name.outputs.ref-name }}" =~ "beta/" ]]; then |
| 42 | + echo "target-name=${{ steps.set-tag-name.outputs.ref-name }}" >> $GITHUB_OUTPUT |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Create a local tag for beta branches |
| 46 | + run: | |
| 47 | + if [ "${{ steps.set-target-name.outputs.target-name }}" != "" ]; then |
| 48 | + git tag "${{ steps.set-tag-name.outputs.tag-name }}" |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Run generate-changelog |
| 52 | + id: generate-changelog |
| 53 | + uses: autowarefoundation/autoware-github-actions/generate-changelog@v1 |
| 54 | + |
| 55 | + - name: Select verb |
| 56 | + id: select-verb |
| 57 | + run: | |
| 58 | + has_previous_draft=$(gh release view --json isDraft -q ".isDraft" "${{ steps.set-tag-name.outputs.tag-name }}") || true |
| 59 | +
|
| 60 | + verb=create |
| 61 | + if [ "$has_previous_draft" = "true" ]; then |
| 62 | + verb=edit |
| 63 | + fi |
| 64 | +
|
| 65 | + echo "verb=$verb" >> $GITHUB_OUTPUT |
| 66 | + env: |
| 67 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + |
| 69 | + - name: Release to GitHub |
| 70 | + run: | |
| 71 | + gh release ${{ steps.select-verb.outputs.verb }} "${{ steps.set-tag-name.outputs.tag-name }}" \ |
| 72 | + --draft \ |
| 73 | + --target "${{ steps.set-target-name.outputs.target-name }}" \ |
| 74 | + --title "Release ${{ steps.set-tag-name.outputs.tag-name }}" \ |
| 75 | + --notes "$NOTES" |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + NOTES: ${{ steps.generate-changelog.outputs.changelog }} |
0 commit comments