From fcf64c6bccd69a0272f37134ea65da98de525886 Mon Sep 17 00:00:00 2001 From: Victor Martinez Date: Tue, 24 Sep 2024 23:10:47 +0200 Subject: [PATCH] ci: use GitHub app for ephemeral tokens (#3801) --- .github/workflows/pre-post-release.yml | 24 ++++++++++++++++++------ .github/workflows/release-step-3.yml | 22 +++++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pre-post-release.yml b/.github/workflows/pre-post-release.yml index 18b61057e9..4e5adb5599 100644 --- a/.github/workflows/pre-post-release.yml +++ b/.github/workflows/pre-post-release.yml @@ -53,17 +53,29 @@ jobs: runs-on: ubuntu-latest needs: - validate-tag - permissions: - contents: write - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} steps: + - name: Get token + id: get_token + uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 + with: + app_id: ${{ secrets.OBS_AUTOMATION_APP_ID }} + private_key: ${{ secrets.OBS_AUTOMATION_APP_PEM }} + permissions: >- + { + "contents": "write", + "pull_requests": "write" + } + repositories: >- + ["apm-agent-java"] + - uses: actions/checkout@v4 with: ref: ${{ inputs.ref }} - token: ${{ env.GITHUB_TOKEN }} + token: ${{ steps.get_token.outputs.token }} - uses: elastic/oblt-actions/git/setup@v1 + with: + github-token: ${{ steps.get_token.outputs.token }} - name: Create the release tag (post phase) if: inputs.phase == 'post' @@ -95,4 +107,4 @@ jobs: - name: Create the ${{ inputs.phase }} release PR run: gh pr create --title="${{ inputs.pr_title }}" --base main --head ${{ env.BRANCH_NAME }} -b "${{ inputs.pr_body }}" env: - GH_TOKEN: ${{ env.GITHUB_TOKEN }} + GH_TOKEN: ${{ steps.get_token.outputs.token }} diff --git a/.github/workflows/release-step-3.yml b/.github/workflows/release-step-3.yml index 5825547d0c..0a143258e0 100644 --- a/.github/workflows/release-step-3.yml +++ b/.github/workflows/release-step-3.yml @@ -213,17 +213,29 @@ jobs: runs-on: ubuntu-latest needs: - post-release - permissions: - contents: write - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }} steps: + - name: Get token + id: get_token + uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 + with: + app_id: ${{ secrets.OBS_AUTOMATION_APP_ID }} + private_key: ${{ secrets.OBS_AUTOMATION_APP_PEM }} + permissions: >- + { + "contents": "write", + "pull_requests": "write" + } + repositories: >- + ["apm-agent-java"] + - uses: actions/checkout@v4 with: ref: ${{ inputs.ref }} - token: ${{ env.GITHUB_TOKEN }} + token: ${{ steps.get_token.outputs.token }} - uses: elastic/oblt-actions/git/setup@v1 + with: + github-token: ${{ steps.get_token.outputs.token }} - name: Update major branch if: ${{ ! inputs.dry_run }}