|
6 | 6 | - 'Learn/week3/**' |
7 | 7 | - 'Learn/week4/**' |
8 | 8 | - 'Learn/week5/**' |
9 | | - workflow_dispatch: |
10 | | - inputs: |
11 | | - directory: |
12 | | - description: 'Select the directory (week) to build and push' |
13 | | - required: true |
14 | | - type: choice |
15 | | - options: |
16 | | - - week3 |
17 | | - - week4 |
18 | | - - week5 |
19 | | - - all |
20 | | - image_tag: |
21 | | - description: 'Tag for the Docker image (e.g., v1.0, latest)' |
22 | | - required: true |
23 | | - default: 'latest' |
24 | | - type: string |
25 | 9 |
|
26 | 10 | jobs: |
27 | 11 | prepare: |
28 | 12 | runs-on: ubuntu-latest |
29 | 13 | outputs: |
30 | | - directories: ${{ steps.set-dirs.outputs.directories }} |
| 14 | + directories: ${{ steps.filter.outputs.changes }} |
31 | 15 | steps: |
32 | 16 | - name: Checkout code |
33 | 17 | uses: actions/checkout@v4 |
34 | 18 |
|
35 | 19 | - name: Check changed directories |
36 | 20 | id: filter |
37 | | - if: github.event_name == 'push' |
38 | 21 | uses: dorny/paths-filter@v3 |
39 | 22 | with: |
40 | 23 | filters: | |
41 | 24 | week3: 'Learn/week3/**' |
42 | 25 | week4: 'Learn/week4/**' |
43 | 26 | week5: 'Learn/week5/**' |
44 | 27 |
|
45 | | - - id: set-dirs |
46 | | - run: | |
47 | | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
48 | | - if [ "${{ github.event.inputs.directory }}" = "all" ]; then |
49 | | - echo 'directories=["week3", "week4", "week5"]' >> $GITHUB_OUTPUT |
50 | | - else |
51 | | - echo 'directories=["${{ github.event.inputs.directory }}"]' >> $GITHUB_OUTPUT |
52 | | - fi |
53 | | - else |
54 | | - # For push events, build array based on filter results |
55 | | - DIRS=() |
56 | | - if [ "${{ steps.filter.outputs.week3 }}" = "true" ]; then DIRS+=("\"week3\""); fi |
57 | | - if [ "${{ steps.filter.outputs.week4 }}" = "true" ]; then DIRS+=("\"week4\""); fi |
58 | | - if [ "${{ steps.filter.outputs.week5 }}" = "true" ]; then DIRS+=("\"week5\""); fi |
59 | | - |
60 | | - # Join array with commas and wrap in brackets |
61 | | - JSON_DIRS=$(IFS=,; echo "[${DIRS[*]}]") |
62 | | - echo "directories=$JSON_DIRS" >> $GITHUB_OUTPUT |
63 | | - fi |
64 | | -
|
65 | 28 | docker-build-push: |
66 | 29 | needs: prepare |
| 30 | + if: needs.prepare.outputs.directories != '[]' |
67 | 31 | runs-on: ubuntu-latest |
68 | 32 | strategy: |
69 | 33 | matrix: |
|
90 | 54 | id: prep |
91 | 55 | run: | |
92 | 56 | echo "OWNER_LOWERCASE=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT |
93 | | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
94 | | - echo "IMAGE_TAG=${{ github.event.inputs.image_tag }}" >> $GITHUB_OUTPUT |
95 | | - else |
96 | | - echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT |
97 | | - fi |
| 57 | + echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT |
98 | 58 |
|
99 | 59 | - name: Build and Push |
100 | 60 | uses: docker/build-push-action@v6 |
|
0 commit comments