This commit is contained in:
Moritz Utcke
2025-04-28 16:31:33 -03:00
parent 344651dfc1
commit aca01b859f

View File

@@ -33,12 +33,58 @@ jobs:
exit 1 exit 1
fi fi
- name: Merge staging into main - name: Generate GitHub App Installation Token
if: steps.check.outcome == 'success'
run: | run: |
git checkout main echo "${{ secrets.IBCORNELSEN_APP_PRIVATE_KEY }}" > private-key.pem
git merge origin/staging --no-ff --no-edit chmod 600 private-key.pem
git push origin main --force
# Generate JWT
now=$(date +%s)
exp=$((now + 600)) # 10 minutes validity
header_base64=$(echo -n '{"alg":"RS256","typ":"JWT"}' | openssl base64 -e | tr -d '=' | tr '/+' '_-' | tr -d '\n')
payload_base64=$(echo -n "{\"iat\":$now,\"exp\":$exp,\"iss\":${{ secrets.IBCORNELSEN_APP_ID }}}" | openssl base64 -e | tr -d '=' | tr '/+' '_-' | tr -d '\n')
header_payload="${header_base64}.${payload_base64}"
signature=$(echo -n "$header_payload" | openssl dgst -sha256 -sign private-key.pem | openssl base64 -e | tr -d '=' | tr '/+' '_-' | tr -d '\n')
jwt="${header_payload}.${signature}"
# Request Installation Token
response=$(curl -s -X POST \
-H "Authorization: Bearer $jwt" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/app/installations/${{ secrets.IBCORNELSEN_INSTALLATION_ID }}/access_tokens)
installation_token=$(echo "$response" | grep '"token"' | head -n 1 | cut -d '"' -f4)
# Save the token as a GitHub environment variable
echo "INSTALLATION_TOKEN=$installation_token" >> $GITHUB_ENV
# Clean up private key
rm -f private-key.pem
- name: Create or update PR from staging → main
if: steps.check.outcome == 'success'
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ env.INSTALLATION_TOKEN }} # Use the installation token here
commit-message: "chore: auto-merge staging into main"
branch: auto-merge/staging-to-main
base: main
title: "Auto-merge staging into main"
body: |
This PR was created automatically by GitHub Actions.
It merges the latest `staging` into `main`.
draft: false
- name: Enable auto-merge on PR
if: steps.cpr.outputs.pull-request-number != ''
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ env.INSTALLATION_TOKEN }} # Use the installation token here
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: merge
notify_failure: notify_failure:
needs: merge needs: merge