-
Notifications
You must be signed in to change notification settings - Fork 2
89 lines (78 loc) · 2.94 KB
/
build-and-push.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Docker Image Build and Push
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'action.yml'
- .github/workflows/build-and-push.yml
- 'draft_images/py-rocket-2/**'
- 'draft_images/coastwatch-qgis/**'
- 'draft_images/test/**'
env:
WATCHED_DIRECTORIES: |
draft_images/py-rocket-2
draft_images/coastwatch-qgis
draft_images/test
jobs:
find-changes:
runs-on: ubuntu-latest
outputs:
matrix_dirs: ${{ steps.find-changes.outputs.matrix_dirs }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Find changed directories
id: find-changes
run: |
# Prepare the watched directories list as a single line with | separator
watched_dirs=$(echo "${WATCHED_DIRECTORIES}" | tr '\n' '|')
all_changed_dirs=$(git diff --name-only HEAD^ HEAD | grep -E "^(${watched_dirs})" | sort -u)
echo "Debugging: all_changed_dirs is $all_changed_dirs"
# Now apply sed to reduce each path to the top-level watched directory
dirs=$(echo "$all_changed_dirs" | while read -r path; do
# Match the path to one of the watched directories, preserving only the matched part
for watched in ${WATCHED_DIRECTORIES}; do
if [[ "$path" == $watched* ]]; then
echo "$watched"
fi
done
done | sort -u | uniq)
echo "Filtered directories: $dirs"
echo "Debugging: all_changed_dirs is $dirs"
if [ -z "$dirs" ]; then
echo "No changed directories"
echo "::set-output name=matrix_dirs::[]" # Set an empty array to handle no changes
exit 0
fi
# Convert to JSON array for matrix strategy
matrix_dirs=$(echo "$dirs" | jq -R -s -c 'split("\n") | map(select(. != ""))')
echo "::set-output name=matrix_dirs::$matrix_dirs"
echo "Debugging: matrix_dirs output is $matrix_dirs"
# Build job using matrix
build:
runs-on: ubuntu-latest
needs: find-changes
if: needs.find-changes.outputs.matrix_dirs != '[]' # Only run if there are changed directories
strategy:
matrix:
dir: ${{ fromJson(needs.find-changes.outputs.matrix_dirs) }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Extract image name
id: extract-name
shell: bash
run: |
full_image_name="${{ github.event.repository.name }}/$(basename ${{ matrix.dir }})"
echo "image_name=$full_image_name" >> $GITHUB_ENV
echo "Full image name set to: $full_image_name"
- name: Use reusable action for each directory
uses: nmfs-opensci/container-images@main
with:
image_dir: ${{ matrix.dir }}
image_name: ${{ env.image_name }}
github_token: ${{ secrets.GITHUB_TOKEN }}