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: post workflow hooks #1990

Merged
merged 3 commits into from
Jan 13, 2022

Conversation

tim775
Copy link
Contributor

@tim775 tim775 commented Jan 10, 2022

This PR implement functionality to run user defined scripts after all workflows have executed. This is a complement to Pre Workflow Hooks that addresses #1954 and builds off previous work done by @gezb.

As with pre_workflow_hooks, the server's repo config can contain custom post_workflow_hooks scripts:

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

Our specific use case is to generate a combined cost estimate report that contains the cost of all workflows. So with a server config like

# repos.yaml
workflows:
  myworkflow:
    plan:
      steps:
      - init
      - plan
      - run: infracost breakdown --path=$PLANFILE --format=json --out-file=/tmp/$BASE_REPO_OWNER-$BASE_REPO_NAME-$PULL_NUM-$WORKSPACE-$REPO_REL_DIR-infracost.json
repos:
  - id: /.*/
    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
      # Now report the output as desired, e.g. post to GitHub as a comment.
      ...

A separate cost estimate comment is posted on the PR (sort of like CodeCov comments but for cost):

Screen Shot 2022-01-10 at 4 27 12 PM

@tim775 tim775 requested a review from a team as a code owner January 10, 2022 21:28
@chenrui333 chenrui333 changed the title Feature/post workflow hooks feat: post workflow hooks Jan 13, 2022
@chenrui333 chenrui333 merged commit b859f72 into runatlantis:master Jan 13, 2022
@chenrui333
Copy link
Member

Thanks @tim775!

@tim775 tim775 deleted the feature/post_workflow_hooks branch January 13, 2022 01:44
@alikhajeh1
Copy link

@nishkrishnan, @jamengual and @chenrui333 I just wanted to say thank you for shipping this as it simplified the Infracost integration that we shipped today. It enabled 1 cost estimate comment to be shown for multiple Terraform dirs/workspaces 🎉

@jamengual
Copy link
Contributor

I'm glad it worked out, thanks for the contribution.

krrrr38 pushed a commit to krrrr38/atlantis that referenced this pull request Dec 16, 2022
* Add post-workflow hooks

* docs: Add cost estimation as post workflow use case

Co-authored-by: Gerald Barker <[email protected]>
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.

6 participants