diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml new file mode 100644 index 0000000..2442845 --- /dev/null +++ b/.github/workflows/container-image.yml @@ -0,0 +1,65 @@ +name: Docker Image CI + +on: + workflow_dispatch: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + TAG: "3.1" + +jobs: + + main-root: + outputs: + is-main: ${{ steps.is-main-root.outputs.test }} + runs-on: ubuntu-latest + steps: + - name: Echo a message + if: github.ref == 'refs/heads/main' && github.repository == 'commonhaus/pandoc-pdf' + id: is-main-root + run: echo "test=true" >> "$GITHUB_OUTPUT" + + build: + needs: main-root + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ github.repository }} + tags: | + type=raw,enable=true,priority=200,prefix=,suffix=,value=${{ env.TAG }} + + - name: Log in to the Container registry + if: ${{needs.main-root.outputs.is-main}} + uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6.9.0 + with: + context: . + push: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + + - name: Publish OCI image to GCR + if: ${{needs.main-root.outputs.is-main}} + id: publish-oci + run: | + image="${IMAGE_NAME}:${TAG}" + docker tag "${image}" "ghcr.io/${image}" + docker push "ghcr.io/${image}" \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index ffceb74..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Docker Image CI - -on: - workflow_dispatch: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - THIS: "ebullient/pandoc-emoji" - TAG: "3.1" - -jobs: - - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ github.repository }} - tags: | - type=schedule,pattern={{date 'YYYYMMDD'}} - type=raw,value=latest,enable={{is_default_branch}} - type=raw,enable=true,priority=200,prefix=,suffix=,value=${{ env.TAG }} - - - name: Login to Docker Hub - if: github.ref == 'refs/heads/main' - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push Docker image - if: github.repository == ${{ env.THIS }} && github.ref == 'refs/heads/main' - uses: docker/build-push-action@v3 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file