Skip to content

Commit b227361

Browse files
committed
.github: add workflow to open downstream PR
Signed-off-by: flouthoc <[email protected]>
1 parent 5f3bd88 commit b227361

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
name: 'Open downstream PRs'
2+
3+
on:
4+
pull_request_target:
5+
branches:
6+
- 'main'
7+
8+
jobs:
9+
sync:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 'Checkout Self'
13+
uses: actions/checkout@v5
14+
# This checks out the code from the PR branch itself
15+
16+
- name: 'Check for Go file changes'
17+
id: check_go_changes
18+
run: |
19+
# Get the list of changed files in the PR
20+
CHANGED_FILES=$(gh pr view ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --json files --jq '.files[].path')
21+
22+
# Filter for relevant Go files that should trigger downstream sync
23+
# Include: .go files (excluding test files and vendor directory)
24+
# Exclude: *_test.go files, vendor/ directory files
25+
RELEVANT_GO_FILES=$(echo "$CHANGED_FILES" | grep -E '\.go$' | grep -v '_test\.go$' | grep -v '^vendor/' || echo "")
26+
27+
if [ -n "$RELEVANT_GO_FILES" ]; then
28+
echo "Relevant Go files changed (excluding tests and vendor):"
29+
echo "should_run=true" >> $GITHUB_OUTPUT
30+
echo "go_changes=true" >> $GITHUB_ENV
31+
else
32+
echo "No relevant Go files were changed in this PR."
33+
echo "Only test files, vendor files, or non-Go files were modified - skipping downstream sync."
34+
echo "should_run=false" >> $GITHUB_OUTPUT
35+
echo "go_changes=false" >> $GITHUB_ENV
36+
fi
37+
env:
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: 'Setup Go'
41+
if: steps.check_go_changes.outputs.should_run == 'true'
42+
uses: actions/setup-go@v6
43+
with:
44+
go-version: 'stable'
45+
46+
- name: 'Checkout forked buildah'
47+
if: steps.check_go_changes.outputs.should_run == 'true'
48+
uses: actions/checkout@v5
49+
with:
50+
repository: 'flouthoc/buildah' # The target repository
51+
path: 'buildah' # Checkout into a sub-directory
52+
token: ${{ secrets.VENDOR_TOKEN_PODMANBOT }}
53+
54+
- name: 'Vendor Code from this repo to buildah'
55+
if: steps.check_go_changes.outputs.should_run == 'true'
56+
run: |
57+
# Get the current commit SHA from the PR
58+
COMMIT_SHA="${{ github.event.pull_request.head.sha }}"
59+
echo "Using commit SHA: $COMMIT_SHA"
60+
61+
cd buildah
62+
# Create a unique branch name based on the container-libs PR number
63+
BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}"
64+
git switch -c $BRANCH_NAME
65+
git remote add upstream https://github.com/containers/buildah.git
66+
git fetch upstream
67+
git rebase upstream/main
68+
69+
70+
echo "Current go.mod before update:"
71+
cat go.mod
72+
73+
# Function to update module and verify
74+
update_module() {
75+
local module=$1
76+
echo "Updating module: $module"
77+
go mod edit -replace ${module}=github.com/${{ github.event.pull_request.head.repo.full_name }}/${module#go.podman.io/}@${COMMIT_SHA}
78+
GOWORK=off go mod tidy
79+
}
80+
81+
# Update all required modules
82+
update_module "go.podman.io/common"
83+
update_module "go.podman.io/storage"
84+
update_module "go.podman.io/image/v5"
85+
GOWORK=off go mod vendor
86+
GOWORK=off go mod verify
87+
88+
echo "Updated go.mod:"
89+
cat go.mod
90+
91+
- name: 'Commit and Push to buildah'
92+
if: steps.check_go_changes.outputs.should_run == 'true'
93+
run: |
94+
cd buildah
95+
git config user.name "github-actions[bot]"
96+
git config user.email "github-actions[bot]@users.noreply.github.com"
97+
98+
BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}"
99+
git switch $BRANCH_NAME
100+
101+
git add .
102+
git commit -m "dnd: Vendor changes from containers/container-libs#${{ github.event.pull_request.number }}"
103+
104+
# Force push to update the branch if the action re-runs on 'synchronize'
105+
git push origin $BRANCH_NAME --force
106+
107+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
108+
109+
- name: 'Create or Update Pull Request in Buildah'
110+
if: steps.check_go_changes.outputs.should_run == 'true'
111+
id: create_pr
112+
env:
113+
GH_TOKEN: ${{ secrets.VENDOR_TOKEN_PODMANBOT }}
114+
SELF_REPO_PR_NUMBER: ${{ github.event.pull_request.number }}
115+
SELF_REPO_PR_URL: ${{ github.event.pull_request.html_url }}
116+
SELF_REPO_PR_TITLE: ${{ github.event.pull_request.title }}
117+
run: |
118+
cd buildah
119+
120+
BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}"
121+
PR_TITLE="Sync: ${{ env.SELF_REPO_PR_TITLE }}"
122+
PR_BODY="This PR automatically vendors changes from [repo-A#${{ env.SELF_REPO_PR_NUMBER }}](${{ env.SELF_REPO_PR_URL }})."
123+
124+
# Check if PR already exists for this branch
125+
echo "Searching for existing PR with branch: $BRANCH_NAME"
126+
127+
EXISTING_PR_URL=$(gh pr list --repo flouthoc/buildah --head "$BRANCH_NAME" --json url --jq '.[0].url // empty' 2>/dev/null || echo "")
128+
129+
if [ -n "$EXISTING_PR_URL" ]; then
130+
echo "Found existing PR: $EXISTING_PR_URL"
131+
# Update existing PR title and body
132+
gh pr edit $EXISTING_PR_URL \
133+
--title "$PR_TITLE" \
134+
--body "$PR_BODY"
135+
echo "Updated existing PR: $EXISTING_PR_URL"
136+
echo "pr_url=$EXISTING_PR_URL" >> $GITHUB_OUTPUT
137+
echo "pr_action=updated" >> $GITHUB_OUTPUT
138+
else
139+
# Create new PR
140+
NEW_PR_URL=$(gh pr create \
141+
--repo flouthoc/buildah \
142+
--draft \
143+
--base main \
144+
--head "$BRANCH_NAME" \
145+
--title "$PR_TITLE" \
146+
--body "$PR_BODY")
147+
echo "Created new PR: $NEW_PR_URL"
148+
echo "pr_url=$NEW_PR_URL" >> $GITHUB_OUTPUT
149+
echo "pr_action=created" >> $GITHUB_OUTPUT
150+
fi
151+
152+
- name: 'Comment on container-libs PR with the link to buildah PR'
153+
if: steps.check_go_changes.outputs.should_run == 'true'
154+
env:
155+
GH_TOKEN: ${{ secrets.VENDOR_TOKEN_PODMANBOT }}
156+
SELF_REPO_PR_NUMBER: ${{ github.event.pull_request.number }}
157+
TARGET_REPO_PR_URL: ${{ steps.create_pr.outputs.pr_url }}
158+
PR_ACTION: ${{ steps.create_pr.outputs.pr_action }}
159+
run: |
160+
if [ "${{ env.PR_ACTION }}" = "created" ]; then
161+
COMMENT_BODY="✅ A new PR has been created in buildah to vendor these changes: **${{ env.TARGET_REPO_PR_URL }}**"
162+
gh pr comment ${{ env.SELF_REPO_PR_NUMBER }} \
163+
--repo ${{ github.repository }} \
164+
--body "$COMMENT_BODY"
165+
fi
166+
167+
- name: 'Skip workflow - No relevant Go files changed'
168+
if: steps.check_go_changes.outputs.should_run == 'false'
169+
run: |
170+
echo "✅ Workflow completed successfully - No relevant Go files were changed in this PR."
171+
echo "The downstream sync workflow was skipped as it only runs when non-test .go files (excluding vendor/) are modified."

