feat: Add pre and post workflow hook status (#2441)

* Add pre and post workflow hook status

* fix missing mocks

* fix pre/post workflow hooks tests

* add cmd output to file

* fix typo

* add cmd output to file on pre workflow hooks

* Add hooks output to web UI

* Remove unnecessary dependencies

* Clean the code and make tests work again

* Make lint happy

* Small fixes, create dedicated UUID generator and docs

* Add missing commentary

* Use matchers instead of mocking for tests and fix e2e tests

* Change 'OUTPUT_FILE' to 'OUTPUT_STATUS_FILE'

* Reduce SendWorkflowHook calls on hooks

* Apply suggestions from code review

Co-authored-by: PePe Amengual <jose.amengual@gmail.com>
Co-authored-by: nitrocode <7775707+nitrocode@users.noreply.github.com>
This commit is contained in:
Fabiano Soares Honorato
2022-12-19 17:20:34 -03:00
committed by GitHub
parent 36686597b8
commit cb485f11ee
45 changed files with 1428 additions and 264 deletions

View File

@@ -6,7 +6,7 @@ workflows](custom-workflows.html#custom-run-command) in that they are run
outside of Atlantis commands. Which means they do not surface their output
back to the PR as a comment.
Post workflow hooks also only allow `run` commands.
Post workflow hooks also only allow `run` and `description` commands.
[[toc]]
@@ -40,6 +40,7 @@ repos:
workflow: myworkflow
post_workflow_hooks:
- run: infracost output --path=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM-*-infracost.json --format=github-comment --out-file=/tmp/infracost-comment.md
description: Running infracost
# Now report the output as desired, e.g. post to GitHub as a comment.
# ...
```
@@ -55,9 +56,10 @@ command](custom-workflows.html#custom-run-command).
- run: custom-command
```
| Key | Type | Default | Required | Description |
| --- | ------ | ------- | -------- | -------------------- |
| run | string | none | no | Run a custom command |
| Key | Type | Default | Required | Description |
| ----------- | ------ | ------- | -------- | --------------------- |
| run | string | none | no | Run a custom command |
| description | string | none | no | Post hook description |
::: tip Notes
* `run` commands are executed with the following environment variables:
@@ -74,4 +76,5 @@ command](custom-workflows.html#custom-run-command).
* `USER_NAME` - Username of the VCS user running command, ex. `acme-user`. During an autoplan, the user will be the Atlantis API user, ex. `atlantis`.
* `COMMENT_ARGS` - Any additional flags passed in the comment on the pull request. Flags are separated by commas and
every character is escaped, ex. `atlantis plan -- arg1 arg2` will result in `COMMENT_ARGS=\a\r\g\1,\a\r\g\2`.
* `OUTPUT_STATUS_FILE` - An output file to customize the success or failure status. ex. `echo 'failure' > $OUTPUT_STATUS_FILE`.
:::

View File

@@ -8,7 +8,7 @@ workflows](custom-workflows.html#custom-run-command) in several ways.
present. This be utilized to [dynamically generate repo configs](pre-workflow-hooks.html#dynamic-repo-config-generation).
2. Pre workflow hooks are run outside of Atlantis commands. Which means
they do not surface their output back to the PR as a comment.
3. Pre workflow hooks only allow `run` commands.
3. Pre workflow hooks only allow `run` and `description` commands.
[[toc]]
@@ -31,6 +31,7 @@ repos:
- id: /.*/
pre_workflow_hooks:
- run: ./repo-config-generator.sh
description: Generating configs
```
## Reference
### Custom `run` Command
@@ -39,9 +40,10 @@ command](custom-workflows.html#custom-run-command).
```yaml
- run: custom-command
```
| Key | Type | Default | Required | Description |
| --- | ------ | ------- | -------- | -------------------- |
| run | string | none | no | Run a custom command |
| Key | Type | Default | Required | Description |
| ----------- | ------ | ------- | -------- | -------------------- |
| run | string | none | no | Run a custom command |
| description | string | none | no | Pre hook description |
::: tip Notes
* `run` commands are executed with the following environment variables:
@@ -58,5 +60,6 @@ command](custom-workflows.html#custom-run-command).
* `USER_NAME` - Username of the VCS user running command, ex. `acme-user`. During an autoplan, the user will be the Atlantis API user, ex. `atlantis`.
* `COMMENT_ARGS` - Any additional flags passed in the comment on the pull request. Flags are separated by commas and
every character is escaped, ex. `atlantis plan -- arg1 arg2` will result in `COMMENT_ARGS=\a\r\g\1,\a\r\g\2`.
* `OUTPUT_STATUS_FILE` - An output file to customize the success or failure status. ex. `echo 'failure' > $OUTPUT_STATUS_FILE`.
:::