Skip to content

Commit 2569be4

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

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
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@v4
43+
with:
44+
go-version: '1.21'
45+
46+
- name: 'Checkout forked buildah'
47+
if: steps.check_go_changes.outputs.should_run == 'true'
48+
uses: actions/checkout@v4
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+
# Update the go.mod file to use the specific commit
74+
go mod edit -replace go.podman.io/common=github.com/flouthoc/container-libs/common@${COMMIT_SHA}
75+
76+
echo "After go mod edit"
77+
cat go.mod
78+
79+
# Download and verify the module
80+
GOWORK=off go mod tidy
81+
GOWORK=off go mod vendor
82+
GOWORK=off go mod verify
83+
84+
echo "Updated go.mod:"
85+
cat go.mod
86+
87+
- name: 'Commit and Push to buildah'
88+
if: steps.check_go_changes.outputs.should_run == 'true'
89+
run: |
90+
cd buildah
91+
git config user.name "github-actions[bot]"
92+
git config user.email "github-actions[bot]@users.noreply.github.com"
93+
94+
BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}"
95+
git switch $BRANCH_NAME
96+
97+
git add .
98+
git commit -m "feat: Vendor changes from podmanbot/container-libs#${{ github.event.pull_request.number }}"
99+
100+
# Force push to update the branch if the action re-runs on 'synchronize'
101+
git push origin $BRANCH_NAME --force
102+
103+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
104+
105+
- name: 'Create or Update Pull Request in Buildah'
106+
if: steps.check_go_changes.outputs.should_run == 'true'
107+
id: create_pr
108+
env:
109+
GH_TOKEN: ${{ secrets.VENDOR_TOKEN_PODMANBOT }}
110+
SELF_REPO_PR_NUMBER: ${{ github.event.pull_request.number }}
111+
SELF_REPO_PR_URL: ${{ github.event.pull_request.html_url }}
112+
SELF_REPO_PR_TITLE: ${{ github.event.pull_request.title }}
113+
run: |
114+
cd buildah
115+
116+
BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}"
117+
PR_TITLE="Sync: ${{ env.SELF_REPO_PR_TITLE }}"
118+
PR_BODY="This PR automatically vendors changes from [repo-A#${{ env.SELF_REPO_PR_NUMBER }}](${{ env.SELF_REPO_PR_URL }})."
119+
120+
# Check if PR already exists for this branch
121+
echo "Searching for existing PR with branch: $BRANCH_NAME"
122+
123+
EXISTING_PR_URL=$(gh pr list --repo flouthoc/buildah --head "$BRANCH_NAME" --json url --jq '.[0].url // empty' 2>/dev/null || echo "")
124+
125+
if [ -n "$EXISTING_PR_URL" ]; then
126+
echo "Found existing PR: $EXISTING_PR_URL"
127+
# Update existing PR title and body
128+
gh pr edit $EXISTING_PR_URL \
129+
--title "$PR_TITLE" \
130+
--body "$PR_BODY"
131+
echo "Updated existing PR: $EXISTING_PR_URL"
132+
echo "pr_url=$EXISTING_PR_URL" >> $GITHUB_OUTPUT
133+
echo "pr_action=updated" >> $GITHUB_OUTPUT
134+
else
135+
# Create new PR
136+
NEW_PR_URL=$(gh pr create \
137+
--repo flouthoc/buildah \
138+
--base main \
139+
--head "$BRANCH_NAME" \
140+
--title "$PR_TITLE" \
141+
--body "$PR_BODY")
142+
echo "Created new PR: $NEW_PR_URL"
143+
echo "pr_url=$NEW_PR_URL" >> $GITHUB_OUTPUT
144+
echo "pr_action=created" >> $GITHUB_OUTPUT
145+
fi
146+
147+
- name: 'Comment on container-libs PR with the link to buildah PR'
148+
if: steps.check_go_changes.outputs.should_run == 'true'
149+
env:
150+
GH_TOKEN: ${{ secrets.VENDOR_TOKEN_PODMANBOT }}
151+
SELF_REPO_PR_NUMBER: ${{ github.event.pull_request.number }}
152+
TARGET_REPO_PR_URL: ${{ steps.create_pr.outputs.pr_url }}
153+
PR_ACTION: ${{ steps.create_pr.outputs.pr_action }}
154+
run: |
155+
if [ "${{ env.PR_ACTION }}" = "created" ]; then
156+
COMMENT_BODY="✅ A new PR has been created in buildah to vendor these changes: **${{ env.TARGET_REPO_PR_URL }}**"
157+
else
158+
COMMENT_BODY="✅ The existing PR in buildah has been updated with these changes: **${{ env.TARGET_REPO_PR_URL }}**"
159+
fi
160+
161+
gh pr comment ${{ env.SELF_REPO_PR_NUMBER }} \
162+
--repo ${{ github.repository }} \
163+
--body "$COMMENT_BODY"
164+
165+
- name: 'Skip workflow - No Go files changed'
166+
if: steps.check_go_changes.outputs.should_run == 'false'
167+
run: |
168+
echo "✅ Workflow completed successfully - No Go files were changed in this PR."
169+
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)