Skip to content

Commit 94ac734

Browse files
salmanmkcjc-clark
andauthored
docs: add job workflow identity context properties (ADR 10024) also bumping checkout to v6 (#60709)
Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
1 parent 2e4af8e commit 94ac734

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

content/actions/reference/workflows-and-actions/contexts.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,15 +378,23 @@ The `job` context contains information about the currently running job.
378378
| `job.services.<service_id>.network` | `string` | The ID of the service container network. The runner creates the network used by all containers in a job. |
379379
| `job.services.<service_id>.ports` | `object` | The exposed ports of the service container. |
380380
| `job.status` | `string` | The current status of the job. Possible values are `success`, `failure`, or `cancelled`. |
381+
| `job.workflow_ref` | `string` | The full ref of the workflow file that defines the current job. For example, `octo-org/octo-repo/.github/workflows/deploy.yml@refs/heads/main`. For jobs defined directly in a workflow file, this is the same as `github.workflow_ref`. For jobs defined in a [AUTOTITLE](/actions/using-workflows/reusing-workflows), this refers to the reusable workflow file. (not available on {% data variables.product.prodname_ghe_server %}) |
382+
| `job.workflow_sha` | `string` | The commit SHA of the workflow file that defines the current job. (not available on {% data variables.product.prodname_ghe_server %}) |
383+
| `job.workflow_repository` | `string` | The `owner/repo` of the repository containing the workflow file that defines the current job. For example, `octo-org/octo-repo`. (not available on {% data variables.product.prodname_ghe_server %}) |
384+
| `job.workflow_file_path` | `string` | The file path of the workflow file that defines the current job, relative to the repository root. For example, `.github/workflows/deploy.yml`. (not available on {% data variables.product.prodname_ghe_server %}) |
381385

382386
### Example contents of the `job` context
383387

384-
This example `job` context uses a PostgreSQL service container with mapped ports. If there are no containers or service containers used in a job, the `job` context only contains the `status` and `check_run_id` properties.
388+
This example `job` context uses a PostgreSQL service container with mapped ports. If there are no containers or service containers used in a job, the `job` context only contains `status`. The `check_run_id` and workflow identity properties (`workflow_ref`, `workflow_sha`, `workflow_repository`, `workflow_file_path`) are not available on {% data variables.product.prodname_ghe_server %}.
385389

386390
```json
387391
{
388392
"status": "success",
389-
{% ifversion fpt or ghec %}"check_run_id": 51725241954,{% endif %}
393+
"check_run_id": 51725241954,
394+
"workflow_ref": "octo-org/octo-repo/.github/workflows/deploy.yml@refs/heads/main",
395+
"workflow_sha": "abc123def456789abc123def456789abc123def4",
396+
"workflow_repository": "octo-org/octo-repo",
397+
"workflow_file_path": ".github/workflows/deploy.yml",
390398
"container": {
391399
"network": "github_network_53269bd575974817b43f4733536b200c"
392400
},
@@ -427,6 +435,32 @@ jobs:
427435
- run: echo "Run tests against Postgres"
428436
```
429437

438+
### Example usage of `job` context workflow identity
439+
440+
> [!NOTE]
441+
> The `job.workflow_*` context properties are not available on {% data variables.product.prodname_ghe_server %}.
442+
443+
This example reusable workflow uses `job.workflow_repository` and `job.workflow_sha` to check out its own source code, rather than the caller's repository. This is useful when a reusable workflow needs to access files co-located with the workflow definition.
444+
445+
```yaml copy
446+
# In a reusable workflow (e.g., octo-org/shared-workflows/.github/workflows/deploy.yml)
447+
name: Reusable deploy workflow
448+
on:
449+
workflow_call:
450+
451+
jobs:
452+
deploy:
453+
runs-on: ubuntu-latest
454+
steps:
455+
- uses: {% data reusables.actions.action-checkout %}
456+
with:
457+
repository: {% raw %}${{ job.workflow_repository }}{% endraw %}
458+
ref: {% raw %}${{ job.workflow_sha }}{% endraw %}
459+
460+
- run: echo "Deploying from {% raw %}${{ job.workflow_ref }}{% endraw %}"
461+
- run: echo "Workflow file path is {% raw %}${{ job.workflow_file_path }}{% endraw %}"
462+
```
463+
430464
## `jobs` context
431465

432466
The `jobs` context is only available in reusable workflows, and can only be used to set outputs for a reusable workflow. For more information, see [AUTOTITLE](/actions/using-workflows/reusing-workflows#using-outputs-from-a-reusable-workflow).
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
actions/checkout@v5
1+
actions/checkout@v6

0 commit comments

Comments
 (0)