Skip to content

Commit af68a41

Browse files
committed
[build] add reusable commit-changes.yml workflow
1 parent 421cf91 commit af68a41

File tree

6 files changed

+126
-135
lines changed

6 files changed

+126
-135
lines changed

.github/workflows/ci-lint.yml

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,12 @@ jobs:
5656
commit-fixes:
5757
name: Commit fixes
5858
needs: format
59-
if: failure() && github.event_name == 'pull_request'
60-
runs-on: ubuntu-latest
61-
permissions:
62-
contents: write
63-
actions: read
64-
steps:
65-
- name: Check Permissions
66-
if: github.event.pull_request.head.repo.fork == true
67-
run: |
68-
echo "::error::Code needs formatting. Run ./scripts/format.sh locally and push changes."
69-
exit 1
70-
- name: Checkout PR
71-
uses: actions/checkout@v4
72-
with:
73-
ref: ${{ github.event.pull_request.head.ref }}
74-
- name: Download format changes
75-
uses: actions/download-artifact@v4
76-
with:
77-
name: format-changes
78-
- name: Apply and commit fixes
79-
id: apply
80-
run: |
81-
if [ -s changes.patch ]; then
82-
git apply --index changes.patch
83-
rm changes.patch
84-
git config --local user.name "Selenium CI Bot"
85-
git config --local user.email "[email protected]"
86-
git commit -m "Auto-format code"
87-
echo "has_changes=true" >> "$GITHUB_OUTPUT"
88-
else
89-
echo "::notice::No formatting changes needed."
90-
fi
91-
- name: Push fixes
92-
if: steps.apply.outputs.has_changes == 'true'
93-
run: |
94-
git push
95-
echo "::notice::Auto-formatted and pushed. New CI run will start."
59+
if: failure() && github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
60+
uses: ./.github/workflows/commit-changes.yml
61+
with:
62+
artifact-name: format-changes
63+
commit-message: "Auto-format code"
64+
ref: ${{ github.event.pull_request.head.ref }}
9665

9766
ci-lint:
9867
if: always()

.github/workflows/ci-renovate-rbe.yml

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,10 @@ jobs:
4242
name: Commit Repins
4343
needs: pin
4444
if: github.event.repository.fork == false
45-
runs-on: ubuntu-latest
46-
permissions:
47-
contents: write
48-
steps:
49-
- name: Checkout
50-
uses: actions/checkout@v4
51-
- name: Download repin patch
52-
uses: actions/download-artifact@v4
53-
with:
54-
name: repin-changes
55-
continue-on-error: true
56-
- name: Apply patch and commit
57-
run: |
58-
if [ -f changes.patch ] && [ -s changes.patch ]; then
59-
git apply --index changes.patch
60-
git config --local user.email "[email protected]"
61-
git config --local user.name "Selenium CI Bot"
62-
git commit -m 'Repin dependencies'
63-
git push
64-
else
65-
echo "No changes to commit"
66-
fi
45+
uses: ./.github/workflows/commit-changes.yml
46+
with:
47+
artifact-name: repin-changes
48+
commit-message: "Repin dependencies"
6749

6850
check-format:
6951
needs: commit-repins
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Commit Changes
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
artifact-name:
7+
description: Name of artifact containing changes.patch
8+
required: true
9+
type: string
10+
commit-message:
11+
description: Commit message
12+
required: true
13+
type: string
14+
ref:
15+
description: Git ref to checkout
16+
required: false
17+
type: string
18+
default: ''
19+
push-branch:
20+
description: Branch to push to (defaults to current branch, uses force push)
21+
required: false
22+
type: string
23+
default: ''
24+
outputs:
25+
changes-committed:
26+
description: Whether changes were committed and pushed
27+
value: ${{ jobs.commit.outputs.committed }}
28+
secrets:
29+
SELENIUM_CI_TOKEN:
30+
required: false
31+
32+
jobs:
33+
commit:
34+
name: Commit Changes
35+
runs-on: ubuntu-latest
36+
outputs:
37+
committed: ${{ steps.commit.outputs.committed }}
38+
permissions:
39+
contents: write
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
with:
44+
ref: ${{ inputs.ref || github.ref }}
45+
token: ${{ secrets.SELENIUM_CI_TOKEN || github.token }}
46+
- name: Download patch
47+
uses: actions/download-artifact@v4
48+
with:
49+
name: ${{ inputs.artifact-name }}
50+
continue-on-error: true
51+
- name: Apply and commit
52+
id: commit
53+
run: |
54+
if [ -f changes.patch ] && [ -s changes.patch ]; then
55+
git apply --index changes.patch
56+
git config --local user.email "[email protected]"
57+
git config --local user.name "Selenium CI Bot"
58+
git commit -m "$COMMIT_MESSAGE"
59+
if [ -n "$PUSH_BRANCH" ]; then
60+
git push origin HEAD:"$PUSH_BRANCH" --force
61+
else
62+
git push
63+
fi
64+
echo "::notice::Changes committed and pushed"
65+
echo "committed=true" >> "$GITHUB_OUTPUT"
66+
else
67+
echo "::notice::No changes to commit"
68+
echo "committed=false" >> "$GITHUB_OUTPUT"
69+
fi
70+
env:
71+
COMMIT_MESSAGE: ${{ inputs.commit-message }}
72+
PUSH_BRANCH: ${{ inputs.push-branch }}

.github/workflows/pin-browsers.yml

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,39 @@ jobs:
1616
run: bazel run //scripts:pinned_browsers
1717
artifact-name: pinned-browsers
1818

