Skip to content

Commit e7a6d02

Browse files
authored
Unified inputs context (github#27254)
1 parent 6377003 commit e7a6d02

File tree

5 files changed

+71
-24
lines changed

5 files changed

+71
-24
lines changed

content/actions/learn-github-actions/contexts.md

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ You can access contexts using the expression syntax. For more information, see "
4545
| `matrix` | `object` | Contains the matrix properties defined in the workflow that apply to the current job. For more information, see [`matrix` context](#matrix-context). |
4646
| `needs` | `object` | Contains the outputs of all jobs that are defined as a dependency of the current job. For more information, see [`needs` context](#needs-context). |
4747
{%- ifversion fpt or ghec or ghes > 3.3 or ghae-issue-4757 %}
48-
| `inputs` | `object` | Contains the inputs of a reusable workflow. For more information, see [`inputs` context](#inputs-context). |{% endif %}
48+
| `inputs` | `object` | Contains the inputs of a reusable {% if actions-unified-inputs %}or manually triggered {% endif %}workflow. For more information, see [`inputs` context](#inputs-context). |{% endif %}
4949

5050
As part of an expression, you can access context information using one of two syntaxes.
5151

@@ -714,33 +714,32 @@ jobs:
714714
{% ifversion fpt or ghec or ghes > 3.3 or ghae-issue-4757 %}
715715
## `inputs` context
716716

717-
The `inputs` context contains input properties passed to a reusable workflow. The input names and types are defined in the [`workflow_call` event configuration](/actions/learn-github-actions/events-that-trigger-workflows#workflow-reuse-events) of a reusable workflow, and the input values are passed from [`jobs.<job_id>.with`](/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idwith) in an external workflow that calls the reusable workflow.
717+
The `inputs` context contains input properties passed to a reusable workflow{% if actions-unified-inputs %} or to a manually triggered workflow{% endif %}. {% if actions-unified-inputs %}For reusable workflows, the{% else %}The{% endif %} input names and types are defined in the [`workflow_call` event configuration](/actions/learn-github-actions/events-that-trigger-workflows#workflow-reuse-events) of a reusable workflow, and the input values are passed from [`jobs.<job_id>.with`](/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idwith) in an external workflow that calls the reusable workflow. {% if actions-unified-inputs %}For manually triggered workflows, the inputs are defined in the [`workflow_dispatch` event configuration](/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch) of a workflow.{% endif %}
718718

719-
There are no standard properties in the `inputs` context, only those which are defined in the reusable workflow file.
719+
There are no standard properties in the `inputs` context, only those which are defined in the workflow file.
720720

721721
{% data reusables.actions.reusable-workflows-ghes-beta %}
722722

723-
For more information, see "[Reusing workflows](/actions/learn-github-actions/reusing-workflows)".
724-
725723
| Property name | Type | Description |
726724
|---------------|------|-------------|
727-
| `inputs` | `object` | This context is only available in a [reusable workflow](/actions/learn-github-actions/reusing-workflows). You can access this context from any job or step in a workflow. This object contains the properties listed below. |
725+
| `inputs` | `object` | This context is only available in a [reusable workflow](/actions/learn-github-actions/reusing-workflows){% if actions-unified-inputs %} or in a workflow triggered by the [`workflow_dispatch` event](/actions/learn-github-actions/events-that-trigger-workflows#workflow_dispatch){% endif %}. You can access this context from any job or step in a workflow. This object contains the properties listed below. |
728726
| `inputs.<name>` | `string` or `number` or `boolean` | Each input value passed from an external workflow. |
729727

730728
### Example contents of the `inputs` context
731729

732-
The following example contents of the `inputs` context is from a job in a reusable workflow that has defined the `build_id` and `deploy_target` inputs.
730+
The following example contents of the `inputs` context is from a workflow that has defined the `build_id`, `deploy_target`, and `perform_deploy` inputs.
733731

734732
```yaml
735733
{
736734
"build_id": 123456768,
737-
"deploy_target": "deployment_sys_1a"
735+
"deploy_target": "deployment_sys_1a",
736+
"perform_deploy": true
738737
}
739738
```
740739

741-
### Example usage of the `inputs` context
740+
### Example usage of the `inputs` context in a reusable workflow
742741

743-
This example reusable workflow uses the `inputs` context to get the values of the `build_id` and `deploy_target` inputs that were passed to the reusable workflow from the caller workflow.
742+
This example reusable workflow uses the `inputs` context to get the values of the `build_id`, `deploy_target`, and `perform_deploy` inputs that were passed to the reusable workflow from the caller workflow.
744743

745744
{% raw %}
746745
```yaml{:copy}
@@ -761,10 +760,42 @@ on:
761760
jobs:
762761
deploy:
763762
runs-on: ubuntu-latest
764-
if: ${{ inputs.perform_deploy == 'true' }}
763+
if: ${{ inputs.perform_deploy }}
764+
steps:
765+
- name: Deploy build to target
766+
run: deploy --build ${{ inputs.build_id }} --target ${{ inputs.deploy_target }}
767+
```
768+
{% endraw %}
769+
770+
{% if actions-unified-inputs %}
771+
### Example usage of the `inputs` context in a manually triggered workflow
772+
773+
This example workflow triggered by a `workflow_dispatch` event uses the `inputs` context to get the values of the `build_id`, `deploy_target`, and `perform_deploy` inputs that were passed to the workflow.
774+
775+
{% raw %}
776+
```yaml{:copy}
777+
on:
778+
workflow_dispatch:
779+
inputs:
780+
build_id:
781+
required: true
782+
type: string
783+
deploy_target:
784+
required: true
785+
type: string
786+
perform_deploy:
787+
required: true
788+
type: boolean
789+
790+
jobs:
791+
deploy:
792+
runs-on: ubuntu-latest
793+
if: ${{ inputs.perform_deploy }}
765794
steps:
766795
- name: Deploy build to target
767796
run: deploy --build ${{ inputs.build_id }} --target ${{ inputs.deploy_target }}
768797
```
769798
{% endraw %}
770799
{% endif %}
800+
801+
{% endif %}

content/actions/using-workflows/events-that-trigger-workflows.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,12 +1250,13 @@ on: workflow_dispatch
12501250

12511251
#### Providing inputs
12521252

1253-
You can configure custom-defined input properties, default input values, and required inputs for the event directly in your workflow. When you trigger the event, you can provide the `ref` and any `inputs`. When the workflow runs, you can access the input values in the `github.event.inputs` context. For more information, see "[Contexts](/actions/learn-github-actions/contexts)."
1253+
You can configure custom-defined input properties, default input values, and required inputs for the event directly in your workflow. When you trigger the event, you can provide the `ref` and any `inputs`. When the workflow runs, you can access the input values in the {% if actions-unified-inputs %}`inputs`{% else %}`github.event.inputs`{% endif %} context. For more information, see "[Contexts](/actions/learn-github-actions/contexts)."
1254+
1255+
{% data reusables.actions.inputs-vs-github-event-inputs %}
12541256

12551257
{% ifversion fpt or ghec or ghes > 3.3 or ghae-issue-5511 %}
1256-
This example defines inputs called `logLevel`, `tags`, and `environment`. You pass values for these inputs to the workflow when you run it. This workflow then prints the values to the log, using the `github.event.inputs.logLevel`, `github.event.inputs.tags`, and `github.event.inputs.environment` context properties.
1258+
This example defines inputs called `logLevel`, `tags`, and `environment`. You pass values for these inputs to the workflow when you run it. This workflow then prints the values to the log, using the {% if actions-unified-inputs %}`inputs.logLevel`, `inputs.tags`, and `inputs.environment`{% else %}`github.event.inputs.logLevel`, `github.event.inputs.tags`, and `github.event.inputs.environment`{% endif %} context properties.
12571259

1258-
{% raw %}
12591260
```yaml
12601261
on:
12611262
workflow_dispatch:
@@ -1287,11 +1288,10 @@ jobs:
12871288
echo "Tags: $TAGS"
12881289
echo "Environment: $ENVIRONMENT"
12891290
env:
1290-
LEVEL: ${{ github.event.inputs.logLevel }}
1291-
TAGS: ${{ github.event.inputs.tags }}
1292-
ENVIRONMENT: ${{ github.event.inputs.environment }}
1291+
LEVEL: {% if actions-unified-inputs %}{% raw %}${{ inputs.logLevel }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.logLevel }}{% endraw %}{% endif %}
1292+
TAGS: {% if actions-unified-inputs %}{% raw %}${{ inputs.tags }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.tags }}{% endraw %}{% endif %}
1293+
ENVIRONMENT: {% if actions-unified-inputs %}{% raw %}${{ inputs.environment }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.environment }}{% endraw %}{% endif %}
12931294
```
1294-
{% endraw %}
12951295

12961296
If you run this workflow from a browser you must enter values for the required inputs manually before the workflow will run.
12971297

@@ -1306,7 +1306,7 @@ gh workflow run run-tests.yml -f logLevel=warning -f tags=false -f environment=s
13061306
For more information, see the {% data variables.product.prodname_cli %} information in "[Manually running a workflow](/actions/managing-workflow-runs/manually-running-a-workflow)."
13071307

13081308
{% else %}
1309-
This example defines the `name` and `home` inputs and prints them using the `github.event.inputs.name` and `github.event.inputs.home` contexts. If a `home` isn't provided, the default value 'The Octoverse' is printed.
1309+
This example defines the `name` and `home` inputs and prints them using the {% if actions-unified-inputs %}`inputs.name` and `inputs.home`{% else %}`github.event.inputs.name` and `github.event.inputs.home`{% endif %} contexts. If a `home` isn't provided, the default value 'The Octoverse' is printed.
13101310

13111311
```yaml
13121312
name: Manually triggered workflow
@@ -1330,8 +1330,8 @@ jobs:
13301330
echo Hello $NAME!
13311331
echo -in $HOME
13321332
env:
1333-
NAME: {% raw %}${{ github.event.inputs.name }}{% endraw %}
1334-
HOME: {% raw %}${{ github.event.inputs.home }}{% endraw %}
1333+
NAME: {% if actions-unified-inputs %}{% raw %}${{ inputs.name }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.name }}{% endraw %}{% endif %}
1334+
HOME: {% if actions-unified-inputs %}{% raw %}${{ github.event.inputs.home }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.home }}{% endraw %}{% endif %}
13351335
```
13361336
{% endif %}
13371337

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Issue 6921
2+
versions:
3+
fpt: '*'
4+
ghec: '*'
5+
ghes: '>=3.6'
6+
ghae: 'issue-6921'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% if actions-unified-inputs %}
2+
3+
{% note %}
4+
5+
**Note**: The workflow will also receive the inputs in the `github.event.inputs` context. The information in the `inputs` context and `github.event.inputs` context is identical except that the `inputs` context preserves Boolean values as Booleans instead of converting them to strings.
6+
7+
{% endnote %}
8+
{% endif %}

data/reusables/actions/workflow-dispatch-inputs.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
When using the `workflow_dispatch` event, you can optionally specify inputs that are passed to the workflow.
22

3-
The triggered workflow receives the inputs in the `github.event.inputs` context. For more information, see "[Contexts](/actions/learn-github-actions/contexts#github-context)."
3+
The triggered workflow receives the inputs in the {% if actions-unified-inputs %}`inputs`{% else %}`github.event.inputs`{% endif %} context. For more information, see "[Contexts]({% if actions-unified-inputs %}/actions/learn-github-actions/contexts#inputs-context{% else %}/actions/learn-github-actions/contexts#github-context{% endif %})."
4+
5+
{% data reusables.actions.inputs-vs-github-event-inputs %}
46

57
```yaml
68
on:
@@ -31,8 +33,8 @@ on:
3133
jobs:
3234
print-tag:
3335
runs-on: ubuntu-latest
34-
if: {% raw %} ${{ github.event.inputs.print_tags == 'true' }} {% endraw %}
36+
if: {% if actions-unified-inputs %}{% raw %} ${{ inputs.print_tags }} {% endraw %}{% else %}{% raw %} ${{ github.event.inputs.print_tags == 'true' }} {% endraw %}{% endif %}
3537
steps:
3638
- name: Print the input tag to STDOUT
37-
run: echo {% raw %} The tags are ${{ github.event.inputs.tags }} {% endraw %}
39+
run: {% if actions-unified-inputs %}echo {% raw %} The tags are ${{ inputs.tags }} {% endraw %}{% else %}echo {% raw %} The tags are ${{ github.event.inputs.tags }} {% endraw %}{% endif %}
3840
```

0 commit comments

Comments
 (0)