Pull changes from build-definitions #282
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull changes from build-definitions | |
on: | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
build-definitions-sync: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
path: tssc-sample-pipelines | |
ref: main | |
- name: Checkout build-definitions | |
uses: actions/checkout@v4 | |
with: | |
repository: konflux-ci/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: 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 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 -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 |