forked from coecms/cms-conda-singularity
-
Notifications
You must be signed in to change notification settings - Fork 0
41 lines (41 loc) · 1.63 KB
/
get_changed_env.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
name: Get changed conda envs
on:
workflow_call:
outputs:
matrix:
value: ${{ jobs.generate_matrix.outputs.matrix }}
jobs:
generate_matrix:
name: Determine changed environments
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.diff.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Check changed environments
id: diff
run: |
# See https://github.community/t/check-pushed-file-changes-with-git-diff-tree-in-github-actions/17220/10
### https://stackoverflow.com/questions/59977364/github-actions-how-use-strategy-matrix-with-script
if [ $GITHUB_BASE_REF ]; then
# Pull Request
git fetch origin $GITHUB_BASE_REF --depth=1
export DIFF=$( git diff --name-only origin/$GITHUB_BASE_REF $GITHUB_SHA )
echo "Diff between origin/$GITHUB_BASE_REF and $GITHUB_SHA"
else
# Push
git fetch origin ${{ github.event.before }} --depth=1
export DIFF=$( git diff --name-only ${{ github.event.before }} $GITHUB_SHA )
echo "Diff between ${{ github.event.before }} and $GITHUB_SHA"
fi
json="{\"include\":["
for line in $DIFF; do
if [[ $line =~ environments ]]; then
env_name=$( basename ${line%/*} )
if ! [[ $json =~ $env_name ]]; then
json="$json{\"environment\":\"$env_name\"},"
fi
fi
done
### https://github.com/actions/runner/issues/2947
echo "matrix=$( echo "${json%,}]}" | jq -r 'tostring' )" >> $GITHUB_OUTPUT