Skip to content

move pr-update workflow logic into shell functions #100

move pr-update workflow logic into shell functions

move pr-update workflow logic into shell functions #100

Workflow file for this run

name: pull-request-update
on:
push:
branches: [ main ]
pull_request:
branches: [ "*" ]
workflow_dispatch:
jobs:
update-stacked-pull-requests:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_UPDATE_BOT_APPID }}
private-key: ${{ secrets.PR_UPDATE_BOT_PRIVATE_KEY}}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: update stacked pull requests
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -a
source .github/pr-update-utils.sh
default_branch=${{ github.event.repository.default_branch }}
git fetch origin "$default_branch" --depth 1 --quiet
base_change_id=$(\
gh_api --jq ".commit.message" "/repos/${{ github.repository }}/commits/${default_branch}" \
| grep "Change-Id:" \
| cut -d' ' -f2)
pull_requests_with_base "$base_change_id" \
| xargs -I {} bash -c 'set -euo pipefail; echo "updating PR {}"; try_update_with "{}" "origin/${default_branch}"'
update-out-of-date-pull-requests:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.PR_UPDATE_BOT_APPID }}
private-key: ${{ secrets.PR_UPDATE_BOT_PRIVATE_KEY}}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: update out of date pull requests
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -a
source .github/pr-update-utils.sh
default_branch=${{ github.event.repository.default_branch }}
git fetch origin "$default_branch" --depth 1 --quiet
head_commit=$(gh_api --jq ".sha" "/repos/${{ github.repository }}/commits/${default_branch}")
function update
{
number="$1"
echo -n "checking if PR $number is up to date "
pr_head_commit=$(gh pr view $number --json commits --jq ".commits | last | .oid")
pr_status=$(gh_api --jq ".status" /repos/${{ github.repository }}/compare/$head_commit...$pr_head_commit)
if [[ "$pr_status" == "ahead" ]]; then
echo "✅"
else
echo "";
try_update_with "$number" "origin/${default_branch}"
fi
}
pull_requests_with_base "$default_branch" \
| xargs -I {} bash -c 'set -euo pipefail; update "{}"'