Skip to content

Commit f5020f4

Browse files
Merge pull request #10 from arvatoaws-labs/stack-filter
final job
2 parents 4998e0e + f7d1870 commit f5020f4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

.github/workflows/githubaction-comment-apply.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,56 @@ on:
3434

3535

3636
jobs:
37+
check-changes:
38+
runs-on: ubuntu-latest
39+
outputs:
40+
stack_changed: ${{ steps.filter.outputs.stack_changed }}
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v2
44+
with:
45+
fetch-depth: 0 # Important to fetch all history for branches
46+
47+
- name: Check for changes in the stack based on input
48+
id: filter
49+
run: |
50+
STACK_DIR=${{ inputs.stack }}
51+
echo "Checking for changes in the $STACK_DIR directory..."
52+
53+
PR_NUMBER=$(echo ${{ github.event.issue.pull_request.url }} | grep -o '[^/]*$')
54+
55+
HEAD_SHA=$(gh pr view $PR_NUMBER --json headRefOid -q .headRefOid)
56+
BASE_BRANCH=$(gh pr view $PR_NUMBER --json baseRefName -q .baseRefName)
57+
58+
# Ensure correct repo syntax for GH API call
59+
REPO="${{ github.repository }}"
60+
BASE_SHA=$(gh api repos/$REPO/commits/$BASE_BRANCH --jq '.sha')
61+
62+
echo "Base branch latest commit SHA: $BASE_SHA, PR head commit SHA: $HEAD_SHA"
63+
64+
if git diff --name-only $BASE_SHA $HEAD_SHA | grep -q "^${STACK_DIR}/"; then
65+
echo "Changes detected in the $STACK_DIR directory."
66+
echo "stack_changed=true" >> $GITHUB_OUTPUT
67+
else
68+
echo "No changes detected in the $STACK_DIR directory."
69+
echo "stack_changed=false" >> $GITHUB_OUTPUT
70+
fi
71+
env:
72+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
shell: bash
74+
75+
- name: Set output
76+
run: |
77+
echo "Final stack_changed value: ${{ env.stack_changed }}"
78+
echo "stack_changed=${{ env.stack_changed }}" >> $GITHUB_OUTPUT
79+
- name: Debug stack_changed output
80+
run: |
81+
echo "stack_changed set to: ${{ steps.filter.outputs.stack_changed }}"
82+
if: always()
83+
3784
terraform:
85+
needs: check-changes
86+
if: needs.check-changes.outputs.stack_changed == 'true'
3887
name: 'Apply Terraform'
3988
runs-on: ubuntu-latest
4089
outputs:

0 commit comments

Comments
 (0)