-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composite Run Steps ADR #554
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
edbe74a
start
ethanchewy 185ef8c
Inputs + Outputs
ethanchewy d30db96
Clarify docs
ethanchewy 02b6823
Finish Environment
ethanchewy 91bb0a9
Add if condition
ethanchewy 8e42609
Clarify language
ethanchewy 45c1514
Update 0549-composite-run-steps.md
ethanchewy bc8488e
timeout-minutes
ethanchewy c712d5d
Finish
ethanchewy ef811a4
add relevant example
ethanchewy 474f239
Fix syntax
ethanchewy 0741388
fix env example
ethanchewy d4a1c00
fix yaml syntax
ethanchewy ac9354f
Update 0549-composite-run-steps.md
ethanchewy 0d8e0f0
Update file names, add more relevant example if condition
ethanchewy a48fc79
Add note to continue-on-error
ethanchewy 02020f1
Apply changes to If Condition
ethanchewy bcaed7a
bolding
ethanchewy d74a9ab
Update 0549-composite-run-steps.md
ethanchewy 7e432a5
Update 0549-composite-run-steps.md
ethanchewy c5ddde9
Update 0549-composite-run-steps.md
ethanchewy dc63a51
Update 0549-composite-run-steps.md
ethanchewy 225ef90
Syntax support + spacing
ethanchewy 4170900
Add guiding principles.
ethanchewy 292dab3
Update 0549-composite-run-steps.md
ethanchewy 45458e9
Reverse order.
ethanchewy de80742
Update 0549-composite-run-steps.md
ethanchewy 51f06d4
change from job to step
ethanchewy bba6d10
Update 0549-composite-run-steps.md
ethanchewy 1caedf1
Update 0549-composite-run-steps.md
ethanchewy 8ae6dd9
Update 0549-composite-run-steps.md
ethanchewy 22c8c27
Add Secrets
ethanchewy 43cd477
Update 0549-composite-run-steps.md
ethanchewy 82079ae
Update 0549-composite-run-steps.md
ethanchewy 580cd08
Fix output example
ethanchewy c9eb5df
Fix output example
ethanchewy 3ea4aed
Fix action examples to use using.
ethanchewy 5383305
fix output variable name
ethanchewy 4bc9ce4
update workingDir + env
ethanchewy d2843e8
Defaults + continue-on-error
ethanchewy b2199ac
Update Outputs Section
ethanchewy 9051dfc
Eliminate Env
ethanchewy c88a953
Secrets
ethanchewy 3166328
Update timeout-minutes
ethanchewy e3489c5
Update 0549-composite-run-steps.md
ethanchewy 9664871
Update 0549-composite-run-steps.md
ethanchewy 53da2f5
Fix example.
ethanchewy f9d6481
Remove TODOs
ethanchewy 18124bd
Update 0549-composite-run-steps.md
ethanchewy 1be703b
Update 0549-composite-run-steps.md
ethanchewy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,275 @@ | ||
# ADR 054x: Composite Run Steps | ||
|
||
**Date**: 2020-06-17 | ||
|
||
**Status**: Proposed | ||
|
||
**Relevant PR**: https://github.com/actions/runner/pull/549 | ||
|
||
## Context | ||
|
||
Customers want to be able to compose actions from actions (ex: https://github.com/actions/runner/issues/438) | ||
|
||
An important step towards meeting this goal is to build in functionality for actions where users can simply execute any number of steps. | ||
|
||
## Guiding Principles | ||
|
||
We don't want the workflow author to need to know how the internal workings of the action work. Users shouldn't know the internal workings of the composite action (for example, `default.shell` and `default.workingDir` should not be inherited from the workflow file to the action file). When deciding how to design certain parts of composite run steps, we want to think one logical step from the consumer. | ||
|
||
A composite action is treated as **one** individual job step (aka encapsulation). | ||
|
||
|
||
## Decision | ||
|
||
**In this ADR, we only support running multiple run steps in an Action.** In doing so, we build in support for mapping and flowing the inputs, outputs, and env variables (ex: All nested steps should have access to its parents' input variables and nested steps can overwrite the input variables). | ||
|
||
## Steps | ||
|
||
Example `workflow.yml` | ||
|
||
```yaml | ||
jobs: | ||
build: | ||
runs-on: self-hosted | ||
steps: | ||
- id: step1 | ||
uses: actions/setup-python@v1 | ||
- id: step2 | ||
uses: actions/setup-node@v2 | ||
- uses: actions/checkout@v2 | ||
- uses: user/composite@v1 | ||
- name: workflow step 1 | ||
run: echo hello world 3 | ||
- name: workflow step 2 | ||
run: echo hello world 4 | ||
``` | ||
|
||
Example `user/composite/action.yml` | ||
|
||
```yaml | ||
runs: | ||
using: "composite" | ||
steps: | ||
- run: pip install -r requirements.txt | ||
- run: npm install | ||
``` | ||
|
||
Example Output | ||
|
||
```yaml | ||
[npm installation output] | ||
[pip requirements output] | ||
echo hello world 3 | ||
echo hello world 4 | ||
``` | ||
|
||
We add a token called "composite" which allows our Runner code to process composite actions. By invoking "using: composite", our Runner code then processes the "steps" attribute, converts this template code to a list of steps, and finally runs each run step sequentially. If any step fails and there are no `if` conditions defined, the whole composite action job fails. | ||
|
||
## Inputs | ||
|
||
Example `workflow.yml`: | ||
|
||
```yaml | ||
steps: | ||
- id: foo | ||
uses: user/composite@v1 | ||
with: | ||
your_name: "Octocat" | ||
``` | ||
|
||
Example `user/composite/action.yml`: | ||
|
||
```yaml | ||
inputs: | ||
your_name: | ||
description: 'Your name' | ||
default: 'Ethan' | ||
runs: | ||
using: "composite" | ||
steps: | ||
- run: echo hello ${{ inputs.your_name }} | ||
``` | ||
|
||
Example Output: | ||
|
||
``` | ||
hello Octocat | ||
``` | ||
|
||
Each input variable in the composite action is only viewable in its own scope. | ||
|
||
## Outputs | ||
|
||
Example `workflow.yml`: | ||
|
||
```yaml | ||
... | ||
steps: | ||
- id: foo | ||
uses: user/composite@v1 | ||
- run: echo random-number ${{ steps.foo.outputs.random-number }} | ||
``` | ||
|
||
Example `user/composite/action.yml`: | ||
|
||
```yaml | ||
outputs: | ||
random-number: | ||
description: "Random number" | ||
value: ${{ steps.random-number-generator.outputs.random-id }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- id: random-number-generator | ||
run: echo "::set-output name=random-number::$(echo $RANDOM)" | ||
``` | ||
|
||
Example Output: | ||
|
||
``` | ||
::set-output name=my-output::43243 | ||
random-number 43243 | ||
``` | ||
|
||
Each of the output variables from the composite action is viewable from the workflow file that uses the composite action. In other words, every child action output(s) is viewable only by its parent using dot notation (ex `steps.foo.outputs.random-number`). | ||
|
||
Moreover, the output ids are only accessible within the scope where it was defined. Note that in the example above, in our `workflow.yml` file, it should not have access to output id (i.e. `random-id`). The reason why we are doing this is because we don't want to require the workflow author to know the internal workings of the composite action. | ||
|
||
## Context | ||
|
||
Similar to the workflow file, the composite action has access to the [same context objects](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#contexts) (ex: `github`, `env`, `strategy`). | ||
|
||
## Environment | ||
|
||
In the Composite Action, you'll only be able to use `::set-env::` to set environment variables just like you could with other actions. | ||
|
||
## Secrets | ||
|
||
**Note** : This feature will be focused on in a future ADR. | ||
|
||
We'll pass the secrets from the composite action's parents (ex: the workflow file) to the composite action. Secrets can be created in the composite action with the secrets context. In the actions yaml, we'll automatically mask the secret. | ||
|
||
|
||
## If Condition | ||
|
||
Example `workflow.yml`: | ||
|
||
```yaml | ||
steps: | ||
thboop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- run: exit 1 | ||
- uses: user/composite@v1 # <--- this will run, as it's marked as always runing | ||
if: always() | ||
``` | ||
|
||
Example `user/composite/action.yml`: | ||
|
||
```yaml | ||
runs: | ||
using: "composite" | ||
steps: | ||
- run: echo "just succeeding" | ||
- run: echo "I will run, as my current scope is succeeding" | ||
if: success() | ||
- run: exit 1 | ||
- run: echo "I will not run, as my current scope is now failing" | ||
``` | ||
|
||
See the paragraph below for a rudimentary approach (thank you to @cybojenix for the idea, example, and explanation for this approach): | ||
|
||
The `if` statement in the parent (in the example above, this is the `workflow.yml`) shows whether or not we should run the composite action. So, our composite action will run since the `if` condition for running the composite action is `always()`. | ||
|
||
**Note that the if condition on the parent does not propogate to the rest of its children though.** | ||
|
||
In the child action (in this example, this is the `action.yml`), it starts with a clean slate (in other words, no imposing if conditions). Similar to the logic in the paragraph above, `echo "I will run, as my current scope is succeeding"` will run since the `if` condition checks if the previous steps **within this composite action** has not failed. `run: echo "I will not run, as my current scope is now failing"` will not run since the previous step resulted in an error and by default, the if expression is set to `success()` if the if condition is not set for a step. | ||
|
||
|
||
What if a step has `cancelled()`? We do the opposite of our approach above if `cancelled()` is used for any of our composite run steps. We will cancel any step that has this condition if the workflow is cancelled at all. | ||
|
||
## Timeout-minutes | ||
|
||
Example `workflow.yml`: | ||
|
||
```yaml | ||
steps: | ||
- id: bar | ||
uses: user/test@v1 | ||
timeout-minutes: 50 | ||
``` | ||
|
||
Example `user/composite/action.yml`: | ||
|
||
```yaml | ||
runs: | ||
using: "composite" | ||
steps: | ||
- id: foo1 | ||
run: echo test 1 | ||
timeout-minutes: 10 | ||
- id: foo2 | ||
run: echo test 2 | ||
- id: foo3 | ||
run: echo test 3 | ||
timeout-minutes: 10 | ||
``` | ||
|
||
A composite action in its entirety is a job. You can set both timeout-minutes for the whole composite action or its steps as long as the the sum of the `timeout-minutes` for each composite action step that has the attribute `timeout-minutes` is less than or equals to `timeout-minutes` for the composite action. There is no default timeout-minutes for each composite action step. | ||
|
||
If the time taken for any of the steps in combination or individually exceed the whole composite action `timeout-minutes` attribute, the whole job will fail (1). If an individual step exceeds its own `timeout-minutes` attribute but the total time that has been used including this step is below the overall composite action `timeout-minutes`, the individual step will fail but the rest of the steps will run based on their own `timeout-minutes` attribute (they will still abide by condition (1) though). | ||
|
||
For reference, in the example above, if the composite step `foo1` takes 11 minutes to run, that step will fail but the rest of the steps, `foo1` and `foo2`, will proceed as long as their total runtime with the previous failed `foo1` action is less than the composite action's `timeout-minutes` (50 minutes). If the composite step `foo2` takes 51 minutes to run, it will cause the whole composite action job to fail. I | ||
|
||
The rationale behind this is that users can configure their steps with the `if` condition to conditionally set how steps rely on each other. Due to the additional capabilities that are offered with combining `timeout-minutes` and/or `if`, we wanted the `timeout-minutes` condition to be as dumb as possible and not effect other steps. | ||
|
||
[Usage limits still apply](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions?query=if%28%29#usage-limits) | ||
|
||
|
||
## Continue-on-error | ||
|
||
Example `workflow.yml`: | ||
|
||
```yaml | ||
steps: | ||
- run: exit 1 | ||
- id: bar | ||
uses: user/test@v1 | ||
continue-on-error: false | ||
- id: foo | ||
run: echo "Hello World" <------- This step will not run | ||
``` | ||
|
||
Example `user/composite/action.yml`: | ||
|
||
```yaml | ||
runs: | ||
using: "composite" | ||
steps: | ||
- run: exit 1 | ||
continue-on-error: true | ||
- run: echo "Hello World 2" <----- This step will run | ||
``` | ||
|
||
If any of the steps fail in the composite action and the `continue-on-error` is set to `false` for the whole composite action step in the workflow file, then the steps below it will run. On the flip side, if `continue-on-error` is set to `true` for the whole composite action step in the workflow file, the next job step will run. | ||
|
||
For the composite action steps, it follows the same logic as above. In this example, `"Hello World 2"` will be outputted because the previous step has `continue-on-error` set to `true` although that previous step errored. | ||
|
||
## Defaults | ||
|
||
The composite action author will be required to set the `shell` and `workingDir` of the composite action. Moreover, the composite action author will be able to explicitly set the shell for each composite run step. The workflow author will not have the ability to change these attributes. | ||
|
||
## Visualizing Composite Action in the GitHub Actions UI | ||
We want all the composite action's steps to be condensed into the original composite action node. | ||
thboop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Here is a visual represenation of the [first example](#Steps) | ||
|
||
```yaml | ||
| composite_action_node | | ||
| echo hello world 1 | | ||
| echo hello world 2 | | ||
| echo hello world 3 | | ||
| echo hello world 4 | | ||
|
||
``` | ||
|
||
|
||
## Conclusion | ||
This ADR lays the framework for eventually supporting nested Composite Actions within Composite Actions. This ADR allows for users to run multiple run steps within a GitHub Composite Action with the support of inputs, outputs, environment, and context for use in any steps as well as the if, timeout-minutes, and the continue-on-error attributes for each Composite Action step. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about all the commands we have, ex:
::set-env::
will it only scope to the composite action, or still affect steps within the job?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think following our logic that the workflow author shouldn't know the internal workings of the composite action, we should say that::set-env::
will only scope to the composite action.Update: users can use set-env in composite action that will set env variables for workflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that actions can set environment variables for the job, it feel like
set-env
should also work the same way for composite actions.An usecase would be if someone wants to configure AWS credentials as part of their boilerplate for preparing a deploy.
This involves setting up environment variables.
The workaround here would be for the action author to output everything using
outputs
, and have the workflow author doset-env
themselves.. which is a fair amount of boilerplate, especially that to do it properly you need to handle escaping.