Skip to content

Commit 2fac9b9

Browse files
committed
Update docker-publish.yml
1 parent bef8e73 commit 2fac9b9

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

.github/workflows/docker-publish.yml

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,66 @@ env:
1111
REGISTRY: ghcr.io
1212

1313
jobs:
14-
setup:
14+
prepare:
1515
runs-on: ubuntu-latest
1616
outputs:
17-
matrix: ${{ steps.set-matrix.outputs.matrix }}
18-
filters: ${{ steps.set-matrix.outputs.filters }}
17+
matrix: ${{ steps.generate-matrix.outputs.matrix }}
1918
steps:
2019
- uses: actions/checkout@v4
21-
- id: set-matrix
20+
21+
- id: set-filters
2222
run: |
2323
python3 -c "
24-
import yaml, json, os
24+
import yaml, os
2525
with open('config.yml', 'r') as f:
2626
config = yaml.safe_load(f)
2727
images = config.get('images', [])
28-
filters = {}
29-
for img in images:
30-
path = img['context']
31-
if path.startswith('./'): path = path[2:]
32-
filters[img['name']] = [f'{path}/**']
28+
filters = {img['name']: [f\"{img['context'].lstrip('./')}/**\"] for img in images}
3329
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
34-
f.write(f'matrix={json.dumps(images)}\n')
3530
f.write('filters<<EOF\n')
3631
f.write(yaml.dump(filters))
3732
f.write('EOF\n')
3833
"
3934
40-
filter-changes:
41-
needs: setup
42-
runs-on: ubuntu-latest
43-
outputs:
44-
changes: ${{ steps.filter.outputs.changes }}
45-
steps:
46-
- uses: actions/checkout@v4
4735
- uses: dorny/paths-filter@v3
4836
id: filter
4937
with:
50-
filters: ${{ needs.setup.outputs.filters }}
38+
filters: ${{ steps.set-filters.outputs.filters }}
39+
40+
- id: generate-matrix
41+
run: |
42+
python3 -c "
43+
import yaml, json, os
44+
with open('config.yml', 'r') as f:
45+
config = yaml.safe_load(f)
46+
images = config.get('images', [])
47+
48+
changes = json.loads(os.environ.get('CHANGES', '[]'))
49+
event = os.environ.get('EVENT_NAME')
50+
ref_type = os.environ.get('REF_TYPE')
51+
is_build_all = event in ['schedule', 'workflow_dispatch'] or ref_type == 'tag'
52+
53+
if is_build_all:
54+
matrix = images
55+
else:
56+
matrix = [img for img in images if img['name'] in changes]
57+
58+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
59+
f.write(f'matrix={json.dumps(matrix)}\n')
60+
"
61+
env:
62+
CHANGES: ${{ steps.filter.outputs.changes }}
63+
EVENT_NAME: ${{ github.event_name }}
64+
REF_TYPE: ${{ github.ref_type }}
5165

5266
build:
5367
name: Build ${{ matrix.name }} Dockerfile and Push
54-
needs: [setup, filter-changes]
55-
if: |
56-
github.event_name == 'schedule' ||
57-
github.event_name == 'workflow_dispatch' ||
58-
github.ref_type == 'tag' ||
59-
contains(fromJSON(needs.filter-changes.outputs.changes), matrix.name)
68+
needs: prepare
69+
if: needs.prepare.outputs.matrix != '[]'
6070
strategy:
6171
fail-fast: false
6272
matrix:
63-
include: ${{ fromJSON(needs.setup.outputs.matrix) }}
73+
include: ${{ fromJSON(needs.prepare.outputs.matrix) }}
6474
runs-on: ubuntu-latest
6575
permissions:
6676
contents: read

0 commit comments

Comments
 (0)