name: Publish Docker Image on: push: branches: - main - '*-dev' env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build-and-push-image: runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v3 - name: Extract Docker metadata id: meta uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value={{branch}}-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.ref != format('refs/heads/{0}', 'main') }} type=raw,value={{date 'YYYYMMDD'}}-{{sha}},enable={{is_default_branch}} type=raw,value={{date 'YYYYMMDD'}},enable={{is_default_branch}} type=raw,value=latest,enable={{is_default_branch}} - name: Log into registry ${{ env.REGISTRY }} uses: docker/login-action@v2.1.0 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.CI_PAT_WRITE_PACKAGE }} - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} push: true