Skip to content

Commit

Permalink
Merge pull request #753 from carstingaxion/fix/playground-preview-run…
Browse files Browse the repository at this point in the history
…-build-on-pr-opening

Make sure the build step runs at least once, when the PR is opened.
  • Loading branch information
carstingaxion authored Aug 2, 2024
2 parents 0f1d8b8 + 48665bb commit fd21c7d
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions .github/workflows/playground-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,37 @@ concurrency:

jobs:

check-changes:
name: Check for changes in /src/ directory
needs-build:
name: Check if the pull request was just opened or if PR has changes in /src/ directory
runs-on: ubuntu-latest
outputs:
src_changed: ${{ steps.src_changed.outputs.src_changed }}
run_build: ${{ steps.set-run-build.outputs.run_build }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Check if /src/ directory has changed
id: src_changed
- name: Set run_build for initial PR or /src/ changes
id: set-run-build
run: |
# Check if there are changes in the /src/ directory between the base and head refs
if git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep -q '^src/'; then
echo "src_changed=true" >> $GITHUB_ENV
echo "::set-output name=src_changed::true"
# Check if the pull request was just opened
if [ "${{ github.event.action }}" == "opened" ]; then
echo "run_build=true" >> $GITHUB_ENV
echo "::set-output name=run_build::true"
# Check if there are changes in the /src/ directory
elif git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | grep -q '^src/'; then
echo "run_build=true" >> $GITHUB_ENV
echo "::set-output name=run_build::true"
else
echo "src_changed=false" >> $GITHUB_ENV
echo "::set-output name=src_changed::false"
echo "run_build=false" >> $GITHUB_ENV
echo "::set-output name=run_build::false"
fi
zip:
name: Build GatherPress plugin & upload as zipped artifact
runs-on: ubuntu-latest
needs: check-changes
if: needs.check-changes.outputs.src_changed == 'true' # Only run this job if there are changes in /src/
needs: needs-build
if: needs.needs-build.outputs.run_build == 'true' # Only run this job if if the pull request was just opened or there are changes in /src/
steps:

- name: Checkout
Expand Down Expand Up @@ -92,7 +97,7 @@ jobs:

comment:
name: Comment with playground link
needs: [zip, check-changes] # Ensure this runs after the zip and check-changes jobs
needs: [zip, needs-build] # Ensure this runs after the zip and needs-build jobs
runs-on: ubuntu-latest

steps:
Expand Down

0 comments on commit fd21c7d

Please sign in to comment.