[GH-ISSUE #2627] event file overrides github.ref but not github.ref_name #1193

Open
opened 2026-03-01 21:49:34 +03:00 by kerem · 1 comment
Owner

Originally created by @Dr-Electron on GitHub (Jan 21, 2025).
Original GitHub issue: https://github.com/nektos/act/issues/2627

Bug report info

act version:            0.2.71
GOOS:                   darwin
GOARCH:                 amd64
NumCPU:                 16
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	/var/run/docker.sock
Config files:           
	/Users/dr-electron/.actrc:
		-P ubuntu-latest=catthehacker/ubuntu:act-latest
		-P ubuntu-22.04=catthehacker/ubuntu:act-22.04
		-P ubuntu-20.04=catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.23.4
	Module path:           command-line-arguments
	Main version:          
	Main path:             
	Main checksum:         
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-ldflags:             -X main.version=0.2.71
		CGO_ENABLED:          1
		CGO_CFLAGS:           
		CGO_CPPFLAGS:         
		CGO_CXXFLAGS:         
		CGO_LDFLAGS:          
		GOARCH:               amd64
		GOOS:                 darwin
		GOAMD64:              v1
Docker Engine:
	Engine version:        27.4.1
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         cgroupfs
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    OrbStack
	OS type:               linux
	OS version:            
	OS arch:               x86_64
	OS kernel:             6.12.10-orbstack-00297-gf8f6e015b993
	OS CPU:                16
	OS memory:             16049 MB
	Security options:
		name=seccomp,profile=builtin
		name=cgroupns

Command used with act

act -W ./.github/workflows/upload-docs-to-aws.yml -P ubuntu-latest=catthehacker/ubuntu:full-20.04 -e event.json

Describe issue

I have an event.json file with the following content:

{
    "ref": "develop",
    "ref_name": "develop"
}

If I look at the GitHub context, github.ref is set to develop, but github.ref_name is not. Seems inconsistent to me.

No response

Workflow content

on:
  push:
    branches:
      - develop

jobs:
  build-and-upload-docs:
    runs-on: ubuntu-latest

    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

Relevant log output

| {
|   "event": {
|     "ref": "develop",
|     "ref_name": "develop"
|   },
|   "event_path": "/var/run/act/workflow/event.json",
|   "workflow": "Upload Docs to S3",
|   "run_attempt": "1",
|   "run_id": "1",
|   "run_number": "1",
|   "actor": "nektos/act",
|   "repository": "",
|   "event_name": "push",
|   "sha": "ca9b545cb54f9f2b9905cab56102936d81f79fe6",
|   "ref": "develop",
|   "ref_name": "",
|   "ref_type": "",
|   "head_ref": "",
|   "base_ref": "",
|   "token": "",
|   "workspace": "",
|   "action": "0",
|   "action_path": "",
|   "action_ref": "",
|   "action_repository": "",
|   "job": "build-and-upload-docs",
|   "job_name": "",
|   "repository_owner": "",
|   "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

No response

Originally created by @Dr-Electron on GitHub (Jan 21, 2025). Original GitHub issue: https://github.com/nektos/act/issues/2627 ### Bug report info ```plain text act version: 0.2.71 GOOS: darwin GOARCH: amd64 NumCPU: 16 Docker host: DOCKER_HOST environment variable is not set Sockets found: /var/run/docker.sock Config files: /Users/dr-electron/.actrc: -P ubuntu-latest=catthehacker/ubuntu:act-latest -P ubuntu-22.04=catthehacker/ubuntu:act-22.04 -P ubuntu-20.04=catthehacker/ubuntu:act-20.04 -P ubuntu-18.04=catthehacker/ubuntu:act-18.04 Build info: Go version: go1.23.4 Module path: command-line-arguments Main version: Main path: Main checksum: Build settings: -buildmode: exe -compiler: gc -ldflags: -X main.version=0.2.71 CGO_ENABLED: 1 CGO_CFLAGS: CGO_CPPFLAGS: CGO_CXXFLAGS: CGO_LDFLAGS: GOARCH: amd64 GOOS: darwin GOAMD64: v1 Docker Engine: Engine version: 27.4.1 Engine runtime: runc Cgroup version: 2 Cgroup driver: cgroupfs Storage driver: overlay2 Registry URI: https://index.docker.io/v1/ OS: OrbStack OS type: linux OS version: OS arch: x86_64 OS kernel: 6.12.10-orbstack-00297-gf8f6e015b993 OS CPU: 16 OS memory: 16049 MB Security options: name=seccomp,profile=builtin name=cgroupns ``` ### Command used with act ```sh act -W ./.github/workflows/upload-docs-to-aws.yml -P ubuntu-latest=catthehacker/ubuntu:full-20.04 -e event.json ``` ### Describe issue I have an event.json file with the following content: ```json { "ref": "develop", "ref_name": "develop" } ``` If I look at the GitHub context, `github.ref` is set to `develop`, but `github.ref_name` is not. Seems inconsistent to me. ### Link to GitHub repository _No response_ ### Workflow content ```yml on: push: branches: - develop jobs: build-and-upload-docs: runs-on: ubuntu-latest steps: - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" ``` ### Relevant log output ```sh | { | "event": { | "ref": "develop", | "ref_name": "develop" | }, | "event_path": "/var/run/act/workflow/event.json", | "workflow": "Upload Docs to S3", | "run_attempt": "1", | "run_id": "1", | "run_number": "1", | "actor": "nektos/act", | "repository": "", | "event_name": "push", | "sha": "ca9b545cb54f9f2b9905cab56102936d81f79fe6", | "ref": "develop", | "ref_name": "", | "ref_type": "", | "head_ref": "", | "base_ref": "", | "token": "", | "workspace": "", | "action": "0", | "action_path": "", | "action_ref": "", | "action_repository": "", | "job": "build-and-upload-docs", | "job_name": "", | "repository_owner": "", | "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 _No response_
Author
Owner

@LauH1987 commented on GitHub (Jul 2, 2025):

I'm still new to act and GitHub Actions, but something I learned is that the event json in general (partially) follows the schema of the Webhook payload in the GitHub API. In your case you're simulating a push event, so the fields that are normally available to you are documented here. act doesn't require you to fill out all the required fields, and it also supports adding extra fields like the github.event.act field in the Skipping Jobs example in the docs.

However setting ref_name in the event is not supported. You can see how act sets the ref_name from the ref here.

If you manually want to set the ref_name, you can do so by adding it to the environment. The default available environment variables are documented in the GitHub Action Docs here.

As you can see you need to set the GITHUB_REF_NAME environment variable. So to make your example work, first remove the ref_name from the event:

event.json

{
    "ref": "develop"
}

Next you add GITHUB_REF_NAME to the environment. This can be done in multiple ways:

The first way is to use the --env argument like --env GITHUB_REF_NAME=develop when running act, or to put it in the .actrc file.

The second way is to add it to an envrionment file. By default act will look for the filename .env, but if you want a different file you can use the --env-file argument.

I ran your code with the following .env file:

GITHUB_REF_NAME=develop

And it gave me the output you're looking for (I have shortened the output below):

| {
|   "event": {
|     "ref": "develop"
|   },
|   "event_name": "push",
|   "ref": "develop",
|   "ref_name": "develop",
|   "job": "build-and-upload-docs"
| }
<!-- gh-comment-id:3027021250 --> @LauH1987 commented on GitHub (Jul 2, 2025): I'm still new to `act` and GitHub Actions, but something I learned is that the event json in general (partially) follows the schema of the Webhook payload in the GitHub API. In your case you're simulating a `push` event, so the fields that are normally available to you are documented [here](https://docs.github.com/en/webhooks/webhook-events-and-payloads#push). `act` doesn't require you to fill out all the required fields, and it also supports adding extra fields like the `github.event.act` field in the [Skipping Jobs example](https://nektosact.com/usage/index.html#skipping-jobs) in the docs. However setting `ref_name` in the event is not supported. You can see how `act` sets the `ref_name` from the `ref` [here](https://github.com/nektos/act/blob/v0.2.79/pkg/model/github_context.go#L183-L205). If you manually want to set the `ref_name`, you can do so by adding it to the environment. The default available environment variables are documented in the GitHub Action Docs [here](https://docs.github.com/en/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#default-environment-variables). As you can see you need to set the `GITHUB_REF_NAME` environment variable. So to make your example work, first remove the `ref_name` from the event: `event.json` ```json { "ref": "develop" } ``` Next you add `GITHUB_REF_NAME` to the environment. This can be done in multiple ways: The first way is to use the `--env` argument like `--env GITHUB_REF_NAME=develop` when running `act`, or to put it in the `.actrc` file. The second way is to add it to an envrionment file. By default `act` will look for the filename `.env`, but if you want a different file you can use the `--env-file` argument. I ran your code with the following `.env` file: ```properties GITHUB_REF_NAME=develop ``` And it gave me the output you're looking for (I have shortened the output below): ``` | { | "event": { | "ref": "develop" | }, | "event_name": "push", | "ref": "develop", | "ref_name": "develop", | "job": "build-and-upload-docs" | } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#1193
No description provided.