Skip to content
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

sync workflow: send PR instead of pushing to main #43

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions .github/workflows/build-definitions-sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

permissions:
contents: write
pull-requests: write

jobs:
build-definitions-sync:
Expand All @@ -16,28 +17,57 @@ jobs:
uses: actions/checkout@v4
with:
path: tssc-sample-pipelines
ref: main

- name: Checkout build-definitions
uses: actions/checkout@v4
with:
repository: redhat-appstudio/build-definitions
path: build-definitions

- name: Synchronize build-definitions
run: |
export BUILD_DEFINITIONS=$GITHUB_WORKSPACE/build-definitions
$GITHUB_WORKSPACE/tssc-sample-pipelines/hack/import-build-definitions
- name: Commit changes

- name: Create a PR with the changes
env:
GH_TOKEN: ${{ github.token }}
run: |
cd $GITHUB_WORKSPACE/tssc-sample-pipelines/

if [[ -z $(git status -s) ]]; then
echo 'No changes has been detected'
exit 0
fi

echo "Updates detected"
update_branch=selfupdate/import-build-definitions

git checkout -b "$update_branch"

git diff
git config --global user.name 'RHTAP bot'
git config --global user.email '[email protected]'
git add .

echo "Pushing to $update_branch"
git commit -m "Sync build-definitions"
git push
git push -f --set-upstream origin "$update_branch"

cat <<- 'EOF' > /tmp/body.txt
Synchronize changes from https://github.com/konflux-ci/build-definitions

(Done using the `hack/import-build-definitions` script)
EOF

echo "Checking if PR exists for $update_branch"
pr_number=$(
gh pr list --base main --head "$update_branch" --json number --jq '.[].number'
)
if [[ -z "$pr_number" ]]; then
echo "Creating PR"
gh pr create --title "Sync build-definitions" --body-file /tmp/body.txt
else
echo "Found existing PR: #$pr_number"
gh pr edit "$pr_number" --title "Sync build-definitions" --body-file /tmp/body.txt
fi