docker / metadata-action

GitHub Action to extract metadata (tags, labels) from Git reference and GitHub events for Docker
https://github.com/marketplace/actions/docker-metadata-action
Apache License 2.0
892 stars 115 forks source link

steps.meta.outputs.version seems to always be 'head' #436

Closed amir20 closed 1 month ago

amir20 commented 2 months ago

Contributing guidelines

I've found a bug, and:

Description

I have the following workflow:

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
name: Push container
jobs:
  buildx:
    name: Push branches and PRs
    runs-on: ubuntu-latest
    if: ${{ !github.event.repository.fork && !github.event.pull_request.head.repo.fork && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == 'amir20/dozzle') }}
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@4fd812986e6c8c2a69e18311145f9371337f27d4 # v3.4.0
      - name: Login to DockerHub
        uses: docker/login-action@v3.2.0
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Checkout
        uses: actions/checkout@v4
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: amir20/dozzle
      - name: Writing certs to file
        run: |
          echo "${{ secrets.TTL_KEY }}" > shared_key.pem
          echo "${{ secrets.TTL_CERT }}" > shared_cert.pem
      - name: Build and push
        uses: docker/build-push-action@v6.3.0
        with:
          context: .
          push: true
          platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
          tags: ${{ steps.meta.outputs.tags }}
          build-args: TAG=${{ steps.meta.outputs.version }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

I didn't use to have actions/checkout@v4 and everything seemed to work. But recently I added actions/checkout@v4 because I need to generate certs before building.

Now that I have added checkout, build-args: TAG=${{ steps.meta.outputs.version }} seems to be broken and always providing head as the result.

I created a test PR and when pulling it is still head

Expected behaviour

For steps.meta.outputs.version to point to pr-xxx. However, the container is correctly tagged so seems like steps.meta.outputs.tags is working.

Actual behaviour

steps.meta.outputs.version is head.

Repository URL

https://github.com/amir20/dozzle

Workflow run URL

https://github.com/amir20/dozzle/actions/runs/9867277820/job/27247401374?pr=3084

YAML workflow

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
name: Push container
jobs:
  buildx:
    name: Push branches and PRs
    runs-on: ubuntu-latest
    if: ${{ !github.event.repository.fork && !github.event.pull_request.head.repo.fork && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == 'amir20/dozzle') }}
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@4fd812986e6c8c2a69e18311145f9371337f27d4 # v3.4.0
      - name: Login to DockerHub
        uses: docker/login-action@v3.2.0
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - name: Checkout
        uses: actions/checkout@v4
      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: amir20/dozzle
      - name: Writing certs to file
        run: |
          echo "${{ secrets.TTL_KEY }}" > shared_key.pem
          echo "${{ secrets.TTL_CERT }}" > shared_cert.pem
      - name: Build and push
        uses: docker/build-push-action@v6.3.0
        with:
          context: .
          push: true
          platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
          tags: ${{ steps.meta.outputs.tags }}
          build-args: TAG=${{ steps.meta.outputs.version }}
          labels: ${{ steps.meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

Workflow logs

No response

BuildKit logs

No response

Additional info

This used to work fine. But it broke recently and I can't figure out if it is my doing or something else.

amir20 commented 1 month ago

I did echo "Version: ${{ steps.meta.outputs.version }}" and it print the right version. It might be something on my side. I am going to investigate a little more and close if I feel it is something on my side.

amir20 commented 1 month ago

Something is happening on my side. Closing. I think my -X path.subpackage.var is not working.