-
Notifications
You must be signed in to change notification settings - Fork 1
98 lines (83 loc) · 2.96 KB
/
env-build.yaml
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
89
90
91
92
93
94
95
96
97
98
name: Docker automatic build and publish
on:
push:
branches:
- issue17_fix_root_env
# - main
env:
REGISTRY: ghcr.io
jobs:
build-matrix-from-changed-files:
runs-on: ubuntu-latest # windows-latest || macos-latest
name: Build matrix from directorues with changed files
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2 # "0" (OR "2" -> To retrieve the preceding commit).
- name: Run changed-files with dir_names
id: changed-files
uses: tj-actions/changed-files@v37
with:
files_ignore: |
.github/workflows/env-build.yaml
**/README.md
dir_names: "true"
dir_names_exclude_current_dir: "true"
- name: List all changed dirs and create list with unique directories
id: set-matrix
run: |
environments=()
for dir in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$dir was changed"
if [[ $(echo ${environments[@]} | fgrep -w ${dir}) ]]; then
echo " - ${dir} is in the list of changed dirs"
else
echo " - ${dir} is NOT in the list of changed dirs. Adding it!"
environments+=("\"${dir}\"")
echo " ** The update list is ${environments[@]}"
fi
done
ENVS_LIST=`echo "[${environments[@]}]" | sed 's/ /,/g'`
echo ::set-output name=environment_list::$ENVS_LIST
echo "The final list is: ${ENVS_LIST}"
outputs:
environment_list: ${{ steps.set-matrix.outputs.environment_list }}
build-and-push-image:
needs: build-matrix-from-changed-files
runs-on: ubuntu-latest
strategy:
matrix:
environments: ${{ fromJson(needs.build-matrix-from-changed-files.outputs.environment_list) }}
permissions:
contents: read
packages: write
steps:
- name: Docker Checkout
uses: actions/checkout@v3
- name: Log in to the GH Container Registry
id: login
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for ${{ matrix.environments }}
id: meta
uses: docker/[email protected]
with:
flavor: |
latest=true
tags: |
type=sha
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.environments }}
- name: Build and push ${{ matrix.environments }}
id: build
uses: docker/[email protected]
with:
context: ./${{ matrix.environments }}
file: ./${{ matrix.environments }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%SZ')