✨ Add support for nested package paths (#14) #19
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 Package Images | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'libs/**' | |
| workflow_call: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: ${{fromJson(needs.setup.outputs.matrix)}} | |
| needs: [setup] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create temporary Dockerfile | |
| run: | | |
| cat >libs/Dockerfile <<'EOF' | |
| FROM scratch | |
| LABEL org.opencontainers.image.source https://github.com/${{ github.repository }} | |
| ARG PACKAGE | |
| COPY ${PACKAGE}/* /${PACKAGE}/ | |
| EOF | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./libs | |
| file: ./libs/Dockerfile | |
| build-args: PACKAGE=${{ matrix.item }} | |
| push: true | |
| tags: ghcr.io/lf-certification/bashp-${{ matrix.item }}:latest | |
| setup: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: List all directories in libs and create matrix | |
| id: set-matrix | |
| run: | | |
| json=$( | |
| ( | |
| for directory in $(find libs/ -mindepth 1 -type d); do | |
| echo -n '"'"${directory#*/}"'",' | |
| done | |
| echo '""' | |
| ) | sed -E 's/,?""$//' | |
| ) | |
| echo "matrix={\"item\":[$json]}" >> $GITHUB_OUTPUT | |
| shell: bash |