Add auto merge workflow #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Merge Bot PRs | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create temporary directory | |
id: tempdir | |
run: | | |
tempdir=$(mktemp -d) | |
echo "tempdir=${tempdir}" >> $GITHUB_OUTPUT | |
- name: Create JWT | |
id: jwt | |
run: | | |
DIR="${{ steps.tempdir.outputs.tempdir }}" | |
python3 -m venv ${DIR}/.venv | |
source ${DIR}/.venv/bin/activate | |
pip install --quiet --upgrade pip | |
pip install --quiet jwt | |
cat > ./create-jwt.py << EOF | |
#!/usr/bin/env python3 | |
from time import time | |
from os import environ | |
from sys import argv | |
from jwt import JWT, jwk_from_pem | |
private_key, app_id, now = argv[1], argv[2], int(time()) | |
signing_key = jwk_from_pem(private_key.encode("utf-8")) | |
print(JWT().encode(dict(iat=now, exp=now + 600, iss=app_id), signing_key, alg="RS256")) | |
EOF | |
chmod 755 ./create-jwt.py | |
VALUE=$(./create-jwt.py "${{ secrets.LETTUCE_BOT_PRIVATE_KEY }}" "${{ vars.LETTUCE_BOT_APP_ID }}) | |
echo "::add-mask::${VALUE}" | |
echo "value=${VALUE}" >> "$GITHUB_OUTPUT" | |
- name: Create token | |
id: token | |
run: | | |
TOKEN=$(curl --silent --request POST \ | |
--url "https://api.github.com/app/installations/${{ vars.LETTUCE_BOT_INSTALLATION_ID }}/access_tokens" \ | |
--header "Accept: application/vnd.github+json" \ | |
--header "Authorization: Bearer ${{ steps.jwt.outputs.value }}" \ | |
--header "X-GitHub-Api-Version: 2022-11-28" \ | |
| jq .token -r) | |
echo "::add-mask::${TOKEN}" | |
echo "value=${TOKEN}" >> "$GITHUB_OUTPUT" | |
- name: Delete temporary directory | |
if: always() | |
run: | | |
rm -rf ${{ steps.tempdir.outputs.tempdir }} | |
- name: Auto Merge Lettuce Bot | |
if: ${{ github.actor == 'lettuce-bot[bot]' || github.actor == 'renovate[bot]' }} | |
run: | | |
gh pr merge --repo ${{ github.repository }} --auto --merge ${{ github.event.number }} | |
env: | |
GH_TOKEN: ${{ steps.token.outputs.token }} |