blob: c6db8a5d08fc361abe01357443e22bb26c92c3d4 [file]
name: Shared - Update Pull Request
on:
workflow_call:
inputs:
run:
description: Command that updates the source tree; its "output" is appended to the title
required: true
type: string
branch:
description: Pull request branch
required: true
type: string
title:
description: Pull request title
required: true
type: string
body:
description: Pull request body, used when the pull request is created
required: true
type: string
secrets:
SELENIUM_CI_TOKEN:
required: true
jobs:
update:
name: Update
permissions:
contents: read
pull-requests: read
uses: ./.github/workflows/bazel.yml
with:
name: Update
run: ./scripts/github-actions/safe-checkout.sh ${{ inputs.branch }}; ${{ inputs.run }}
artifact-name: pr-changes
publish:
name: Publish
if: github.event.repository.fork == false
needs: update
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Download patch
uses: actions/download-artifact@v8
with:
pattern: pr-changes
merge-multiple: true
- name: Commit and open or retitle the pull request
if: hashFiles('changes.patch') != ''
env:
GH_TOKEN: ${{ secrets.SELENIUM_CI_TOKEN }}
GH_REPO: ${{ github.repository }}
BRANCH: ${{ inputs.branch }}
TITLE: ${{ inputs.title }}${{ needs.update.outputs.output && format(' {0}', needs.update.outputs.output) || '' }}
BODY: ${{ inputs.body }}
run: |
./scripts/github-actions/safe-checkout.sh "$BRANCH"
git apply --index changes.patch
git -c user.name="Selenium CI Bot" -c user.email="selenium-ci@users.noreply.github.com" commit -qm "$TITLE"
git push --force "https://x-access-token:${GH_TOKEN}@github.com/${GH_REPO}.git" HEAD:refs/heads/"$BRANCH"
number=$(gh pr list --head "$BRANCH" --base trunk --json number --jq '.[0].number')
if [ -n "$number" ]; then
gh api --silent -X PATCH "repos/$GH_REPO/pulls/$number" -f title="$TITLE"
else
gh pr create --base trunk --head "$BRANCH" --title "$TITLE" --body "$BODY" --label C-build
fi