Trigger clair db image build #80
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: Trigger clair db image build | |
# This workflow creates/reopens PR and closes it | |
# in order to trigger PAC to build clair DB image | |
on: | |
schedule: | |
- cron: '0 4 * * *' | |
env: | |
REGISTRY: quay.io/redhat-appstudio | |
IMAGE_NAME: clair-in-ci | |
LATEST_TAG: latest | |
PREVIOUS_TAG: previous | |
GITHUB_TOKEN: ${{ secrets.HACBS_TEST_GITHUB_TOKEN }} | |
TARGET_BRANCH: daily | |
SOURCE_BRANCH: main # building from main | |
jobs: | |
test: | |
name: Build the new image | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
with: | |
ref: 'main' | |
- name: create pull request & empty commit | |
run: | | |
git config --global user.email "<>" | |
git config --global user.name "hacbs-test-bot" | |
echo "Check if PR is already created." | |
PR_NUMBER=$(gh pr list --state all --label clair-db --json number | jq -r '.[0] | .number') | |
if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" == null ]; then | |
echo "No existing PR with label clair-db was found. Creating a new PR..." | |
gh pr create -B $TARGET_BRANCH -H $SOURCE_BRANCH --title 'Using branch: "${SOURCE_BRANCH}" to create PR triggering clair-db build PAC.' --body 'Created by Github action' --label clair-db | |
sleep 5 | |
PR_NUMBER=$(gh pr list --state all --label clair-db --json number | jq -r '.[0] | .number') | |
fi | |
PR_STATE=$(gh pr view $PR_NUMBER --json state | jq -r '.state') | |
if [ "$PR_STATE" != "OPEN" ]; then | |
echo "$PR_NUMBER is $PR_STATE, reopening it now." | |
gh pr reopen $PR_NUMBER | |
echo "PR number: $PR_NUMBER has been opened." | |
else | |
git commit --allow-empty -m "$(date)" | |
git push origin "${SOURCE_BRANCH}" -f | |
fi |