Skip to content

Commit

Permalink
Unified inputs context (#27254)
Browse files Browse the repository at this point in the history
  • Loading branch information
skedwards88 authored Jun 10, 2022
1 parent 6377003 commit e7a6d02
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 24 deletions.
53 changes: 42 additions & 11 deletions content/actions/learn-github-actions/contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ You can access contexts using the expression syntax. For more information, see "
| `matrix` | `object` | Contains the matrix properties defined in the workflow that apply to the current job. For more information, see [`matrix` context](#matrix-context). |
| `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). |
{%- ifversion fpt or ghec or ghes > 3.3 or ghae-issue-4757 %}
| `inputs` | `object` | Contains the inputs of a reusable workflow. For more information, see [`inputs` context](#inputs-context). |{% endif %}
| `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 %}

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

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

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.
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 %}

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

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

For more information, see "[Reusing workflows](/actions/learn-github-actions/reusing-workflows)".

| Property name | Type | Description |
|---------------|------|-------------|
| `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. |
| `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. |
| `inputs.<name>` | `string` or `number` or `boolean` | Each input value passed from an external workflow. |

### Example contents of the `inputs` context

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.
The following example contents of the `inputs` context is from a workflow that has defined the `build_id`, `deploy_target`, and `perform_deploy` inputs.

```yaml
{
"build_id": 123456768,
"deploy_target": "deployment_sys_1a"
"deploy_target": "deployment_sys_1a",
"perform_deploy": true
}
```

### Example usage of the `inputs` context
### Example usage of the `inputs` context in a reusable workflow

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.
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.

{% raw %}
```yaml{:copy}
Expand All @@ -761,10 +760,42 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ inputs.perform_deploy == 'true' }}
if: ${{ inputs.perform_deploy }}
steps:
- name: Deploy build to target
run: deploy --build ${{ inputs.build_id }} --target ${{ inputs.deploy_target }}
```
{% endraw %}

{% if actions-unified-inputs %}
### Example usage of the `inputs` context in a manually triggered workflow

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.

{% raw %}
```yaml{:copy}
on:
workflow_dispatch:
inputs:
build_id:
required: true
type: string
deploy_target:
required: true
type: string
perform_deploy:
required: true
type: boolean
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ inputs.perform_deploy }}
steps:
- name: Deploy build to target
run: deploy --build ${{ inputs.build_id }} --target ${{ inputs.deploy_target }}
```
{% endraw %}
{% endif %}

{% endif %}
20 changes: 10 additions & 10 deletions content/actions/using-workflows/events-that-trigger-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -1250,12 +1250,13 @@ on: workflow_dispatch

#### Providing inputs

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)."
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)."

{% data reusables.actions.inputs-vs-github-event-inputs %}

{% ifversion fpt or ghec or ghes > 3.3 or ghae-issue-5511 %}
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.
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.

{% raw %}
```yaml
on:
workflow_dispatch:
Expand Down Expand Up @@ -1287,11 +1288,10 @@ jobs:
echo "Tags: $TAGS"
echo "Environment: $ENVIRONMENT"
env:
LEVEL: ${{ github.event.inputs.logLevel }}
TAGS: ${{ github.event.inputs.tags }}
ENVIRONMENT: ${{ github.event.inputs.environment }}
LEVEL: {% if actions-unified-inputs %}{% raw %}${{ inputs.logLevel }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.logLevel }}{% endraw %}{% endif %}
TAGS: {% if actions-unified-inputs %}{% raw %}${{ inputs.tags }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.tags }}{% endraw %}{% endif %}
ENVIRONMENT: {% if actions-unified-inputs %}{% raw %}${{ inputs.environment }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.environment }}{% endraw %}{% endif %}
```
{% endraw %}

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

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

{% else %}
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.
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.

```yaml
name: Manually triggered workflow
Expand All @@ -1330,8 +1330,8 @@ jobs:
echo Hello $NAME!
echo -in $HOME
env:
NAME: {% raw %}${{ github.event.inputs.name }}{% endraw %}
HOME: {% raw %}${{ github.event.inputs.home }}{% endraw %}
NAME: {% if actions-unified-inputs %}{% raw %}${{ inputs.name }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.name }}{% endraw %}{% endif %}
HOME: {% if actions-unified-inputs %}{% raw %}${{ github.event.inputs.home }}{% endraw %}{% else %}{% raw %}${{ github.event.inputs.home }}{% endraw %}{% endif %}
```
{% endif %}

Expand Down
6 changes: 6 additions & 0 deletions data/features/actions-unified-inputs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Issue 6921
versions:
fpt: '*'
ghec: '*'
ghes: '>=3.6'
ghae: 'issue-6921'
8 changes: 8 additions & 0 deletions data/reusables/actions/inputs-vs-github-event-inputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% if actions-unified-inputs %}

{% note %}

**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.

{% endnote %}
{% endif %}
8 changes: 5 additions & 3 deletions data/reusables/actions/workflow-dispatch-inputs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
When using the `workflow_dispatch` event, you can optionally specify inputs that are passed to the workflow.

The triggered workflow receives the inputs in the `github.event.inputs` context. For more information, see "[Contexts](/actions/learn-github-actions/contexts#github-context)."
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 %})."

{% data reusables.actions.inputs-vs-github-event-inputs %}

```yaml
on:
Expand Down Expand Up @@ -31,8 +33,8 @@ on:
jobs:
print-tag:
runs-on: ubuntu-latest
if: {% raw %} ${{ github.event.inputs.print_tags == 'true' }} {% endraw %}
if: {% if actions-unified-inputs %}{% raw %} ${{ inputs.print_tags }} {% endraw %}{% else %}{% raw %} ${{ github.event.inputs.print_tags == 'true' }} {% endraw %}{% endif %}
steps:
- name: Print the input tag to STDOUT
run: echo {% raw %} The tags are ${{ github.event.inputs.tags }} {% endraw %}
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 %}
```

0 comments on commit e7a6d02

Please sign in to comment.