go.work.sum

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.26.0
2222
github.com/Microsoft/cosesign1go v1.4.0/go.mod h1:1La/HcGw19rRLhPW0S6u55K6LKfti+GQSgGCtrfhVe8=
2323
github.com/Microsoft/didx509go v0.0.3/go.mod h1:wWt+iQsLzn3011+VfESzznLIp/Owhuj7rLF7yLglYbk=
2424
github.com/Microsoft/go-winio v0.4.21/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
25+
github.com/Microsoft/hcsshim v0.12.9/go.mod h1:fJ0gkFAna6ukt0bLdKB8djt4XIJhF/vEPuoIWYVvZ8Y=
2526
github.com/Microsoft/hcsshim v0.13.0/go.mod h1:9KWJ/8DgU+QzYGupX4tzMhRQE8h6w90lH6HAaclpEok=
2627
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
2728
github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I=
@@ -33,6 +34,7 @@ github.com/akavel/rsrc v0.10.2/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxk
3334
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
3435
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
3536
github.com/alexflint/go-filemutex v1.3.0/go.mod h1:U0+VA/i30mGBlLCrFPGtTe9y6wGQfNAWPBTekHQ+c8A=
37+
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
3638
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
3739
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
3840
github.com/aws/aws-sdk-go-v2 v1.32.8/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U=
@@ -65,6 +67,7 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
6567
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
6668
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
6769
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w=
70+
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
6871
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
6972
github.com/containerd/console v1.0.4/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
7073
github.com/containerd/containerd v1.7.23/go.mod h1:7QUzfURqZWCZV7RLNEn1XjUCQLEf0bkaK4GjUaZehxw=
@@ -75,7 +78,9 @@ github.com/containerd/go-runc v1.0.0/go.mod h1:cNU0ZbCgCQVZK4lgG3P+9tn9/PaJNmoDX
7578
github.com/containerd/protobuild v0.3.0/go.mod h1:5mNMFKKAwCIAkFBPiOdtRx2KiQlyEJeMXnL5R1DsWu8=
7679
github.com/containerd/stargz-snapshotter/estargz v0.16.3/go.mod h1:uyr4BfYfOj3G9WBVE8cOlQmXAbPN9VEQpBBeJIuOipU=
7780
github.com/containerd/ttrpc v1.2.5/go.mod h1:YCXHsb32f+Sq5/72xHubdiJRQY9inL4a4ZQrAbN1q9o=
81+
github.com/containerd/typeurl/v2 v2.2.0/go.mod h1:8XOOxnyatxSWuG8OfsZXVnAF4iZfedjS/8UHSPJnX4g=
7882
github.com/containerd/typeurl/v2 v2.2.3/go.mod h1:95ljDnPfD3bAbDJRugOiShd/DlAAsxGtUBhJxIn7SCk=
83+
github.com/containers/storage v1.59.1/go.mod h1:KoAYHnAjP3/cTsRS+mmWZGkufSY2GACiKQ4V3ZLQnR0=
7984
github.com/coreos/go-iptables v0.8.0/go.mod h1:Qe8Bv2Xik5FyTXwgIbLAnv2sWSBmvWdFETJConOQ//Q=
8085
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
8186
github.com/danieljoos/wincred v1.2.2/go.mod h1:w7w4Utbrz8lqeMbDAK0lkNJUv5sAOkFi7nd/ogr0Uh8=
@@ -105,6 +110,7 @@ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVI
105110
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
106111
github.com/golang/glog v1.2.4/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
107112
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
113+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
108114
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
109115
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
110116
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
@@ -114,13 +120,15 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
114120
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
115121
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
116122
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
123+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
117124
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
118125
github.com/google/certificate-transparency-go v1.3.1/go.mod h1:gg+UQlx6caKEDQ9EElFOujyxEQEfOiQzAt6782Bvi8k=
119126
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
120127
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
121128
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
122129
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
123130
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
131+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
124132
github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM=
125133
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
126134
github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA=
@@ -180,6 +188,7 @@ github.com/proglottis/gpgme v0.1.4/go.mod h1:5LoXMgpE4bttgwwdv9bLs/vwqv3qV7F4glE
180188
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
181189
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
182190
github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
191+
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
183192
github.com/rs/cors v1.11.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=
184193
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
185194
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
@@ -282,6 +291,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
282291
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
283292
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
284293
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
294+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
295+
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
285296
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
286297
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
287298
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 commit comments

Comments
 (0)