Skip to content

Check for new Preflight release and create PR #217

Check for new Preflight release and create PR

Check for new Preflight release and create PR #217

name: Check for new Preflight release and create PR
on:
schedule:
- cron: '0 8 * * *' # daily at 8 AM
workflow_dispatch:
jobs:
check-new-release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Preflight latest release
id: preflight_latest
uses: pozetroninc/[email protected]
with:
owner: redhat-openshift-ecosystem
repo: openshift-preflight
excludes: prerelease, draft
- name: Get preflight release in the repo
id: get_current_release
run: |
preflight_current=$(awk -F: '/^preflight_image:/ {print $NF}' roles/preflight/defaults/main.yml | tr -d '"')
echo "Preflight current release: $preflight_current"
echo "preflight_current=$preflight_current" >> $GITHUB_OUTPUT
- name: Compare versions
id: compare_versions
env:
PREFLIGHT_LATEST: ${{ steps.preflight_latest.outputs.release }}
PREFLIGHT_CURRENT: ${{ steps.get_current_release.outputs.preflight_current }}
run: |
if [ "$PREFLIGHT_LATEST" != "$PREFLIGHT_CURRENT" ]; then
echo "New Preflight release found: $PREFLIGHT_LATEST, current: $PREFLIGHT_CURRENT"
echo "new_release=true" >> $GITHUB_OUTPUT
else
echo "Both Preflight latest and current are the same: $PREFLIGHT_LATEST"
echo "new_release=false" >> $GITHUB_OUTPUT
fi
- name: Check if branch exists
id: check_branch
if: steps.compare_versions.outputs.new_release == 'true'
env:
PREFLIGHT_LATEST: ${{ steps.preflight_latest.outputs.release }}
run: |
branch_exists=$(git ls-remote --heads origin preflight-release-$PREFLIGHT_LATEST)
if [ -n "$branch_exists" ]; then
echo "Branch preflight-release-$PREFLIGHT_LATEST already exists"
echo "branch_exists=true" >> $GITHUB_OUTPUT
else
echo "Branch preflight-release-$PREFLIGHT_LATEST does not exist"
echo "branch_exists=false" >> $GITHUB_OUTPUT
fi
- name: Import GPG key
if: steps.compare_versions.outputs.new_release == 'true' && steps.check_branch.outputs.branch_exists == 'false'
env:
GPG_PRIVATE_KEY_DCIBOT: ${{ secrets.GPG_PRIVATE_KEY_DCIBOT }}
run: |
echo "$GPG_PRIVATE_KEY_DCIBOT" | gpg --batch --import
- name: Configure git for GPG
if: steps.compare_versions.outputs.new_release == 'true' && steps.check_branch.outputs.branch_exists == 'false'
env:
DCIBOT_EMAIL: ${{ secrets.DCIBOT_EMAIL }}
run: |
GPG_KEY=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d '/' -f 2)
git config --global user.signingkey "$GPG_KEY"
git config --global gpg.program gpg
git config --global commit.gpgSign true
git config --global user.name "dcibot"
git config --global user.email "$DCIBOT_EMAIL"
- name: Create new branch with updated Preflight version
if: steps.compare_versions.outputs.new_release == 'true' && steps.check_branch.outputs.branch_exists == 'false'
env:
PREFLIGHT_LATEST: ${{ steps.preflight_latest.outputs.release }}
run: |
# Pull the latest changes from the main branch
git fetch origin main
git checkout main
git pull origin main
# Create a new branch from the main branch
git checkout -b preflight-release-$PREFLIGHT_LATEST
# Update preflight version
sed -i "s|quay.io/opdev/preflight:[0-9]*\.[0-9]*\.[0-9]*|quay.io/opdev/preflight:${PREFLIGHT_LATEST}|" roles/preflight/defaults/main.yml
sed -i "s|quay.io/opdev/preflight:[0-9]*\.[0-9]*\.[0-9]*|quay.io/opdev/preflight:${PREFLIGHT_LATEST}|" roles/preflight/README.md
git add roles/preflight/defaults/main.yml roles/preflight/README.md
git commit -S -m "Update Preflight to release $PREFLIGHT_LATEST"
git push --set-upstream origin preflight-release-$PREFLIGHT_LATEST
- name: Create PR moving to the latest Preflight
if: steps.compare_versions.outputs.new_release == 'true' && steps.check_branch.outputs.branch_exists == 'false'
env:
PREFLIGHT_LATEST: ${{ steps.preflight_latest.outputs.release }}
GITHUB_TOKEN: ${{ secrets.DCIBOT_TOKEN }}
run: |
gh pr create \
--title "Move to Preflight release $PREFLIGHT_LATEST" \
--body "This pull request was opened by a bot." \
--base main \
--head preflight-release-$PREFLIGHT_LATEST