From a8ba5806c707ec1221a9f086884e71414ab0b687 Mon Sep 17 00:00:00 2001 From: Elliot Jackson <13633636+elliotmjackson@users.noreply.github.com> Date: Tue, 8 Nov 2022 09:01:55 -0500 Subject: [PATCH] TCN-667 add release action (#70) ```sh cd "${BUFBUILD_BUF_SETUP_ACTION_DIR}" git switch main git pull origin main make updateversion VERSION=${VERSION} git diff git checkout -b release/v${VERSION} git commit -am "Update to v${VERSION}" git push origin release/v${VERSION} # Get that PR approved and merged git switch main git pull origin main git tag -a "v${VERSION}" -m "v${VERSION}" git push origin "v${VERSION}" ``` Resolves [TCN-680](https://linear.app/bufbuild/issue/TCN-680) --- .github/workflows/release.yaml | 75 ++++++++++++++++++++++++++++++++++ Makefile | 1 + README.md | 8 ++-- 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..9879f0c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,75 @@ +name: Release +on: + workflow_dispatch: + inputs: + version: + type: string + description: The version you intend to release (eg x.y.z) + required: true + +env: + VERSION: v${{ github.event.inputs.version }} + APP_ID: 257262 + +jobs: + prepare: + runs-on: ubuntu-latest + steps: + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{env.APP_ID}} + private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} + repository: ${{ github.repository }} + permissions: >- + {"contents": "write", "pull_requests": "write"} + - name: Checkout repository code + uses: actions/checkout@v3 + with: + token: ${{ steps.generate_token.outputs.token }} + - uses: actions/setup-go@v3 + with: + go-version: '^1.19.x' + - name: Update docs Version + run: make updateversion VERSION=${{env.VERSION}} + - name: Create PR + id: cpr + uses: peter-evans/create-pull-request@ad43dccb4d726ca8514126628bec209b8354b6dd + with: + add-paths: . + commit-message: "Update version to ${{env.VERSION}}" + branch: release/${{env.VERSION}} + delete-branch: true + title: "Release ${{env.VERSION}}" + body: Release prepared for ${{env.VERSION}} + token: ${{ steps.generate_token.outputs.token }} + tag: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release') }} + steps: + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{env.APP_ID}} + private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} + repository: ${{ github.repository }} + permissions: >- + {"contents": "write"} + - name: Set VERSION variable from tag + run: | + VERSION=${{github.head_ref}} + echo "VERSION=${VERSION##*/}" >> $GITHUB_ENV + - name: Checkout repository code + uses: actions/checkout@v3 + with: + token: ${{ steps.generate_token.outputs.token }} + fetch-depth: 0 + - name: Tag Release + run: | + git config --global user.password ${{ steps.generate_token.outputs.token }} + git tag -d ${{env.VERSION}} 2> /dev/null || echo 'local ref does not exist' + git push origin :${{env.VERSION}} 2> /dev/null || echo 'remote ref does not exist' + git tag ${{env.VERSION}} + git push origin ${{env.VERSION}} diff --git a/Makefile b/Makefile index 08d4a93..ddab33c 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ ifndef VERSION $(error "VERSION must be set") endif $(SED_I) "s/default: '[0-9].[0-9][0-9]*\.[0-9][0-9]*[-rc0-9]*'/default: '$(VERSION)'/g" action.yml + $(SED_I) "s/[0-9].[0-9][0-9]*\.[0-9][0-9]*[-rc0-9]*/$(VERSION)/g" README.md .PHONY: generate generate: $(BIN)/license-header ## Regenerate licenses diff --git a/README.md b/README.md index 51d51b6..81549e8 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,10 @@ steps: You can configure `buf-setup-action` with these parameters: -Parameter | Description | Default -:---------|:------------|:------- -`version` | The version of the [`buf` CLI][buf-cli] to install | [`1.9.0`][version] -`github_token` | The GitHub token to use when making API requests | +| Parameter | Description | Default | +|:---------------|:---------------------------------------------------|:-------------------| +| `version` | The version of the [`buf` CLI][buf-cli] to install | [`1.9.0`][version] | +| `github_token` | The GitHub token to use when making API requests | | > These parameters are derived from [`action.yml`](./action.yml).