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

github.ref_name is not set to the branch/tag that HEAD points to. #2056

Closed
GROwen opened this issue Oct 20, 2023 · 1 comment · May be fixed by #2061
Closed

github.ref_name is not set to the branch/tag that HEAD points to. #2056

GROwen opened this issue Oct 20, 2023 · 1 comment · May be fixed by #2061
Labels
kind/bug Something isn't working stale

Comments

@GROwen
Copy link

GROwen commented Oct 20, 2023

Bug report info

act version:            0.2.52
GOOS:                   darwin
GOARCH:                 arm64
NumCPU:                 8
Docker host:            unix:///Users/dpc-g/.colima/default/docker.sock
Sockets found:
	$HOME/.colima/docker.sock
Config files:
	/Users/dpc-g/.actrc:
		-P ubuntu-latest=catthehacker/ubuntu:full-latest
		-P ubuntu-latest=catthehacker/ubuntu:full-20.04
		-P ubuntu-18.04=catthehacker/ubuntu:full-18.04
Build info:
	Go version:            go1.21.1
	Module path:           command-line-arguments
	Main version:
	Main path:
	Main checksum:
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-ldflags:             -X main.version=0.2.52
		DefaultGODEBUG:       panicnil=1
		CGO_ENABLED:          1
		CGO_CFLAGS:
		CGO_CPPFLAGS:
		CGO_CXXFLAGS:
		CGO_LDFLAGS:
		GOARCH:               arm64
		GOOS:                 darwin
Docker Engine:
	Engine version:        23.0.6
	Engine runtime:        runc
	Cgroup version:        1
	Cgroup driver:         cgroupfs
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    Alpine Linux v3.18
	OS type:               linux
	OS version:            3.18.4
	OS arch:               aarch64
	OS kernel:             6.1.55-0-virt
	OS CPU:                4
	OS memory:             7938 MB
	Security options:
		name=seccomp,profile=builtin

Command used with act

act schedule -W .github/workflows/context-check.yml --defaultbranch "5.x" --container-architecture linux/amd64 --rm -P ubuntu-latest=catthehacker/ubuntu:act-latest -v

Describe issue

If a Git reference points to multiple branches the last pointer in the series is selected as the value for github.ref_name

i.e.

6cae0a05 (HEAD -> 5.x, origin/5.x, build/git_ref-test) Ref with multiple branch pointers

Expected behaviour (personally)

The values for "ref" and "ref_name" in the GitHub context are set to the branch/tag pointer that HEAD is pointing to i.e.

|   "ref": "refs/heads/5.x",
|   "ref_name": "5.x",

Actual behaviour

See the output posted in the "Relevant log output" section.

Link to GitHub repository

No response

Workflow content

name: Test context values
run-name: GitHub context
on:
  schedule:
    - cron: '23 20 * * 0'
jobs:
  github_context:
    runs-on: ubuntu-latest
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

Relevant log output

[Test context values/github_context] [DEBUG] Working directory '/repo/dir'
| {
|   "event": {
|     "repository": {
|       "default_branch": "5.x"
|     }
|   },
|   "event_path": "/var/run/act/workflow/event.json",
|   "workflow": "Test context values",
|   "run_id": "1",
|   "run_number": "1",
|   "actor": "GROwen",
|   "repository": "dpc-sdp/bay",
|   "event_name": "schedule",
|   "sha": "6cae0a053dc2fe331ddac2b3b0f6b8c8fb6b0269",
|   "ref": "refs/heads/build/git_ref-test",
|   "ref_name": "build/git_ref-test",
|   "ref_type": "branch",
|   "head_ref": "",
|   "base_ref": "",
|   "token": "***",
|   "workspace": "/Users/dpc-g/Projects/bay",
|   "action": "0",
|   "action_path": "",
|   "action_ref": "",
|   "action_repository": "",
|   "job": "github_context",
|   "job_name": "",
|   "repository_owner": "dpc-sdp",
|   "retention_days": "0",
|   "runner_perflog": "/dev/null",
|   "runner_tracking_id": "",
|   "server_url": "https://github.com",
|   "api_url": "https://api.github.com",
|   "graphql_url": "https://api.github.com/graphql"
| }

Additional information

I was trying to solve this and provide a PR but am uncertain of the broader implications of the change that would fix the issue for my scenario.

pkg/common/git/git.go:FindGetRef is responsible for setting the values. I'm assuming the requirement for this and not just the value set for head in pkg/common/git/git.go:FindGitRevision is to lookup any tags that would be related to the revision. Otherwise I'd expect the pointer for HEAD could be used?

It'd be helpful to have this assumption verified by someone more experienced with the project before I dive into a solution.

Expanding the existing tests to check for this scenario seems trivial although I don't think that explicitly checks for what would be output to github.ref_name. Could I have missed that somewhere?

		"current_head_is_master_and_pointer_exists_to_another_branch": {
			Prepare: func(t *testing.T, dir string) {
				require.NoError(t, gitCmd("-C", dir, "checkout", "-b", "mybranch"))
				require.NoError(t, gitCmd("-C", dir, "checkout", "-b", "master"))
			},
			Assert: func(t *testing.T, ref string, err error) {
				require.NoError(t, err)
				require.Equal(t, "refs/heads/master", ref)
			},
		},
@GROwen GROwen added the kind/bug Something isn't working label Oct 20, 2023
GROwen added a commit to GROwen/act that referenced this issue Oct 23, 2023
GROwen added a commit to GROwen/act that referenced this issue Oct 23, 2023
GROwen added a commit to GROwen/act that referenced this issue Oct 23, 2023
GROwen added a commit to GROwen/act that referenced this issue Oct 23, 2023
Copy link
Contributor

Issue is stale and will be closed in 14 days unless there is new activity

@github-actions github-actions bot added the stale label Apr 18, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant