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

Setup Nx distrubuted cache #2514

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
29 changes: 29 additions & 0 deletions .github/actions/build-and-test-with-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'Build'
description: 'This action builds this project with remote s3 cache.'
inputs:
aws-region:
description: 'The AWS region to use for the cache.'
required: true
default: 'us-west-2'
cache-role-to-assume:
description: 'The ARN of the role to assume to access the cache.'
required: true
cache-bucket:
description: 'The name of the S3 bucket to use for the cache.'
required: true
runs:
using: 'composite'
steps:
- name: Build with cache
uses: ./.github/actions/build-with-cache
with:
aws-region: ${{ inputs.aws-region }}
cache-role-to-assume: ${{ inputs.cache-role-to-assume }}
cache-bucket: ${{ inputs.cache-bucket }}

- name: Test
shell: bash
run: NODE_ENV=production yarn build --parallel=3
env:
NXCACHE_S3_REGION: ${{ inputs.aws-region }}
NXCACHE_S3_BUCKET: ${{ inputs.cache-bucket }}
28 changes: 28 additions & 0 deletions .github/actions/build-with-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 'Build'
description: 'This action builds this project with remote s3 cache.'
inputs:
aws-region:
description: 'The AWS region to use for the cache.'
required: true
default: 'us-west-2'
cache-role-to-assume:
description: 'The ARN of the role to assume to access the cache.'
required: true
cache-bucket:
description: 'The name of the S3 bucket to use for the cache.'
required: true
runs:
using: 'composite'
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ inputs.aws-region }}
role-to-assume: ${{ inputs.cache-role-to-assume }}

- name: Build
shell: bash
run: NODE_ENV=production yarn build --parallel=3
env:
NXCACHE_S3_REGION: ${{ inputs.aws-region }}
NXCACHE_S3_BUCKET: ${{ inputs.cache-bucket }}
30 changes: 21 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- main
pull_request:

permissions:
id-token: write

jobs:
test:
name: Unit tests
Expand Down Expand Up @@ -39,11 +42,12 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Build (Affected)
run: NODE_ENV=production yarn nx affected -t build --parallel=3 # nx recipe

- name: Test (Affected)
run: yarn nx affected -t test --parallel=3 --coverage # nx recipe
- name: Build
uses: ./.github/actions/build-and-test-with-cache
with:
aws-region: ${{ secrets.CACHE_AWS_REGION }}
cache-role-to-assume: ${{ secrets.CACHE_ROLE_TO_ASSUME }}
cache-bucket: ${{ secrets.CACHE_BUCKET }}

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
Expand Down Expand Up @@ -78,8 +82,12 @@ jobs:
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Build # TODO: This monorepo should be refactored so packages can be linted invidually. "affected" will not work ATM.
run: NODE_ENV=production yarn build # nx recipe
- name: Build
uses: ./.github/actions/build-with-cache
with:
aws-region: ${{ secrets.CACHE_AWS_REGION }}
cache-role-to-assume: ${{ secrets.CACHE_ROLE_TO_ASSUME }}
cache-bucket: ${{ secrets.CACHE_BUCKET }}

- name: Lint
env:
Expand Down Expand Up @@ -115,8 +123,12 @@ jobs:
- name: Assert yarn.lock is up-to-date
run: bash scripts/assert-lockfile-updated.sh

- name: Build # TODO: This monorepo should be refactored so packages can be linted invidually. "affected" will not work ATM.
run: NODE_ENV=production yarn build # nx recipe
- name: Build
uses: ./.github/actions/build-with-cache
with:
aws-region: ${{ secrets.CACHE_AWS_REGION }}
cache-role-to-assume: ${{ secrets.CACHE_ROLE_TO_ASSUME }}
cache-bucket: ${{ secrets.CACHE_BUCKET }}

- name: Validate Definitions
run: yarn validate
Expand Down
36 changes: 0 additions & 36 deletions .github/workflows/ext.yml

This file was deleted.

8 changes: 7 additions & 1 deletion .github/workflows/publish-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:

jobs:
build-and-publish:
permissions:
id-token: write
env:
HUSKY: 0
NX_DISABLE_DB: true
Expand Down Expand Up @@ -36,7 +38,11 @@ jobs:
run: yarn install --frozen-lockfile

- name: Build
run: NODE_ENV=production yarn build
uses: ./.github/actions/build-with-cache
with:
aws-region: ${{ secrets.CACHE_AWS_REGION }}
cache-role-to-assume: ${{ secrets.CACHE_ROLE_TO_ASSUME }}
cache-bucket: ${{ secrets.CACHE_BUCKET }}

- name: Fetch Latest Tags
run: |
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:

jobs:
build-and-publish:
permissions:
id-token: write
env:
HUSKY: 0
NX_DISABLE_DB: true
Expand All @@ -37,7 +39,11 @@ jobs:
run: yarn install --frozen-lockfile

- name: Build
run: NODE_ENV=production yarn build
uses: ./.github/actions/build-with-cache
with:
aws-region: ${{ secrets.CACHE_AWS_REGION }}
cache-role-to-assume: ${{ secrets.CACHE_ROLE_TO_ASSUME }}
cache-bucket: ${{ secrets.CACHE_BUCKET }}

- name: Fetch Latest Tags
run: |
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/version-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
permissions:
pull-requests: write
contents: write
id-token: write
steps:
- name: Echo Inputs
run: |
Expand Down Expand Up @@ -64,7 +65,11 @@ jobs:
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Build
run: NODE_ENV=production yarn build
uses: ./.github/actions/build-with-cache
with:
aws-region: ${{ secrets.CACHE_AWS_REGION }}
cache-role-to-assume: ${{ secrets.CACHE_ROLE_TO_ASSUME }}
cache-bucket: ${{ secrets.CACHE_BUCKET }}

- name: Version Packages
run: yarn lerna version minor --yes --allow-branch ${{ github.event.inputs.branch }} --no-git-tag-version --no-commit-hooks --no-private
Expand Down
14 changes: 14 additions & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@
"inputs": ["default", "^production"],
"dependsOn": ["build"],
"cache": true
},
"lint": {
"inputs": ["default"],
"dependsOn": ["build"],
"cache": true
}
},
"tasksRunnerOptions": {
"default": {
"runner": "@pellegrims/nx-remotecache-s3",
"options": {
"cacheableOperations": ["build", "test", "lint"],
"forcePathStyle": true
}
}
},
"defaultBase": "main"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"devDependencies": {
"@peculiar/webcrypto": "^1.2.3",
"@pellegrims/nx-remotecache-s3": "^8.0.0",
"@types/aws4": "^1.11.2",
"@types/chance": "^1.1.3",
"@types/cors": "^2.8.12",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"@types/json-schema": "^7.0.7",
"@types/lodash": "^4.14.175",
"@types/mustache": "^4.1.0",
"@types/node": "^14.0.0",
"@types/prompts": "^2.0.10",
"@types/rimraf": "^3.0.2",
"@types/to-title-case": "^1.0.0",
Expand Down
Loading
Loading