From e8c1d6816a10009dcc94070816809e7ec8633296 Mon Sep 17 00:00:00 2001 From: Sergei Semko <28645140+justSmK@users.noreply.github.com> Date: Tue, 27 Oct 2026 21:35:00 +0300 Subject: [PATCH] MOBILE-0000: Use a GitHub App token instead of the PAT in release flows Release PRs and the master-to-develop merge-back were opened and merged with PAT_FOR_TRIGGERING_BRANCH_PROTECTION, a personal token of an org admin account, only because events made with GITHUB_TOKEN start no workflows. An installation token of the mindbox-mobile-ci App starts them the same way, covers only this repository and the permissions of its step, and expires within an hour. The key comes from the org secret MOBILE_CI_APP_PRIVATE_KEY and the client ID from the org variable MOBILE_CI_APP_CLIENT_ID. Release and merge-back PRs are now authored by mindbox-mobile-ci[bot]. --- .../manual-prepare_release_branch.yml | 10 +++++++++- .github/workflows/publish-common-trigger.yml | 4 ++-- .github/workflows/publish-reusable.yml | 19 +++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/manual-prepare_release_branch.yml b/.github/workflows/manual-prepare_release_branch.yml index ee69f99..85f4845 100644 --- a/.github/workflows/manual-prepare_release_branch.yml +++ b/.github/workflows/manual-prepare_release_branch.yml @@ -180,9 +180,17 @@ jobs: runs-on: ubuntu-latest needs: bump_and_branch steps: + - name: Create App token + id: app-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ vars.MOBILE_CI_APP_CLIENT_ID }} + private-key: ${{ secrets.MOBILE_CI_APP_PRIVATE_KEY }} + permission-contents: read + permission-pull-requests: write - name: Build PR body and open PR env: - GITHUB_TOKEN: ${{ secrets.PAT_FOR_TRIGGERING_BRANCH_PROTECTION }} + GH_TOKEN: ${{ steps.app-token.outputs.token }} SRC: ${{ needs.bump_and_branch.outputs.release_branch }} DST: ${{ github.event.inputs.target_branch }} REPO: ${{ github.repository }} diff --git a/.github/workflows/publish-common-trigger.yml b/.github/workflows/publish-common-trigger.yml index 64b732a..def21e0 100644 --- a/.github/workflows/publish-common-trigger.yml +++ b/.github/workflows/publish-common-trigger.yml @@ -35,7 +35,7 @@ jobs: with: branch: ${{ github.ref_name }} secrets: - PAT_FOR_TRIGGERING_BRANCH_PROTECTION: ${{ secrets.PAT_FOR_TRIGGERING_BRANCH_PROTECTION }} + MOBILE_CI_APP_PRIVATE_KEY: ${{ secrets.MOBILE_CI_APP_PRIVATE_KEY }} publish-from-pr: if: github.event_name == 'pull_request' && github.event.pull_request.merged == true @@ -46,4 +46,4 @@ jobs: with: branch: ${{ github.base_ref }} secrets: - PAT_FOR_TRIGGERING_BRANCH_PROTECTION: ${{ secrets.PAT_FOR_TRIGGERING_BRANCH_PROTECTION }} + MOBILE_CI_APP_PRIVATE_KEY: ${{ secrets.MOBILE_CI_APP_PRIVATE_KEY }} diff --git a/.github/workflows/publish-reusable.yml b/.github/workflows/publish-reusable.yml index 79ff146..9d95560 100644 --- a/.github/workflows/publish-reusable.yml +++ b/.github/workflows/publish-reusable.yml @@ -7,7 +7,7 @@ on: required: true type: string secrets: - PAT_FOR_TRIGGERING_BRANCH_PROTECTION: + MOBILE_CI_APP_PRIVATE_KEY: required: true permissions: @@ -106,19 +106,26 @@ jobs: startsWith(github.head_ref, 'release/') && github.base_ref == 'master' runs-on: ubuntu-latest - env: - # gh uses this PAT, not the workflow GITHUB_TOKEN — needed so the merge PR - # re-triggers branch-protection checks. Job-level `permissions:` only scope - # the workflow token, so they don't apply to these gh calls. - GITHUB_TOKEN: ${{ secrets.PAT_FOR_TRIGGERING_BRANCH_PROTECTION }} steps: + - name: Create App token + id: app-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0 + with: + client-id: ${{ vars.MOBILE_CI_APP_CLIENT_ID }} + private-key: ${{ secrets.MOBILE_CI_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write - name: Checkout develop branch uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: develop - name: Create Pull Request + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} run: gh pr create --base develop --head master --title "Merge 'master' into 'develop' after release" --body "Automated Pull Request to merge 'master' into 'develop' after release" - name: Merge Pull Request + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} run: | pr_number=$(gh pr list --base develop --head master --json number --jq '.[0].number') gh pr merge "$pr_number" --merge --auto