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

Add pre workflow custom hooks to run scripts before workflow execution(plan, apply, etc) #1255

Merged
merged 11 commits into from
Dec 14, 2020

Conversation

msarvar
Copy link
Contributor

@msarvar msarvar commented Nov 9, 2020

Implements: #500

This PR implement functionality to run user defined scripts before any workflow is executed, the feature is based on discussion in [Feature request] Dynamically generate repo atlantis.yaml config.

Based on a comment added pre_workflow_hooks to server's repo config. Custom scripts can be declared as follows:

- id: your-repo
   pre_workflow_hooks:
   - run: ./my-script
   - run: |
        my bash script inline

To run the scripts I implemented a new PreWorkflowHooksCommandRunner interface, the interface will manage execution life cycle similar to how CommandRunner works, the difference is that it does not update PR with the outcome of the execution. The PreWorkflowHooksCommandRunner is triggered when PR is created or updated and runs before the autoplan. If PreWorkflowHooksCommandRunner fails during execution it will log the error but will not update the PR or stop autoplan from running.

I haven't updated the documentation but wanted to get the changes out to get some eyes on the PR.

@codecov
Copy link

codecov bot commented Nov 9, 2020

Codecov Report

Merging #1255 (c25d57c) into master (5a1e191) will increase coverage by 0.06%.
The diff coverage is 76.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1255      +/-   ##
==========================================
+ Coverage   69.98%   70.05%   +0.06%     
==========================================
  Files          71       74       +3     
  Lines        5414     5540     +126     
==========================================
+ Hits         3789     3881      +92     
- Misses       1275     1303      +28     
- Partials      350      356       +6     
Impacted Files Coverage Δ
server/events/models/models.go 78.99% <ø> (ø)
server/events/project_command_builder.go 78.92% <ø> (ø)
server/events/yaml/raw/global_cfg.go 0.00% <0.00%> (ø)
server/events/pre_workflow_hooks_command_runner.go 64.58% <64.58%> (ø)
server/events/yaml/raw/pre_workflow_step.go 64.86% <64.86%> (ø)
server/events/runtime/pre_workflow_hook_runner.go 100.00% <100.00%> (ø)
server/events/yaml/valid/global_cfg.go 89.65% <100.00%> (+0.14%) ⬆️
server/events_controller.go 56.38% <100.00%> (+0.31%) ⬆️
server/server.go 62.40% <100.00%> (+0.96%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a1e191...c25d57c. Read the comment docs.

@msarvar msarvar changed the title Pre workflow hooks Adding pre workflow hooks to run scripts Nov 9, 2020
@msarvar msarvar changed the title Adding pre workflow hooks to run scripts Add pre workflow custom hooks to run scripts before workflow execution(plan, apply, etc) Nov 17, 2020
Copy link
Contributor

@nishkrishnan nishkrishnan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

@msarvar
Copy link
Contributor Author

msarvar commented Dec 8, 2020

Thanks for approvals! I will add some runatlantis.io to include pre-workflow-hook example.

@ishallbethat
Copy link

how is it going ? is this PR ready for merge ?

@msarvar
Copy link
Contributor Author

msarvar commented Dec 11, 2020

@nishkrishnan @chenrui333 I update the runatlantis.io/docs to include pre-workflow-hooks as well.

@nishkrishnan
Copy link
Contributor

If you rebase, the failed test will probably resolve

@nishkrishnan nishkrishnan merged commit 3456dc9 into runatlantis:master Dec 14, 2020
@mikecutalo mikecutalo deleted the pre-workflow-hooks branch June 8, 2023 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants