Skip to content

Commit

Permalink
Adds new github context tags
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrolamas committed Mar 10, 2022
1 parent bf11928 commit 4fe5d87
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,39 @@ Templates can use the full expression syntax of Handlebars, including the built-

### GitHub context

- `{{ github.action }}` - The unique identifier (id) of the action.
- `{{ github.actor }}` - The name of the person or app that initiated the workflow. For example, octocat.
- `{{ github.api_url }}` - Returns the API URL. For example: https://api.github.com.
- `{{ github.action }}` - The name of the action currently running, or the [id](https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsid) of a step. For example, for an action, `__repo-owner_name-of-action-repo`.
- `{{ action_path }}` - The path where an action is located.
- `{{ action_repository }}` - For a step executing an action, this is the owner and repository name of the action. For example, `actions/checkout`.
- `{{ github.actor }}` - The name of the person or app that initiated the workflow. For example, `octocat`.
- `{{ github.api_url }}` - Returns the API URL. For example: `https://api.github.com`.
- `{{ github.base_ref }}` - Only set for forked repositories. The branch of the base repository.
- `{{ github.env }}` - The path on the runner to the file that sets environment variables from workflow commands.
- `{{ github.event_name }}` - The name of the webhook event that triggered the workflow.
- `{{ github.event_path }}` - The path of the file with the complete webhook event payload. For example, /github/workflow/event.json.
- `{{ github.graphql_url }}` - Returns the GraphQL API URL. For example: https://api.github.com/graphql.
- `{{ github.event_path }}` - The path of the file with the complete webhook event payload. For example, `/github/workflow/event.json`.
- `{{ github.graphql_url }}` - Returns the GraphQL API URL. For example: `https://api.github.com/graphql`.
- `{{ github.head_ref }}` - Only set for forked repositories. The branch of the head repository.
- `{{ github.ref }}` - The branch or tag ref that triggered the workflow. For example, refs/heads/feature-branch-1. If neither a branch or tag is available for the event type, the variable will not exist.
- `{{ github.repository }}` - The owner and repository name. For example, octocat/Hello-World.
- `{{ github.repository_name }}` - The repository name. For example, Hello-World.
- `{{ github.job }}` - The [job_id](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_id) of the current job. For example, `greeting_job`.
- `{{ github.path }}` - The path on the runner to the file that sets system PATH variables from workflow commands.
- `{{ github.ref }}` - The branch or tag ref that triggered the workflow. For example, `refs/heads/feature-branch-1`. If neither a branch or tag is available for the event type, the variable will not exist.
- `{{ github.ref_name }}` - The branch or tag name that triggered the workflow run. For example, `feature-branch-1`.
- `{{ github.ref_protected }}` - `true` if branch protections are configured for the ref that triggered the workflow run.
- `{{ github.ref_type }}` - The type of ref that triggered the workflow run. Valid values are `branch` or `tag`.
- `{{ github.repository }}` - The owner and repository name. For example, `octocat/Hello-World`.
- `{{ github.repository_name }}` - The repository name. For example, `Hello-World`.
- `{{ github.repository_owner }}` - The repository owner's name. For example, `octocat`.
- `{{ github.retention_days }}` - The number of days that workflow run logs and artifacts are kept. For example, `90`.
- `{{ github.run_attempt }}` - A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run. For example, `3`.
- `{{ github.run_id }}` - A unique number for each run within a repository. This number does not change if you re-run the workflow run.
- `{{ github.run_number }}` - A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run.
- `{{ github.server_url }}` - Returns the URL of the GitHub server. For example: https://github.com.
- `{{ github.sha }}` - The commit SHA that triggered the workflow. For example, ffac537e6cbbf934b08745a378932722df287a53.
- `{{ github.server_url }}` - Returns the URL of the GitHub server. For example: `https://github.com`.
- `{{ github.sha }}` - The commit SHA that triggered the workflow. For example, `ffac537e6cbbf934b08745a378932722df287a53`.
- `{{ github.workflow }}` - The name of the workflow.
- `{{ github.workspace }}` - The GitHub workspace directory path. The workspace directory is a copy of your repository if your workflow uses the actions/checkout action. If you don't use the actions/checkout action, the directory will be empty. For example, /home/runner/work/my-repo-name/my-repo-name.
- `{{ github.workspace }}` - The GitHub workspace directory path. The workspace directory is a copy of your repository if your workflow uses the actions/checkout action. If you don't use the actions/checkout action, the directory will be empty. For example, `/home/runner/work/my-repo-name/my-repo-name`.
- `{{ github.runner_arch }}` - The architecture of the runner executing the job. Possible values are `X86`, `X64`, `ARM`, or `ARM64`.
- `{{ github.runner_name }}` - The name of the runner executing the job. For example, `Hosted Agent`.
- `{{ github.runner_os }}` - The operating system of the runner executing the job. Possible values are `Linux`, `Windows`, or `macOS`.
- `{{ github.runner_temp }}` - The path to a temporary directory on the runner. For example, `D:\a\_temp`.
- `{{ github.runner_tool_cache }}` - The path to the directory containing preinstalled tools for GitHub-hosted runners. For example, `C:\hostedtoolcache\windows`.

### Misc

Expand Down
16 changes: 16 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,38 @@ type BaseData = {
env: Record<string, string | undefined>;
github: {
action?: string;
action_path?: string;
action_repository?: string;
actor?: string;
api_url?: string;
base_ref?: string;
env?: string;
event_name?: string;
event_path?: string;
graphql_url?: string;
head_ref?: string;
job?: string;
path?: string;
ref?: string;
ref_name?: string;
ref_protected?: string;
ref_type?: string;
repository?: string;
repository_name?: string;
repository_owner?: string;
retention_days?: string;
run_attempt?: string;
run_id?: string;
run_number?: string;
server_url?: string;
sha?: string;
workflow?: string;
workspace?: string;
runner_arch?: string;
runner_name?: string;
runner_os?: string;
runner_temp?: string;
runner_tool_cache?: string;
};
};

Expand Down
16 changes: 16 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@ export const buildBaseData = (): BaseData => ({
env: { ...process.env },
github: {
action: process.env['GITHUB_ACTION'],
action_path: process.env['GITHUB_ACTION_PATH'],
action_repository: process.env['GITHUB_ACTION_REPOSITORY'],
actor: process.env['GITHUB_ACTOR'],
api_url: process.env['GITHUB_API_URL'],
base_ref: process.env['GITHUB_BASE_REF'],
env: process.env['GITHUB_ENV'],
event_name: process.env['GITHUB_EVENT_NAME'],
event_path: process.env['GITHUB_EVENT_PATH'],
graphql_url: process.env['GITHUB_GRAPHQL_URL'],
head_ref: process.env['GITHUB_HEAD_REF'],
job: process.env['GITHUB_JOB'],
path: process.env['GITHUB_PATH'],
ref: process.env['GITHUB_REF'],
ref_name: process.env['GITHUB_REF_NAME'],
ref_protected: process.env['GITHUB_REF_PROTECTED'],
ref_type: process.env['GITHUB_REF_TYPE'],
repository: process.env['GITHUB_REPOSITORY'],
repository_name: process.env['GITHUB_REPOSITORY']?.replace(/.*\//, ''),
repository_owner: process.env['GITHUB_REPOSITORY_OWNER'],
retention_days: process.env['GITHUB_RETENTION_DAYS'],
run_attempt: process.env['GITHUB_RUN_ATTEMPT'],
run_id: process.env['GITHUB_RUN_ID'],
run_number: process.env['GITHUB_RUN_NUMBER'],
server_url: process.env['GITHUB_SERVER_URL'],
sha: process.env['GITHUB_SHA'],
workflow: process.env['GITHUB_WORKFLOW'],
workspace: process.env['GITHUB_WORKSPACE'],
runner_arch: process.env['RUNNER_ARCH'],
runner_name: process.env['RUNNER_NAME'],
runner_os: process.env['RUNNER_OS'],
runner_temp: process.env['RUNNER_TEMP'],
runner_tool_cache: process.env['RUNNER_TOOL_CACHE'],
},
});

Expand Down

0 comments on commit 4fe5d87

Please sign in to comment.