Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revision is wrong (push to open PR) #283

Closed
dimaqq opened this issue Apr 6, 2023 · 7 comments
Closed

revision is wrong (push to open PR) #283

dimaqq opened this issue Apr 6, 2023 · 7 comments

Comments

@dimaqq
Copy link

dimaqq commented Apr 6, 2023

First of all, pardon me if this is a known GitHub Actions issue...

My action code:

            echo "try 2 version:"                                                         
            cat << EOF                                                                    
            ${{ steps.tag.outputs.version }}                                              
            EOF                                                                           
            echo "try 2 tags:"                                                            
            cat << EOF                                                                    
            ${{ steps.tag.outputs.tags }}                                                 
            EOF                                                                           
            echo "try 2 labels:"                                                          
            cat << EOF                                                                    
            ${{ steps.tag.outputs.labels }}                                               
            EOF                                                                           
            echo "try 2 json:"                                                            
            jq . << EOF                                                                   
            ${{ steps.tag.outputs.json }}                                                 
            EOF                                                                           
            echo                                                                          
            echo "github event"                                                           
            jq . $GITHUB_EVENT_PATH     

where tag is docker/medata-action@v4

When I push another commit to a branch with an open PR, I get this output:

try 2 version:
pr-10  # OK!
try 2 tags:
my/image:pr-10  # OK!
try 2 labels:
...
org.opencontainers.image.version=pr-10  # OK!
org.opencontainers.image.created=2023-04-06T02:30:38.641Z
org.opencontainers.image.revision=801fef0830758d8ccefdc8966569227b8bc22853  # ???
org.opencontainers.image.licenses=
try 2 json:
{
  "tags": [
    "my/image:pr-10"
  ],
  "labels": {
...
    "org.opencontainers.image.version": "pr-10",
    "org.opencontainers.image.created": "2023-04-06T02:30:38.641Z",
    "org.opencontainers.image.revision": "801fef0830758d8ccefdc8966569227b8bc22853",  # ???
    "org.opencontainers.image.licenses": ""
  }
}

github event
{
  "action": "synchronize",
  "after": "d7a982e8f5b039c7e4607f87a826f74c53918aec",  # correct!
  "before": "5dc80b95cd193b52101c1eecb83961bf16139966",
  "number": 10,
  "organization": {
...

Where did the 801fef0... hash come from?
It's not in the github event at all.

Meanwhile, my local checkout has my git commit d7a982... on top, in line with github event.
And there's no commit like 801... in my history.

At the same time, if I push a tag, the revision is correct, it's the git hash that the tag points to.

@crazy-max
Copy link
Member

@dimaqq Can you post your workflow please? Even better if you have a link to your repo.

dimaqq added a commit to dimaqq/mre-metadata-action-283 that referenced this issue Apr 17, 2023
@dimaqq
Copy link
Author

dimaqq commented Apr 17, 2023

There you go:

https://github.com/dimaqq/mre-metadata-action-283 repo
dimaqq/mre-metadata-action-283#1 sample PR

Here are all the git commits in the repo, all branches:

> gt
* 3fe33e0 (HEAD -> branch-1, origin/branch-1) a sample change
* 93d6762 (origin/main, origin/HEAD, main) CI debug for https://github.com/docker/metadata-action/issues/283
* c650ac7 Initial commit

Here's the GHA run: https://github.com/dimaqq/mre-metadata-action-283/actions/runs/4718439641/jobs/8368042252

Extract:

2023-04-17T07:09:03.1641463Z ##[group]JSON output
2023-04-17T07:09:03.1641740Z {
2023-04-17T07:09:03.1642057Z   "tags": [
2023-04-17T07:09:03.1642593Z     "quay.io/somerepo/someimage:pr-1"
2023-04-17T07:09:03.1642904Z   ],
2023-04-17T07:09:03.1643199Z   "labels": {
2023-04-17T07:09:03.1643746Z     "org.opencontainers.image.title": "mre-metadata-action-283",
2023-04-17T07:09:03.1644437Z     "org.opencontainers.image.description": "https://github.com/docker/metadata-action/issues/283",
2023-04-17T07:09:03.1645873Z     "org.opencontainers.image.url": "https://github.com/dimaqq/mre-metadata-action-283",
2023-04-17T07:09:03.1646669Z     "org.opencontainers.image.source": "https://github.com/dimaqq/mre-metadata-action-283",
2023-04-17T07:09:03.1647318Z     "org.opencontainers.image.version": "pr-1",
2023-04-17T07:09:03.1647868Z     "org.opencontainers.image.created": "2023-04-17T07:09:03.153Z",
2023-04-17T07:09:03.1648589Z     "org.opencontainers.image.revision": "5d733763d2c575d9ac25b5c0922cbc1ac828df8f",
2023-04-17T07:09:03.1649174Z     "org.opencontainers.image.licenses": "MIT"
2023-04-17T07:09:03.1649496Z   }
2023-04-17T07:09:03.1649777Z }

The image.revision git hash 5d73376 does not exist in my repo.

(my guess is that this is GitHub's magical "this would be the merge commit if the PR was merged" hash)

@crazy-max
Copy link
Member

(my guess is that this is GitHub's magical "this would be the merge commit if the PR was merged" hash)

Yes this looks similar to #206. You need to set the associated head sha on pull request event by setting the DOCKER_METADATA_PR_HEAD_SHA env var:

      - id: tag
        uses: docker/metadata-action@v4
        with:
          images:
            quay.io/somerepo/someimage
        env:
          DOCKER_METADATA_PR_HEAD_SHA: true

@dimaqq
Copy link
Author

dimaqq commented Apr 17, 2023

Yep, looks the same.
I wish that PR_HEAD_SHA was on by default.

@danielorbach
Copy link

Yep, looks the same. I wish that PR_HEAD_SHA was on by default.

Just stumbled upon this PR and thought the same to myself until I saw #239

@iamstarkov
Copy link

omg, this should be default

@crazy-max
Copy link
Member

It's not otherwise we break other workflows. Please see #239

@docker docker locked as spam and limited conversation to collaborators Jul 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants