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

chore(e2e): skip PR build for changes limited to e2e folder or existing image #2135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 37 additions & 1 deletion .github/workflows/pr-build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,26 @@ jobs:
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 -qv '^e2e-tests/'; then
echo "Changes detected outside the e2e folder. Proceeding with the build."
echo "proceed_with_build=true" >> $GITHUB_ENV
else
echo "No changes outside the e2e folder. Skipping the build."
echo "proceed_with_build=false" >> $GITHUB_ENV

- name: Get the last commit short SHA of the PR
if: env.proceed_with_build == 'true'
run: |
SHORT_SHA=$(git rev-parse --short=8 ${{ github.event.pull_request.head.sha }})
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
Expand All @@ -63,7 +82,24 @@ jobs:
-e 's|("Last Commit:.+)|"Last Commit: '$repoPR' @ '$SHORT_SHA'"|'
fi

- name: Check if Image Already Exists
if: env.proceed_with_build == 'true'
run: |
IMAGE_TAG="pr-${{ github.event.number }}"
IMAGE_NAME="${{ env.REGISTRY }}/janus-idp/backstage-showcase:${IMAGE_TAG}"

HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://quay.io/v2/janus-idp/backstage-showcase/manifests/${IMAGE_TAG}")

if [ "$HTTP_CODE" -eq 200 ]; then
echo "Image $IMAGE_NAME already exists. 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 }}
Expand All @@ -73,11 +109,11 @@ jobs:
imageTags: |
type=ref,prefix=pr-,event=pr
type=ref,prefix=pr-,suffix=-${{ env.SHORT_SHA }},event=pr
# to autodelete PR image tags, set an expiry date
imageLabels: quay.expires-after=14d
push: true

- name: Comment the image pull link
if: env.proceed_with_build == 'true' && env.image_exists == 'false'
uses: actions/github-script@v7
with:
script: |
Expand Down
Loading