diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2dfd3558..8600f372 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,8 +5,7 @@ name: build on: push: - branches: - - develop + branches: [main, develop, 'GEN*', 'gen*'] pull_request: @@ -14,6 +13,10 @@ on: types: - created +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: test: @@ -77,3 +80,51 @@ jobs: run: python -m build - name: Publish to pypi uses: pypa/gh-action-pypi-publish@release/v1 + + + build-container: + needs: [test, lint] + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Format tags as registry refs + id: registry_refs + env: + TAGS: ${{ steps.meta.outputs.json }} + run: | + echo tags=$(echo $TAGS | jq '.tags[] | "type=registry,ref=" + . + "_cache"| @text') >> $GITHUB_OUTPUT + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5 + if: github.event_name != 'pull_request' + with: + context: . + push: true + provenance: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: ${{ steps.registry_refs.outputs.tags }},mode=max + cache-to: ${{ steps.registry_refs.outputs.tags }},mode=max