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

[HOTFIX]: Add correct cache commands #962

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ The feature branch deploy process occurs whenever a developer opens a pull reque
2. `update-feature-branch.yml` - Ran whenever a commit is made to the branch for the PR, and conditionally deploys each stack depending on changes made
3. `clean-feature-branch.yml` - Ran whenever a PR is merged or closed; deletes all of the infrastructure for the feature branch

### `deploy-feature-branch.yml`

This workflow file is only called when a PR is first opened, or re-opened after being closed. The stacks are deployed sequentially, this is based on the dependencies for each. The order is:

1. Queue stack
2. Worker stack
3. Webhook stack

The queues are only deployed once, as they almost always don't need to be updated. The worker and webhook stacks are the ones that will be updated to reflect code changes, so these will be a part of the `update-feature-branch.yml` workflow.

One thing to note: The webhook stack depends on the worker stack, but this doesn't mean they always need to be deployed sequentially every time, only for the initial deploy. This is because the webhook stack's only dependency on the worker stack is the ECS cluster name associated with the worker stack. This value does not change, and so in the `update-feature-branch.yml` workflow, we are able to deploy these in parallel.

This workflow also will comment on the pull request when the initial feature branch deploy is successful, notifying the developer on how to use their provisioned infrastructure.

### `update-feature-branch.yml`

This workflow handles subsequent commits to the branch that a pull request is a part of. Depending on what changes are made, each stack is conditionally deployed so that only the necessary stacks are updated. In a recent update, these stacks are now deployed in parallel, and caching has been added to share `node_modules` between jobs, as they are the same for all jobs.

### `clean-feature-branch.yml`

As the name suggests, this workflow cleans up the feature branch infrastructure. As well as deleting the AWS resources associated with the feature branch, the GitHub Actions cache that is created in the `update-feature-branch.yml` file is also deleted.

### Bugs

Right now, there is a small bug with the `update-feature-branch.yml` workflow. This workflow conditionally deploys the various stacks depending on what files have changed from a commit. The issue is that the custom filter action compares the PR branch to master for every workflow run. This means that if you make a change to `src/app.ts` in the first commit, but only make changes to files in the `api/` directory in subsequent commits, it will still run the deploy for the worker.

For the `deploy-feature-branch.yml` workflow, this will not re-run if the first build when opening a PR fails. This means that subsequent builds of the `update-feature-branch.yml` workflow will also fail. This is due to the fact that the SQS queues would not have been deployed. For now, the workaround is to close and re-open the PR. This will run the `deploy-feature-branch.yml` workflow.
4 changes: 4 additions & 0 deletions .github/workflows/clean-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ jobs:
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker \
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-queues \
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks
- name: Delete cache
run: gh cache delete ${{github.head_ref}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 9 additions & 1 deletion .github/workflows/deploy-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ jobs:
- name: Get Webhook URL
uses: mongodb/docs-worker-actions/comment-pr@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cache root node_modules
id: cache-root
uses: actions/cache@v3
with:
path: |
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
4 changes: 1 addition & 3 deletions .github/workflows/update-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- 'package-lock.json'
- 'cdk-infra/package-lock.json'
- name: Install dependencies
if: steps.filter.outputs.dependencies == 'true' || (github.event_name == 'pull_request' && github.event.action == 'opened')
if: steps.filter.outputs.dependencies == 'true'
run: |
npm ci
cd cdk-infra/
Expand Down Expand Up @@ -111,8 +111,6 @@ jobs:
cd cdk-infra/
npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \
auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-worker


build-cache-updater:
needs: prep-build
runs-on: ubuntu-latest
Expand Down
Loading