Skip to content

Commit

Permalink
add auto cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed Nov 8, 2024
1 parent f4b0f1d commit 4da102c
Showing 1 changed file with 53 additions and 17 deletions.
70 changes: 53 additions & 17 deletions .github/workflows/auto_docs.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,62 @@
name: Push to docs-latest on merge

# TODO(jan):
# 1. trigger on push to `main`
# 2. if the commit ends with (#\d+), that is the PR number
# 3. find the PR by its number
# 4. if the PR has the label `deploy-docs`, then push the commit
# to `docs-latest`
# 5. once committed, send a comment to the PR:
# "`deploy-docs` label found, this PR has been deployed to `docs-latest`."
# ideally, also include a link to the deploy job on vercel.
name: Docs deploy

on:
pull_request_target:
types:
- closed
push:
branches: [main]

permissions:
contents: "read"
id-token: "write"

defaults:
run:
shell: bash

# The lack of `concurrency` is intentional.
# We want this job to run on every commit, even if multiple are merged in a row.

jobs:
auto-docs:
if: ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'deploy docs') }}
has-label:
name: Check for PR label
runs-on: ubuntu-latest
outputs:
result: ${{ steps.find-pr.outputs.result }}
steps:
- uses: actions/checkout@v3
with:
# ref - not set, because we want to end up on the merge commit
fetch-depth: 0 # don't perform a shallow clone

# Find the PR by the number in the merge commit subject line
- name: Find PR
id: find-pr
env:
GH_TOKEN: ${{ secrets.RERUN_BOT_TOKEN }}
run: |
commit_message=$(git log --pretty=format:%s -n 1 ${{ github.sha }})
pr_number=$(echo $commit_message | grep -oP '(?<=#)\d+')
result=$(gh pr view $pr_number --json labels | jq -r 'any(.labels[].name; . == "deploy docs")')
echo "result=$result" >> $GITHUB_OUTPUT
cherry-pick:
name: Cherry-pick to docs-latest
needs: [has-label]
if: needs.has-label.outputs.result == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: docs-latest
fetch-depth: 0
token: ${{ secrets.RERUN_BOT_TOKEN }}

- name: Cherry-pick
run: |
# Setup git user
git config --global user.name "rerun-bot"
git config --global user.email "[email protected]"
# Cherry-pick the commit
git checkout docs-latest
git cherry-pick ${{ github.sha }}
git push origin docs-latest

0 comments on commit 4da102c

Please sign in to comment.