Skip to content

Commit

Permalink
Scripts -> Actions (#1144)
Browse files Browse the repository at this point in the history
## Related Issues
Related to #939 
Fixes #1137, #1022

### Backwards compatible replacement of simple `scripts` with complex
`actions`
- [x] Define types
- [x] `package create` transparent migration
- [x] `package deploy` transparent migration
- [x] Introduce deprecation pattern into `src/pkg/packager`
- [x] Package`Create` actions: `Before`, `After`, `Success`, `Failure`
- [x] Package`Deploy` actions: `Before`, `After`, `Success`, `Failure` 
- [x] Package`Remove` actions: `Before`, `After`, `Success`, `Failure`
  
### Other refactors
- [x] Expand exec to support env variables, add config struct
- [x] Add common cmd defaults
- [x] Add set working dir support 
- [x] Inject deploy-time variables as env variables for `onDeploy`
- [x] Expand sha256sum function to support any generic crypto hash type

Co-authored-by: Wayne Starr <[email protected]>
Co-authored-by: Jon Perry <[email protected]>
  • Loading branch information
3 people authored Jan 24, 2023
1 parent 3cca81a commit f83dc63
Show file tree
Hide file tree
Showing 65 changed files with 2,517 additions and 660 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ build-examples: ## Build all of the example packages

@test -s ./build/zarf-package-dos-games-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/game -o build -a $(ARCH) --confirm

@test -s ./build/zarf-package-component-scripts-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/component-scripts -o build -a $(ARCH) --confirm
@test -s ./build/zarf-package-component-actions-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/component-actions -o build -a $(ARCH) --confirm

@test -s ./build/zarf-package-component-choice-$(ARCH).tar.zst || $(ZARF_BIN) package create examples/component-choice -o build -a $(ARCH) --confirm

Expand Down
2 changes: 1 addition & 1 deletion adr/0009-yolo-mode.md → adr/0010-yolo-mode.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 9. YOLO Mode
# 10. YOLO Mode

Date: 2022-12-14

Expand Down
27 changes: 27 additions & 0 deletions adr/0011-scripts-actions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 11. Scripts -> Actions

Date: 2023-01-18

## Status

Accepted

## Context

Originally, the `scripts` noun was added to components to allow us to move hard-coded init business logic out of the codebase and into the package system. At the time there was only a `before` and `after` section with simply an array entry per command. Later, `prepare` was added as a way to do something during `zarf package create`. As teams began to find new ways to use the capabilities, their limitations became more obvious.

## Decision

The `scripts` section of the `zarf.yaml` will be replaced with a new `actions` section. The `actions` section will be a map of action names to a list of commands to run. `actions` will contain `action sets` that map to the following lifecycle events:

- `onCreate` - Runs during `zarf package create`
- `onDeploy` - Runs during `zarf package deploy`
- `onRemove` - Runs during `zarf package remove`

In addition to adding more lifecycle events, the `actions` section will also allow for more complex actions to be defined. New configurations include, setting the cmd directory, defining custom env variables, setting the number of retries, setting the max total seconds, muting the output, and [setting a variable](../docs/4-user-guide/5-component-actions.md#creating-dynamic-variables-from-actions) to be used in other actions or components.

Further details can be found in the `component-actions` [component actions documentation](../docs/4-user-guide/7-github-action.md), [component lifecycle documentation](../docs/4-user-guide/4-package-command-lifecycle.md), and the [example package](../examples/component-actions/README.md).

## Consequences

With the current team agreement to not introduce breaking changes as we stabilize the API, a deprecation model was introduced that allows existing Zarf binaries to run with older `zarf.yaml` configs while also allowing the new features to be used by those who have updated their Zarf binary.
Loading

0 comments on commit f83dc63

Please sign in to comment.