Skip to content
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

feat: Add Targeted Execution to the Pre/Post Workflow Hooks #3708

Merged
merged 9 commits into from
Oct 6, 2023

Conversation

X-Guardian
Copy link
Contributor

@X-Guardian X-Guardian commented Aug 28, 2023

what

Adds a commands property to the pre/post workflow hook definition and logic to allow targeted execution of the hooks.

why

tests

repos.yaml

repos:
- id: /.*/
  pre_workflow_hooks:
    - description: pre workflow plan
      commands: plan
      run: |
        echo "plan"
    - description: pre workflow apply
      commands: apply
      run: |
        echo "apply"
    - description: pre workflow plan/apply
      commands: plan, apply
      run: |
        echo "plan & apply"
    - description: pre workflow all
      run: |
        echo "all"
  post_workflow_hooks:
    - description: post workflow plan
      commands: plan
      run: |
        echo "plan"
    - description: post workflow apply
      commands: apply
      run: |
        echo "apply"
    - description: post workflow plan/apply
      commands: plan, apply
      run: |
        echo "plan & apply"
    - description: post workflow all
      run: |
        echo "all"

Plan Command Log Extract

{"level":"debug","ts":"2023-08-28T11:05:03.274+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow plan', Command 'plan', Target commands [plan]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:03.274+0100","caller":"events/pre_workflow_hooks_command_runner.go:116","msg":"Running pre workflow hook: 'pre workflow plan'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:03.275+0100","caller":"events/pre_workflow_hooks_command_runner.go:121","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:03.275+0100","caller":"events/pre_workflow_hooks_command_runner.go:126","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:05:03.631+0100","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"plan\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.033+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow apply', Command 'plan', Target commands [apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.034+0100","caller":"events/pre_workflow_hooks_command_runner.go:112","msg":"Skipping pre workflow hook 'pre workflow apply' as command 'plan' is not in Commands [apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.034+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow plan/apply', Command 'plan', Target commands [plan, apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.035+0100","caller":"events/pre_workflow_hooks_command_runner.go:116","msg":"Running pre workflow hook: 'pre workflow plan/apply'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.035+0100","caller":"events/pre_workflow_hooks_command_runner.go:121","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.035+0100","caller":"events/pre_workflow_hooks_command_runner.go:126","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:05:04.351+0100","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"plan & apply\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.680+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow all', Command 'plan', Target commands []","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.681+0100","caller":"events/pre_workflow_hooks_command_runner.go:116","msg":"Running pre workflow hook: 'pre workflow all'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.681+0100","caller":"events/pre_workflow_hooks_command_runner.go:121","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:04.681+0100","caller":"events/pre_workflow_hooks_command_runner.go:126","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:05:05.011+0100","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"all\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}

{"level":"debug","ts":"2023-08-28T11:05:13.401+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow plan', Command 'plan', Target commands [plan]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:13.401+0100","caller":"events/post_workflow_hooks_command_runner.go:119","msg":"Running post workflow hook: 'post workflow plan'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:13.402+0100","caller":"events/post_workflow_hooks_command_runner.go:125","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:13.402+0100","caller":"events/post_workflow_hooks_command_runner.go:130","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:05:13.727+0100","caller":"runtime/post_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"plan\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.020+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow apply', Command 'plan', Target commands [apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.021+0100","caller":"events/post_workflow_hooks_command_runner.go:115","msg":"Skipping post workflow hook 'post workflow apply' as command 'plan' is not in Commands [apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.021+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow plan/apply', Command 'plan', Target commands [plan, apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.022+0100","caller":"events/post_workflow_hooks_command_runner.go:119","msg":"Running post workflow hook: 'post workflow plan/apply'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.023+0100","caller":"events/post_workflow_hooks_command_runner.go:125","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.024+0100","caller":"events/post_workflow_hooks_command_runner.go:130","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:05:14.336+0100","caller":"runtime/post_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"plan & apply\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.619+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow all', Command 'plan', Target commands []","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.620+0100","caller":"events/post_workflow_hooks_command_runner.go:119","msg":"Running post workflow hook: 'post workflow all'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.620+0100","caller":"events/post_workflow_hooks_command_runner.go:125","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:05:14.620+0100","caller":"events/post_workflow_hooks_command_runner.go:130","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:05:14.957+0100","caller":"runtime/post_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"all\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}

Apply Command Log Extract

{"level":"debug","ts":"2023-08-28T11:26:00.877+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow plan', Command 'apply', Target commands [plan]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:00.877+0100","caller":"events/pre_workflow_hooks_command_runner.go:112","msg":"Skipping pre workflow hook 'pre workflow plan' as command 'apply' is not in Commands [plan]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:00.877+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow apply', Command 'apply', Target commands [apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:00.877+0100","caller":"events/pre_workflow_hooks_command_runner.go:116","msg":"Running pre workflow hook: 'pre workflow apply'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:00.878+0100","caller":"events/pre_workflow_hooks_command_runner.go:121","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:00.878+0100","caller":"events/pre_workflow_hooks_command_runner.go:126","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:26:01.194+0100","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"apply\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:01.479+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow plan/apply', Command 'apply', Target commands [plan, apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:01.479+0100","caller":"events/pre_workflow_hooks_command_runner.go:116","msg":"Running pre workflow hook: 'pre workflow plan/apply'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:01.480+0100","caller":"events/pre_workflow_hooks_command_runner.go:121","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:01.480+0100","caller":"events/pre_workflow_hooks_command_runner.go:126","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:26:01.814+0100","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"plan & apply\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:02.118+0100","caller":"events/pre_workflow_hooks_command_runner.go:109","msg":"Processing pre workflow hook 'pre workflow all', Command 'apply', Target commands []","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:02.118+0100","caller":"events/pre_workflow_hooks_command_runner.go:116","msg":"Running pre workflow hook: 'pre workflow all'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:02.122+0100","caller":"events/pre_workflow_hooks_command_runner.go:121","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:02.122+0100","caller":"events/pre_workflow_hooks_command_runner.go:126","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:26:02.431+0100","caller":"runtime/pre_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"all\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}

{"level":"debug","ts":"2023-08-28T11:26:08.046+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow plan', Command 'apply', Target commands [plan]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.046+0100","caller":"events/post_workflow_hooks_command_runner.go:115","msg":"Skipping post workflow hook 'post workflow plan' as command 'apply' is not in Commands [plan]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.046+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow apply', Command 'apply', Target commands [apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.046+0100","caller":"events/post_workflow_hooks_command_runner.go:119","msg":"Running post workflow hook: 'post workflow apply'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.047+0100","caller":"events/post_workflow_hooks_command_runner.go:125","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.047+0100","caller":"events/post_workflow_hooks_command_runner.go:130","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:26:08.524+0100","caller":"runtime/post_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"apply\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.876+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow plan/apply', Command 'apply', Target commands [plan, apply]","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.877+0100","caller":"events/post_workflow_hooks_command_runner.go:119","msg":"Running post workflow hook: 'post workflow plan/apply'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.877+0100","caller":"events/post_workflow_hooks_command_runner.go:125","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:08.877+0100","caller":"events/post_workflow_hooks_command_runner.go:130","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:26:09.187+0100","caller":"runtime/post_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"plan & apply\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:09.488+0100","caller":"events/post_workflow_hooks_command_runner.go:112","msg":"Processing post workflow hook 'post workflow all', Command 'apply', Target commands []","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:09.488+0100","caller":"events/post_workflow_hooks_command_runner.go:119","msg":"Running post workflow hook: 'post workflow all'","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:09.488+0100","caller":"events/post_workflow_hooks_command_runner.go:125","msg":"Setting shell to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"debug","ts":"2023-08-28T11:26:09.489+0100","caller":"events/post_workflow_hooks_command_runner.go:130","msg":"Setting shellArgs to default: \"\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}
{"level":"info","ts":"2023-08-28T11:26:09.813+0100","caller":"runtime/post_workflow_hook_runner.go:80","msg":"successfully ran \"sh -c echo \\\"all\\\"\\n\" in \"/root/.atlantis/repos/Guardian-Teck/atlantis-test/4/default\"","json":{"repo":"Guardian-Teck/atlantis-test","pull":"4"}}

@X-Guardian X-Guardian requested a review from a team as a code owner August 28, 2023 10:38
@github-actions github-actions bot added docs Documentation go Pull requests that update Go code labels Aug 28, 2023
@jamengual jamengual added the waiting-on-review Waiting for a review from a maintainer label Sep 8, 2023
@GenPage GenPage merged commit 64f7d2e into runatlantis:main Oct 6, 2023
15 checks passed
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
…tis#3708)

* Add Workflow hook target filter

* Fix post workflow hook example

* Update WokrflowHook in global_cfg

* Fix linting

---------

Co-authored-by: PePe Amengual <[email protected]>
ijames-gc pushed a commit to gocardless/atlantis that referenced this pull request Feb 13, 2024
…tis#3708)

* Add Workflow hook target filter

* Fix post workflow hook example

* Update WokrflowHook in global_cfg

* Fix linting

---------

Co-authored-by: PePe Amengual <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation go Pull requests that update Go code waiting-on-review Waiting for a review from a maintainer
Projects
None yet
3 participants