-
Notifications
You must be signed in to change notification settings - Fork 48
.github: add workflow to open downstream PR #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| name: 'Open downstream PRs' | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| branches: | ||
| - 'main' | ||
| paths: | ||
| - '**/*.go' | ||
| - '!vendor/**' | ||
| - '!**/*_test.go' | ||
|
|
||
| jobs: | ||
| sync: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: 'Checkout Self' | ||
| uses: actions/checkout@v5 | ||
| # This checks out the code from the PR branch itself | ||
|
|
||
| - name: 'Setup Go' | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
| go-version: 'stable' | ||
|
|
||
| - name: 'Checkout forked buildah' | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| repository: 'podmanbot/buildah' # The target repository | ||
| path: 'buildah' # Checkout into a sub-directory | ||
| fetch-depth: '1' | ||
| token: ${{ secrets.VENDOR_TOKEN_PODMANBOT }} # We need to push into pobmanbot/buildah | ||
|
|
||
| - name: 'Vendor Code from this repo to buildah' | ||
| run: | | ||
| # Get the current commit SHA from the PR | ||
| COMMIT_SHA="${{ github.event.pull_request.head.sha }}" | ||
| echo "Using commit SHA: $COMMIT_SHA" | ||
|
|
||
| cd buildah | ||
| # Create a unique branch name based on the container-libs PR number | ||
| BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}" | ||
| git switch -c $BRANCH_NAME | ||
| git remote add upstream https://github.com/containers/buildah.git | ||
| git fetch upstream | ||
| git rebase upstream/main | ||
|
Comment on lines
+44
to
+45
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already cloned the repo before so this just fetched the full history which seems unnecessary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are cloning
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but you don't have to clone podmanbot/buildah at all, you can clone https://github.com/containers/buildah.git just fine and then add podmanbot/buildah as push target without having to pull that one. I guess the repos are not that big that it matters that much but as far as checkout goes it should be enough to just clone with --depth=1 to not load the full history create a commit and push that one.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I set fetch
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well you still fetch the entire update repo here, anyway I guess performance wise it doesn't matter much so I don't care to much about it. |
||
|
|
||
| # Function to update module and verify | ||
| update_module() { | ||
| local module=$1 | ||
| echo "Updating module: $module" | ||
| go mod edit -replace ${module}=github.com/${{ github.event.pull_request.head.repo.full_name }}/${module#go.podman.io/}@${COMMIT_SHA} | ||
| GOWORK=off go mod tidy | ||
| } | ||
|
|
||
| # Update all required modules | ||
| update_module "go.podman.io/common" | ||
| update_module "go.podman.io/storage" | ||
| update_module "go.podman.io/image/v5" | ||
| GOWORK=off go mod vendor | ||
| GOWORK=off go mod verify | ||
|
|
||
| echo "Updated go.mod:" | ||
| cat go.mod | ||
|
|
||
| - name: 'Commit and Push to buildah' | ||
| run: | | ||
| cd buildah | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}" | ||
| git switch $BRANCH_NAME | ||
|
|
||
| git add . | ||
| git commit -m "dnm: Vendor changes from containers/container-libs#${{ github.event.pull_request.number }}" | ||
|
|
||
| # Force push to update the branch if the action re-runs on 'synchronize' | ||
| git push origin $BRANCH_NAME --force | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't origin containers/buildah here and the bot of course should have no direct push perms, it should push to its own fork and create the PR from there.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this push is going to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The origin is podmanbot/buildah afaik
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jankaluza Yes, Correct.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (when I added the comment the origin was not podmanbot) Anyhow logically it is really pointless to clone the outdated podmanbot repo. We just need to add this as remote to push to, we would ways want to clone only main of containers/buildah. Cloning the full history just makes things slower like I mentioned here: #305 (comment) Anyhow I am fine to merge it like this. We should first see if this works like that and is helpful before over optimizing I guess. |
||
|
|
||
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
|
|
||
| - name: 'Create or Update Pull Request in Buildah' | ||
| id: create_pr | ||
| env: | ||
| GH_TOKEN: ${{ secrets.VENDOR_TOKEN_PODMANBOT }} | ||
| SELF_REPO_PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| SELF_REPO_PR_URL: ${{ github.event.pull_request.html_url }} | ||
| SELF_REPO_PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: | | ||
| cd buildah | ||
|
|
||
| BRANCH_NAME="sync/container-libs-${{ github.event.pull_request.number }}" | ||
| PR_TITLE="Sync: ${{ env.SELF_REPO_PR_TITLE }}" | ||
| PR_BODY="This PR automatically vendors changes from [repo-A#${{ env.SELF_REPO_PR_NUMBER }}](${{ env.SELF_REPO_PR_URL }})." | ||
|
|
||
| # Check if PR already exists for this branch | ||
| echo "Searching for existing PR with branch: $BRANCH_NAME" | ||
|
|
||
| EXISTING_PR_URL=$(gh pr list --repo containers/buildah --head "$BRANCH_NAME" --json url --jq '.[0].url // empty' 2>/dev/null || echo "") | ||
|
|
||
| if [ -n "$EXISTING_PR_URL" ]; then | ||
| echo "Found existing PR: $EXISTING_PR_URL" | ||
| # Update existing PR title and body | ||
| gh pr edit $EXISTING_PR_URL \ | ||
| --title "$PR_TITLE" \ | ||
| --body "$PR_BODY" | ||
| echo "Updated existing PR: $EXISTING_PR_URL" | ||
| echo "pr_url=$EXISTING_PR_URL" >> $GITHUB_OUTPUT | ||
| echo "pr_action=updated" >> $GITHUB_OUTPUT | ||
| else | ||
| # Create new PR | ||
| NEW_PR_URL=$(gh pr create \ | ||
| --repo containers/buildah \ | ||
| --draft \ | ||
| --base main \ | ||
| --head "$BRANCH_NAME" \ | ||
| --title "$PR_TITLE" \ | ||
| --body "$PR_BODY") | ||
Luap99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "Created new PR: $NEW_PR_URL" | ||
| echo "pr_url=$NEW_PR_URL" >> $GITHUB_OUTPUT | ||
| echo "pr_action=created" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: 'Comment on container-libs PR with the link to buildah PR' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.VENDOR_TOKEN_PODMANBOT }} | ||
| SELF_REPO_PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| TARGET_REPO_PR_URL: ${{ steps.create_pr.outputs.pr_url }} | ||
| PR_ACTION: ${{ steps.create_pr.outputs.pr_action }} | ||
| run: | | ||
| if [ "${{ env.PR_ACTION }}" = "created" ]; then | ||
| COMMENT_BODY="✅ A new PR has been created in buildah to vendor these changes: **${{ env.TARGET_REPO_PR_URL }}**" | ||
| gh pr comment ${{ env.SELF_REPO_PR_NUMBER }} \ | ||
| --repo ${{ github.repository }} \ | ||
| --body "$COMMENT_BODY" | ||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.