|
34 | 34 |
|
35 | 35 |
|
36 | 36 | 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 | + |
37 | 84 | terraform:
|
| 85 | + needs: check-changes |
| 86 | + if: needs.check-changes.outputs.stack_changed == 'true' |
38 | 87 | name: 'Apply Terraform'
|
39 | 88 | runs-on: ubuntu-latest
|
40 | 89 | outputs:
|
|
0 commit comments