-
Notifications
You must be signed in to change notification settings - Fork 1
44 lines (40 loc) · 1.46 KB
/
diff-last-run.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
name: Diff with last workflow run
on:
workflow_call:
inputs:
CHECK_DIFF_LOCATIONS:
type: string
required: true
outputs:
CHANGES:
description: "Whether the given directories have changed since the last successfull workflow run."
value: ${{ jobs.diff.outputs.CHANGES }}
jobs:
diff:
runs-on: ubuntu-latest
outputs:
CHANGES: ${{ steps.git_changes.outputs.CHANGES }}
steps:
- name: Get last run commit SHA
run: |
LAST_RUN_SHA=$(curl --fail -s -S --request GET \
--url https://api.github.com/repos/${{ github.repository }}/actions/runs?branch=${{ github.head_ref || github.ref_name }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
| jq -r '.workflow_runs[] | select(.conclusion == "success") | .head_sha' | head -1)
echo LAST_RUN_SHA=$LAST_RUN_SHA >> $GITHUB_ENV
shell: bash
- name: Checkout current version
uses: actions/checkout@v4
- name: Checkout last build
uses: actions/checkout@v4
with:
ref: ${{ env.LAST_RUN_SHA }}
- name: Check for changes
id: git_changes
run: |
if git diff --exit-code ${{ env.LAST_RUN_SHA }} ${{ github.sha }} -- ${{ inputs.CHECK_DIFF_LOCATIONS }} .github/workflows/; then
echo "CHANGES=false" >> $GITHUB_OUTPUT
else
echo "CHANGES=true" >> $GITHUB_OUTPUT
fi
shell: bash