Skip to content

Commit

Permalink
Simplify the create-pr workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Carvalho <[email protected]>
  • Loading branch information
lcarva committed Jan 24, 2025
1 parent f73361f commit 8613b35
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions .github/workflows/create-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
inputs.run_for == 'infra-deployments' || inputs.run_for == 'all' || inputs.run_for == ''
runs-on: ubuntu-latest

permissions:
pull-requests: write
contents: write
actions: write

steps:

- name: Harden Runner
Expand Down Expand Up @@ -90,32 +95,35 @@ jobs:
run: git diff
working-directory: infra-deployments

- name: Checkout infra-deployments-ci
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
id: generate-branch-token
with:
path: infra-deployments-ci

- name: Create PR in infra-deployments
env:
EC_AUTOMATION_KEY: ${{ secrets.EC_AUTOMATION_KEY }}
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
APP_INSTALL_ID: 32872589
run: |
set -o errexit
set -o pipefail
set -o nounset
app-id: ${{ vars.EC_AUTOMATION_APP_ID }}
private-key: ${{ secrets.EC_AUTOMATION_KEY }}
owner: enterprise-contract
repositories: infra-deployments

function createJWT() {
local header=$(echo -n '{"alg":"RS256","typ":"JWT"}' | base64 | sed s/\+/-/ | sed -E s/=+$//)
local now_utc=$(date --utc +%s)
local payload=$(echo -n '{"iat":'$((now_utc - 60))',"exp":'$((now_utc + 120))',"iss":245286}' | base64 | sed s/\+/-/ | sed -E s/=+$//)
local signature=$(echo -n "${header}.${payload}" | openssl dgst -sha256 -binary -sign <(echo "${EC_AUTOMATION_KEY}")| base64 | tr -d '\n=' | tr -- '+/' '-_')
echo "${header}.${payload}.${signature}"
}
- uses: actions/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0
id: generate-pr-token
with:
app-id: ${{ vars.EC_AUTOMATION_APP_ID }}
private-key: ${{ secrets.EC_AUTOMATION_KEY }}
owner: redhat-appstudio
repositories: infra-deployments

GITHUB_TOKEN=$(curl -s -X POST -H "Authorization: Bearer $(createJWT)" -H "Accept: application/vnd.github+json" "https://api.github.com/app/installations/${APP_INSTALL_ID}/access_tokens" | jq -r .token) \
./hack/create-pr.sh [email protected]:enterprise-contract/infra-deployments.git ../infra-deployments
working-directory: infra-deployments-ci
- name: pull-request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
with:
branch: ci/update-infra-deployments
commit-message: enterprise contract update
sign-commits: true
signoff: true
title: enterprise contract update
branch-token: ${{ steps.generate-branch-token.outputs.token }}
token: ${{ steps.generate-pr-token.outputs.token }}
push-to-fork: enterprise-contract/infra-deployments
path: infra-deployments
maintainer-can-modify: false

create-build-definitions-pr:
if: >
Expand Down

0 comments on commit 8613b35

Please sign in to comment.