New github action for week3 and week4 #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image | |
| on: | |
| push: | |
| paths: | |
| - 'Learn/week3/**' | |
| - 'Learn/week4/**' | |
| - 'Learn/week5/**' | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| directories: ${{ steps.filter.outputs.changes }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check changed directories | |
| id: filter | |
| uses: dorny/paths-filter@v3 | |
| with: | |
| filters: | | |
| week3: 'Learn/week3/**' | |
| week4: 'Learn/week4/**' | |
| week5: 'Learn/week5/**' | |
| docker-build-push: | |
| needs: prepare | |
| if: needs.prepare.outputs.directories != '[]' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| directory: ${{ fromJson(needs.prepare.outputs.directories) }} | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Lowercase repository owner | |
| id: prep | |
| run: | | |
| echo "OWNER_LOWERCASE=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_OUTPUT | |
| echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| - name: Build and Push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./Learn/${{ matrix.directory }} | |
| file: ./Learn/${{ matrix.directory }}/Dockerfile | |
| push: true | |
| tags: | | |
| ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-${{ matrix.directory }}:${{ steps.prep.outputs.IMAGE_TAG }} | |
| ghcr.io/${{ steps.prep.outputs.OWNER_LOWERCASE }}/playground-${{ matrix.directory }}:latest |