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: updated ci that is faster and better #684

Merged
merged 4 commits into from
Jul 18, 2022
Merged

Conversation

jakeyheath
Copy link
Contributor

@jakeyheath jakeyheath commented Jul 15, 2022

Summary

This PR updates the code that is generated to fogg_ci.yml for github actions. It has been tested in a few iterations in shared-infra. The following new features include:

  • auto fix terraform-docs and commit back to branch
  • auto fix fogg apply and commit back to branch
  • auto fix terraform fmt and commit back to branch
  • caching fogg apply using action/cache
  • only doing the above on envs/accounts/modules that have changed files
  • no more code generation; changed directories are collect dynamically and run in parallel
  • fewer bash scripting and more github actions (such as terraform-docs)
  • no more SSH keys in secrets; all code is downloaded using a github app credentials (github app's have finer grain access controls and are easier to manage at an org-wide level)
  • no more random ordering of steps based on fogg apply. should be the same fogg_ci.yml every time

Test Plan

  • Testing on shared-infra

References

In testing on shared-infra, this has been about 4 minutes faster than the previous iteration, per PR commit.

@jakeyheath jakeyheath requested a review from a team as a code owner July 15, 2022 23:31
- uses: actions/checkout@v2
- name: Set up Python 3.x
uses: actions/setup-python@v1
- name: Generate token
Copy link
Contributor Author

@jakeyheath jakeyheath Jul 16, 2022

Choose a reason for hiding this comment

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

generate a token using our github app to do sensitive things like clone repos instead of a SSH key

# can use this filter to decide whether or not to run linters or tests.
- uses: dorny/[email protected]
token: {{`${{ steps.generate_token.outputs.token }}`}}
- name: Cache Fogg
Copy link
Contributor Author

Choose a reason for hiding this comment

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

utilize ~/.fogg/cache

with:
add: -A
message: |
commit from fogg_ci -- ran fogg apply and pushed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if fogg apply has any changes, commit them back to the branch

- name: {{ $component.Dir }}
if: {{ "${{ steps.filter.outputs.terraform == 'true' }}" }}
changed:
- added|modified: 'terraform/**'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

find all changed files in terraform/* in the last commit

changed:
- added|modified: 'terraform/**'
- uses: actions/github-script@v6
id: changedDirs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

take the changed files and find the directories associated with their env/account/module folder

needs: find-changed-dirs
strategy:
matrix:
tfmodule: {{`${{ fromJson(needs.find-changed-dirs.outputs.allChanges) }}`}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for each changed dir...

- uses: actions/checkout@v3
with:
token: {{`${{ steps.generate_token.outputs.token }}`}}
- name: fix terraform docs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix the terraform docs and commit it back to branch

ref: {{`${{ github.event.pull_request.head.ref }}`}}
git-commit-message: |
commit from fogg_ci -- ran terraform-docs and pushed
- name: fix terraform fmt
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix terraform fmt and commit it back to the branch

add: -A
message: |
commit from fogg_ci -- ran terraform fmt and pushed
- name: tflint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also run tflint

@czimergebot czimergebot merged commit 3e78e17 into main Jul 18, 2022
@czimergebot czimergebot deleted the heathj/new-fogg-ci branch July 18, 2022 18:12
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.

3 participants