diff --git a/.github/workflows/create-release-pr.yaml b/.github/workflows/create-release-pr.yaml new file mode 100644 index 0000000..f975383 --- /dev/null +++ b/.github/workflows/create-release-pr.yaml @@ -0,0 +1,49 @@ +name: Create Release PR +on: + workflow_dispatch: + inputs: + version: + type: string + description: The version you intend to release (eg x.y.z) + required: true +permissions: + contents: write + pull-requests: write +env: + VERSION: ${{ github.event.inputs.version }} + APP_ID: 257262 +jobs: + update_version: + runs-on: ubuntu-latest + if: ${{ github.event.inputs.version != '' }} + steps: + - name: Validate input version + if: ${{ startsWith(github.event.inputs.version, 'v') }} + run: | + echo "error: version must not start with 'v'." + exit 1 + - name: Get GitHub app token + uses: actions/create-github-app-token@v1 + id: app_token + with: + app-id: ${{ env.APP_ID }} + private-key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} + - name: Checkout repository code + uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: '^1.19.x' + - name: Update docs Version + run: make updateversion VERSION=${{env.VERSION}} + - name: Create PR + run: | + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor }}@users.noreply.github.com" + BRANCH="release/v${VERSION}" + git switch -C ${BRANCH} + git add . + git commit -m "Update version to ${VERSION}" + git push --set-upstream origin --force ${BRANCH} + gh pr create --title "Release v${VERSION}" --body "Release prepared for ${VERSION}" + env: + GH_TOKEN: ${{ steps.app_token.outputs.token }} diff --git a/.github/workflows/draft-release.yaml b/.github/workflows/draft-release.yaml new file mode 100644 index 0000000..b35c3f6 --- /dev/null +++ b/.github/workflows/draft-release.yaml @@ -0,0 +1,41 @@ +name: Draft Release +on: + pull_request: + types: [closed] + workflow_dispatch: + inputs: + version: + type: string + description: The released CLI version without 'v'. For example, 1.0.0. +permissions: + contents: write +jobs: + draft_release: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release')) }} + steps: + - name: Validate input version + if: ${{ startsWith(github.event.inputs.version, 'v') }} + run: | + echo "error: version must not start with 'v'." + exit 1 + - name: Set VERSION variable + # The head ref looks like release/v1.0.0, and we need to trim the string up to the `/v`. + run: | + VERSION="${{ github.event.inputs.version || github.head_ref}}" + echo "VERSION=${VERSION##*/v}" >> $GITHUB_ENV + - name: Checkout repository code + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 + - name: Sync v1 branch + run: | + git fetch origin + git switch v1 + git merge origin/main + git push origin v1 + - name: Release + run: gh release create --draft --title "v${VERSION}" "v${VERSION}" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index c43d395..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,112 +0,0 @@ -name: Release -on: - workflow_dispatch: - inputs: - version: - type: string - description: The version you intend to release (eg x.y.z) - required: true - pull_request: - types: [ closed ] - push: - branches: - - 'release/**' - tags: - - v* - -env: - VERSION: ${{ github.event.inputs.version }} - APP_ID: 257262 - -jobs: - prepare: - runs-on: ubuntu-latest - if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' }} - steps: - - name: Generate token - id: generate_token - uses: tibdex/github-app-token@0914d50df753bbc42180d982a6550f195390069f - with: - app_id: ${{env.APP_ID}} - private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} - 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@331d02c7e2104af23ad5974d4d5cbc58a3e6dc77 - with: - add-paths: . - commit-message: "Update version to v${{env.VERSION}}" - branch: release/v${{env.VERSION}} - delete-branch: true - title: "Release v${{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@b62528385c34dbc9f38e5f4225ac829252d1ea92 - 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 - 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}} - release: - runs-on: ubuntu-latest - if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }} - steps: - - name: Generate token - id: generate_token - uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 - with: - app_id: ${{env.APP_ID}} - private_key: ${{ secrets.TOKEN_EXCHANGE_GH_APP_PRIVATE_KEY }} - repository: ${{ github.repository }} - permissions: >- - {"contents": "write"} - - name: Checkout repository code - uses: actions/checkout@v3 - with: - token: ${{ steps.generate_token.outputs.token }} - fetch-depth: 0 - - name: Sync v1 branch - run: | - git fetch origin - git switch v1 - git merge origin/main - git push origin v1 - - name: Release - id: ghr - uses: softprops/action-gh-release@v1 - with: - token: ${{ steps.generate_token.outputs.token }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index fd869a0..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,12 +0,0 @@ -name: test -on: [push, pull_request] -jobs: - lint: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - uses: ./ # Run the local version of the action. - with: - version: 'latest' - github_token: ${{ github.token }} - - run: buf --version