@@ -11,114 +11,36 @@ jobs:
1111 prepare :
1212 runs-on : ubuntu-latest
1313 outputs :
14- week3 : ${{ steps.filter.outputs.week3 }}
15- week4 : ${{ steps.filter.outputs.week4 }}
16- week5 : ${{ steps.filter.outputs.week5 }}
14+ directories : ${{ steps.filter.outputs.changes }}
1715 steps :
1816 - name : Checkout code
1917 uses : actions/checkout@v4
2018 with :
21- fetch-depth : 0 # Important: fetch full history for proper diff
19+ fetch-depth : 0
2220
2321 - name : Check changed directories
2422 id : filter
2523 uses : dorny/paths-filter@v3
2624 with :
25+ # This ensures we only detect changes in the current push,
26+ # rather than comparing the whole branch to main.
27+ base : ${{ github.event.before }}
2728 filters : |
28- week3:
29- - 'Learn/week3/**'
30- week4:
31- - 'Learn/week4/**'
32- week5:
33- - 'Learn/week5/**'
34-
35- - name : Debug outputs
36- run : |
37- echo "week3: ${{ steps.filter.outputs.week3 }}"
38- echo "week4: ${{ steps.filter.outputs.week4 }}"
39- echo "week5: ${{ steps.filter.outputs.week5 }}"
40-
41- build-week3 :
42- needs : prepare
43- if : needs.prepare.outputs.week3 == 'true'
44- runs-on : ubuntu-latest
45- permissions :
46- contents : read
47- packages : write
48- steps :
49- - name : Checkout code
50- uses : actions/checkout@v4
51-
52- - name : Set up Docker Buildx
53- uses : docker/setup-buildx-action@v3
54-
55- - name : Login to GitHub Container Registry
56- uses : docker/login-action@v3
57- with :
58- registry : ghcr.io
59- username : ${{ github.actor }}
60- password : ${{ secrets.GITHUB_TOKEN }}
61-
62- - name : Lowercase repository owner
63- id : prep
64- run : |
65- echo "OWNER_LOWERCASE=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT
66- echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
67-
68- - name : Build and Push Week 3
69- uses : docker/build-push-action@v6
70- with :
71- context : ./Learn/week3
72- file : ./Learn/week3/Dockerfile
73- push : true
74- tags : |
75- ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-week3:${{ steps.prep.outputs.IMAGE_TAG }}
76- ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-week3:latest
29+ week3: 'Learn/week3/**'
30+ week4: 'Learn/week4/**'
31+ week5: 'Learn/week5/**'
7732
78- build-week4 :
33+ docker- build-push :
7934 needs : prepare
80- if : needs.prepare.outputs.week4 == 'true '
35+ if : needs.prepare.outputs.directories != '[] '
8136 runs-on : ubuntu-latest
37+ strategy :
38+ matrix :
39+ directory : ${{ fromJson(needs.prepare.outputs.directories) }}
8240 permissions :
8341 contents : read
8442 packages : write
85- steps :
86- - name : Checkout code
87- uses : actions/checkout@v4
88-
89- - name : Set up Docker Buildx
90- uses : docker/setup-buildx-action@v3
91-
92- - name : Login to GitHub Container Registry
93- uses : docker/login-action@v3
94- with :
95- registry : ghcr.io
96- username : ${{ github.actor }}
97- password : ${{ secrets.GITHUB_TOKEN }}
98-
99- - name : Lowercase repository owner
100- id : prep
101- run : |
102- echo "OWNER_LOWERCASE=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT
103- echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
10443
105- - name : Build and Push Week 4
106- uses : docker/build-push-action@v6
107- with :
108- context : ./Learn/week4
109- file : ./Learn/week4/Dockerfile
110- push : true
111- tags : |
112- ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-week4:${{ steps.prep.outputs.IMAGE_TAG }}
113- ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-week4:latest
114-
115- build-week5 :
116- needs : prepare
117- if : needs.prepare.outputs.week5 == 'true'
118- runs-on : ubuntu-latest
119- permissions :
120- contents : read
121- packages : write
12244 steps :
12345 - name : Checkout code
12446 uses : actions/checkout@v4
@@ -139,12 +61,12 @@ jobs:
13961 echo "OWNER_LOWERCASE=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT
14062 echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
14163
142- - name : Build and Push Week 5
64+ - name : Build and Push
14365 uses : docker/build-push-action@v6
14466 with :
145- context : ./Learn/week5
146- file : ./Learn/week5 /Dockerfile
67+ context : ./Learn/${{ matrix.directory }}
68+ file : ./Learn/${{ matrix.directory }} /Dockerfile
14769 push : true
14870 tags : |
149- ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-week5 :${{ steps.prep.outputs.IMAGE_TAG }}
150- ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-week5 :latest
71+ ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-${{ matrix.directory }} :${{ steps.prep.outputs.IMAGE_TAG }}
72+ ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-${{ matrix.directory }} :latest
0 commit comments