|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + version: |
| 6 | + type: string |
| 7 | + description: The version you intend to release (eg x.y.z) |
| 8 | + required: true |
| 9 | + |
| 10 | +env: |
| 11 | + VERSION: v${{ github.event.inputs.version }} |
| 12 | + APP_ID: 257262 |
| 13 | + |
| 14 | +jobs: |
| 15 | + prepare: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Generate token |
| 19 | + id: generate_token |
| 20 | + uses: tibdex/github-app-token@v1 |
| 21 | + with: |
| 22 | + app_id: ${{env.APP_ID}} |
| 23 | + private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} |
| 24 | + repository: ${{ github.repository }} |
| 25 | + permissions: >- |
| 26 | + {"contents": "write", "pull_requests": "write"} |
| 27 | + - name: Checkout repository code |
| 28 | + uses: actions/checkout@v3 |
| 29 | + with: |
| 30 | + token: ${{ steps.generate_token.outputs.token }} |
| 31 | + - uses: actions/setup-go@v3 |
| 32 | + with: |
| 33 | + go-version: '^1.19.x' |
| 34 | + - name: Update docs Version |
| 35 | + run: make updateversion VERSION=${{env.VERSION}} |
| 36 | + - name: Create PR |
| 37 | + id: cpr |
| 38 | + uses: peter-evans/create-pull-request@ad43dccb4d726ca8514126628bec209b8354b6dd |
| 39 | + with: |
| 40 | + add-paths: . |
| 41 | + commit-message: "Update version to ${{env.VERSION}}" |
| 42 | + branch: release/${{env.VERSION}} |
| 43 | + delete-branch: true |
| 44 | + title: "Release ${{env.VERSION}}" |
| 45 | + body: Release prepared for ${{env.VERSION}} |
| 46 | + token: ${{ steps.generate_token.outputs.token }} |
| 47 | + tag: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release') }} |
| 50 | + steps: |
| 51 | + - name: Generate token |
| 52 | + id: generate_token |
| 53 | + uses: tibdex/github-app-token@v1 |
| 54 | + with: |
| 55 | + app_id: ${{env.APP_ID}} |
| 56 | + private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} |
| 57 | + repository: ${{ github.repository }} |
| 58 | + permissions: >- |
| 59 | + {"contents": "write"} |
| 60 | + - name: Set VERSION variable from tag |
| 61 | + run: | |
| 62 | + VERSION=${{github.head_ref}} |
| 63 | + echo "VERSION=${VERSION##*/}" >> $GITHUB_ENV |
| 64 | + - name: Checkout repository code |
| 65 | + uses: actions/checkout@v3 |
| 66 | + with: |
| 67 | + token: ${{ steps.generate_token.outputs.token }} |
| 68 | + fetch-depth: 0 |
| 69 | + - name: Tag Release |
| 70 | + run: | |
| 71 | + git config --global user.password ${{ steps.generate_token.outputs.token }} |
| 72 | + git tag -d ${{env.VERSION}} 2> /dev/null || echo 'local ref does not exist' |
| 73 | + git push origin :${{env.VERSION}} 2> /dev/null || echo 'remote ref does not exist' |
| 74 | + git tag ${{env.VERSION}} |
| 75 | + git push origin ${{env.VERSION}} |
0 commit comments