19-
pull-request:
19+
push-changes:
20+
name: Push Changes
21+
needs: update
2022
if: github.event.repository.fork == false
23+
uses: ./.github/workflows/commit-changes.yml
24+
with:
25+
artifact-name: pinned-browsers
26+
commit-message: "Update pinned browser versions"
27+
push-branch: pinned-browser-updates
28+
secrets:
29+
SELENIUM_CI_TOKEN: ${{ secrets.SELENIUM_CI_TOKEN }}
30+
31+
create-pr:
32+
name: Create Pull Request
33+
needs: push-changes
34+
if: github.event.repository.fork == false && needs.push-changes.outputs.changes-committed == 'true'
2135
runs-on: ubuntu-latest
22-
needs: update
2336
steps:
24-
- name: Checkout repository
37+
- name: Checkout
2538
uses: actions/checkout@v4
26-
- name: Download patch
27-
uses: actions/download-artifact@v4
28-
with:
29-
name: pinned-browsers
30-
- name: Apply Patch
31-
run: |
32-
git apply changes.patch
33-
rm changes.patch
34-
- name: Check Changes
35-
run: |
36-
if [[ -n $(git status --porcelain common/repositories.bzl) ]]; then
37-
echo "CHANGES_FOUND=true" >> "$GITHUB_ENV"
38-
fi
3939
- name: Create Pull Request
40-
if: env.CHANGES_FOUND == 'true'
41-
uses: peter-evans/create-pull-request@v6
42-
with:
43-
token: ${{ secrets.SELENIUM_CI_TOKEN }}
44-
add-paths: common/repositories.bzl
45-
commit-message: "Update pinned browser versions"
46-
committer: Selenium CI Bot <[email protected]>
47-
author: Selenium CI Bot <[email protected]>
48-
title: "[dotnet][rb][java][js][py] Automated Browser Version Update"
49-
body: |
50-
This is an automated pull request to update pinned browsers and drivers
40+
env:
41+
GH_TOKEN: ${{ secrets.SELENIUM_CI_TOKEN }}
42+
run: |
43+
existing=$(gh pr list --head pinned-browser-updates --json number --jq '.[0].number')
44+
if [ -n "$existing" ]; then
45+
echo "::notice::PR #$existing already exists"
46+
else
47+
gh pr create \
48+
--head pinned-browser-updates \
49+
--base trunk \
50+
--title "[dotnet][rb][java][js][py] Automated Browser Version Update" \
51+
--body "This is an automated pull request to update pinned browsers and drivers
5152
52-
Merge after verify the new browser versions properly passing the tests and no bugs need to be filed
53-
branch: "pinned-browser-updates"
53+
Merge after verify the new browser versions properly passing the tests and no bugs need to be filed"
54+
fi

.github/workflows/pre-release.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
secrets:
3131
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
3232

33-
# Rust jobs run in parallel with approval since work is not on trunk
33+
# Run rust jobs run in parallel with approval since work is not on trunk
3434
generate-rust-version:
3535
name: Generate Rust Version
3636
if: github.event.repository.fork == false
@@ -43,29 +43,13 @@ jobs:
4343
push-rust-version:
4444
name: Push Rust Version
4545
needs: generate-rust-version
46-
runs-on: ubuntu-latest
47-
steps:
48-
- name: Checkout repo
49-
uses: actions/checkout@v4
50-
with:
51-
token: ${{ secrets.SELENIUM_CI_TOKEN }}
52-
fetch-depth: 0
53-
- name: Download rust version patch
54-
uses: actions/download-artifact@v4
55-
with:
56-
name: rust-version
57-
- name: Apply and push
58-
run: |
59-
if [ -f changes.patch ] && [ -s changes.patch ]; then
60-
git apply --index changes.patch
61-
git config --local user.email "[email protected]"
62-
git config --local user.name "Selenium CI Bot"
63-
git commit -m "update selenium manager version and rust changelog"
64-
git push origin HEAD:rust-release-${{ inputs.version }} --force
65-
else
66-
echo "::error::No changes to apply for rust version update"
67-
exit 1
68-
fi
46+
uses: ./.github/workflows/commit-changes.yml
47+
with:
48+
artifact-name: rust-version
49+
commit-message: "update selenium manager version and rust changelog"
50+
push-branch: rust-release-${{ inputs.version }}
51+
secrets:
52+
SELENIUM_CI_TOKEN: ${{ secrets.SELENIUM_CI_TOKEN }}
6953

7054
selenium-manager:
7155
name: Release Selenium Manager

.github/workflows/release.yml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,29 +181,12 @@ jobs:
181181
update-version:
182182
name: Push Version Reset
183183
needs: [prepare, reset-version, unrestrict-trunk]
184-
runs-on: ubuntu-latest
185-
permissions:
186-
contents: write
187-
steps:
188-
- name: Checkout
189-
uses: actions/checkout@v4
190-
with:
191-
token: ${{ secrets.SELENIUM_CI_TOKEN }}
192-
- name: Download version reset patch
193-
uses: actions/download-artifact@v4
194-
with:
195-
name: version-reset
196-
- name: Apply and push
197-
run: |
198-
if [ -f changes.patch ] && [ -s changes.patch ]; then
199-
git apply --index changes.patch
200-
git config --local user.email "[email protected]"
201-
git config --local user.name "Selenium CI Bot"
202-
git commit -m "[build] Reset versions to nightly after ${{ needs.prepare.outputs.tag }} release"
203-
git push
204-
else
205-
echo "::notice::No version changes to apply"
206-
fi
184+
uses: ./.github/workflows/commit-changes.yml
185+
with:
186+
artifact-name: version-reset
187+
commit-message: "[build] Reset versions to nightly after ${{ needs.prepare.outputs.tag }} release"
188+
secrets:
189+
SELENIUM_CI_TOKEN: ${{ secrets.SELENIUM_CI_TOKEN }}
207190

208191
nightly:
209192
name: Publish Nightly Packages

0 commit comments

Comments
 (0)