Build and Push Packages #41
Workflow file for this run
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 Packages | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'libs/**' | |
| workflow_call: | |
| jobs: | |
| test: | |
| uses: ./.github/workflows/test.yaml | |
| package: | |
| runs-on: ubuntu-latest | |
| needs: [test] | |
| if: always() && needs.test.outputs.packages != '{"package":[]}' | |
| strategy: | |
| matrix: ${{ fromJson(needs.test.outputs.packages) }} | |
| fail-fast: false | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Check if all tests passed for this package | |
| id: check | |
| run: | | |
| if ! jq -e '.${{ matrix.package }} == "false"' <<<'${{ needs.test.outputs.results }}'; then | |
| echo "✅ All tests passed for package ${{ matrix.package }}" | |
| echo "package=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "❌ Some tests failed for package ${{ matrix.package }}" | |
| echo "package=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set up Docker | |
| if: steps.check.outputs.package == 'true' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| if: steps.check.outputs.package == 'true' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create temporary Dockerfile | |
| if: steps.check.outputs.package == 'true' | |
| run: | | |
| cat >libs/Dockerfile <<'EOF' | |
| FROM scratch | |
| LABEL org.opencontainers.image.source https://github.com/${{ github.repository }} | |
| ARG PACKAGE | |
| ADD ${PACKAGE} /${PACKAGE}/ | |
| EOF | |
| - name: Build and push Docker image | |
| if: steps.check.outputs.package == 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./libs | |
| file: ./libs/Dockerfile | |
| build-args: PACKAGE=${{ matrix.package }} | |
| push: true | |
| tags: ghcr.io/lf-certification/bashp-${{ matrix.package }}:latest |