Skip to content

Commit 3a65ae3

Browse files
committed
add conditions to run the e2e workflow
1 parent 259f047 commit 3a65ae3

1 file changed

Lines changed: 51 additions & 3 deletions

File tree

.github/workflows/end-to-end.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,63 @@ name: End-to-end
33
# on:
44
# schedule:
55
# - cron: "0 4 * * *"
6+
7+
# TODO: Use workflow dispatch for testing manually. Should only enable schedule run when merging the PR
68
on:
79
workflow_dispatch:
810
inputs:
911
environment:
1012
description: "Environment to run tests against"
1113
type: environment
1214
required: true
15+
default: test
16+
alerts:
17+
description: "Send Slack alerts"
18+
type: boolean
19+
default: false
1320

1421
jobs:
22+
check-for-updates:
23+
runs-on: ubuntu-latest
24+
outputs:
25+
should_run: ${{ steps.check-pushes.outputs.should_run }}
26+
steps:
27+
- name: Checkout main branch
28+
uses: actions/checkout@v5
29+
with:
30+
ref: main
31+
32+
- name: Get last workflow run SHA
33+
id: get-last-sha
34+
run: |
35+
LAST_COMPLETED_RUN_SHA=$(curl -s -L \
36+
-H "Accept: application/vnd.github.v3+json" \
37+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
38+
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/${{ github.run_id }}/runs?status=completed&per_page=1" | \
39+
jq -r '.workflow_runs[0].head_sha // ""')
40+
echo "LAST_COMPLETED_RUN_SHA=$LAST_COMPLETED_RUN_SHA" >> $GITHUB_OUTPUT
41+
42+
- name: Check for new pushes
43+
id: check-pushes
44+
run: |
45+
CURRENT_MAIN_SHA=$(git rev-parse HEAD)
46+
echo "Current main branch HEAD SHA: $CURRENT_MAIN_SHA"
47+
echo "Last completed workflow run SHA: ${{ steps.get-last-sha.outputs.LAST_COMPLETED_RUN_SHA }}"
48+
49+
if [ -z "${{ steps.get-last-sha.outputs.LAST_COMPLETED_RUN_SHA }}" ]; then
50+
echo "No previous successful runs found for this workflow. Running workflow."
51+
echo "should_run=true" >> $GITHUB_OUTPUT
52+
elif [ "$CURRENT_MAIN_SHA" == "${{ steps.get-last-sha.outputs.LAST_COMPLETED_RUN_SHA }}" ]; then
53+
echo "No new pushes on main since last successful run. Skipping workflow."
54+
echo "should_run=false" >> $GITHUB_OUTPUT
55+
else
56+
echo "New pushes detected on main. Proceeding with workflow."
57+
echo "should_run=true" >> $GITHUB_OUTPUT
58+
fi
59+
1560
build-apps-image:
61+
needs: check-for-updates
62+
if: needs.check-for-updates.outputs.should_run == 'true'
1663
environment: test
1764
runs-on: ubuntu-latest
1865
steps:
@@ -546,7 +593,7 @@ jobs:
546593

547594
clean-apps-image:
548595
environment: test
549-
needs: apps
596+
needs: [apps]
550597
if: always()
551598
runs-on: ubuntu-latest
552599
steps:
@@ -571,10 +618,11 @@ jobs:
571618
GITHUB_ACTOR: ${{ github.actor }}
572619
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
573620

621+
# Alert run condition github.event.inputs.alerts == 'true' should be changed to always() when PR is ready to merge
574622
alert:
575-
runs-on: ubuntu-latest
576623
needs: [clean-apps-image]
577-
if: always() && github.ref == 'refs/heads/main'
624+
runs-on: ubuntu-latest
625+
if: github.event.inputs.alerts == 'true' && github.ref == 'refs/heads/main'
578626
steps:
579627
- id: get-sha
580628
run: |

0 commit comments

Comments
 (0)