Skip to content

Commit 17fe212

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

File tree

2 files changed

+178
-0
lines changed

2 files changed

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