chore(test): fix quay tests and improve RBAC testing for scaffolding #3300
Workflow file for this run
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
# Copyright Red Hat, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
name: PR Build Image | |
on: | |
pull_request_target: | |
paths-ignore: | |
- 'docs/**' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.number || github.event.pull_request.head.ref }} | |
cancel-in-progress: true | |
env: | |
REGISTRY: quay.io | |
jobs: | |
build-image: | |
name: Build Image | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
pull-requests: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- name: Get the latest commits from base branch | |
run: | | |
git remote add base-origin https://github.com/${{ github.repository }} || true | |
git config user.name "${{ github.event.pull_request.user.login }}" | |
git config user.email "${{ github.event.pull_request.user.email }}" | |
echo "Updating PR with latest commits from ${{ github.event.pull_request.base.ref }} ..." | |
git fetch base-origin ${{ github.event.pull_request.base.ref }} | |
git merge --no-edit base-origin/${{ github.event.pull_request.base.ref }} | |
- name: Determine Changed Files | |
id: changes | |
run: | | |
BASE_COMMIT=${{ github.event.pull_request.base.sha }} | |
HEAD_COMMIT=${{ github.event.pull_request.head.sha }} | |
CHANGED_FILES=$(git diff --name-only "$BASE_COMMIT" "$HEAD_COMMIT") | |
echo "Changed files:" | |
echo "$CHANGED_FILES" | |
if echo "$CHANGED_FILES" | grep -qvE '^(e2e-tests/|\.ibm/)'; then | |
echo "Changes detected outside the e2e-tests or .ibm folders. Proceeding with the build." | |
echo "proceed_with_build=true" >> $GITHUB_ENV | |
else | |
echo "No significant changes detected. Skipping the build." | |
echo "proceed_with_build=false" >> $GITHUB_ENV | |
fi | |
- name: Get the last commit short SHA of the PR | |
uses: ./.github/actions/get-sha | |
- name: Check if Image Already Exists | |
if: env.proceed_with_build == 'true' | |
run: | | |
IMAGE_TAG="pr-${{ github.event.number }}" | |
IMAGE_NAME="${{ env.REGISTRY }}/rhdh-community/rhdh:${IMAGE_TAG}" | |
# Check if any image tag exists for the PR | |
IMAGE_TAGS=$(curl -s "https://quay.io/api/v1/repository/rhdh-community/rhdh/tag/" | jq -r --arg tag "$IMAGE_TAG" '.tags[] | select(.name | startswith($tag)) | .name') | |
if [ -n "$IMAGE_TAGS" ]; then | |
echo "Image $IMAGE_NAME or its variants already exist. Skipping the build." | |
echo "image_exists=true" >> $GITHUB_ENV | |
else | |
echo "Image $IMAGE_NAME does not exist. Proceeding with the build." | |
echo "image_exists=false" >> $GITHUB_ENV | |
fi | |
- name: Build and Push with Buildx | |
if: env.proceed_with_build == 'true' && env.image_exists == 'false' | |
uses: ./.github/actions/docker-build | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ secrets.QUAY_USERNAME }} | |
password: ${{ secrets.QUAY_TOKEN }} | |
imageName: rhdh-community/rhdh | |
imageTags: | | |
type=ref,prefix=pr-,event=pr | |
type=ref,prefix=pr-,suffix=-${{ env.SHORT_SHA }},event=pr | |
imageLabels: quay.expires-after=14d | |
push: true | |
platform: linux/amd64 | |
- name: Comment the image pull link | |
if: env.proceed_with_build == 'true' && env.image_exists == 'false' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'The image is available at:\n* [`quay.io/rhdh-community/rhdh:pr-${{ github.event.number }}`](https://quay.io/rhdh-community/rhdh:pr-${{ github.event.number }}) or\n* [`quay.io/rhdh-community/rhdh:pr-${{ github.event.number }}-${{ env.SHORT_SHA }}`](https://quay.io/rhdh-community/rhdh:pr-${{ github.event.number }}-${{ env.SHORT_SHA }})' | |
}) |