new units cache strategy

This commit is contained in:
Marco Carrozzo
2023-01-19 18:00:31 +01:00
parent d784baac56
commit 77d8b46cdd
5 changed files with 92 additions and 33 deletions
@@ -7,7 +7,16 @@ inputs:
required: false required: false
type: string type: string
default: 'dist nxcache' default: 'dist nxcache'
persistent-packages:
description: 'cache key'
required: false
type: string
default: 'nxcache'
cache-key-suffix:
description: 'cache key suffix'
required: false
type: string
default: ''
runs: runs:
using: "composite" using: "composite"
steps: steps:
@@ -22,6 +31,20 @@ runs:
du -h $i.tar.gz du -h $i.tar.gz
time tar xzf $i.tar.gz time tar xzf $i.tar.gz
done done
- name: download and extract persistent artifacts from s3
shell: bash
env:
REMOTE_PATH: "alfresco-ng2-components/build-cache/${{ hashFiles('**/package-lock.json') }}"
run: |
if [ -n "${{ inputs.cache-key-suffix }}" ]; then
REMOTE_PATH="${REMOTE_PATH}-${{ inputs.cache-key-suffix }}"
fi
packages=( $(echo ${{ inputs.persistent-packages }}) )
for i in "${packages[@]}"; do
time aws s3 cp --no-progress s3://${S3_BUILD_BUCKET_SHORT_NAME}/${REMOTE_PATH}/$i.tar.gz $i.tar.gz
du -h $i.tar.gz
time tar xzf $i.tar.gz
done
- name: show files - name: show files
shell: bash shell: bash
run: | run: |
+4 -4
View File
@@ -6,12 +6,12 @@ inputs:
required: false required: false
type: string type: string
default: '' default: ''
enable-global-nx-cache: use-gh-nx-cache:
description: 'enable caching' description: 'enable caching'
required: false required: false
type: boolean type: boolean
default: 'true' default: 'true'
enable-global-node-modules-cache: use-gh-node-modules-cache:
description: 'enable caching for node modules' description: 'enable caching for node modules'
required: false required: false
type: boolean type: boolean
@@ -36,7 +36,7 @@ runs:
# CACHE # CACHE
- name: NX cache - name: NX cache
id: nx-cache id: nx-cache
if: ${{ inputs.enable-global-nx-cache == 'true' }} if: ${{ inputs.use-gh-nx-cache == 'true' }}
uses: actions/cache@v3 uses: actions/cache@v3
env: env:
cache-name: nx-cache cache-name: nx-cache
@@ -49,7 +49,7 @@ runs:
nxcache- nxcache-
- name: Node Modules cache - name: Node Modules cache
id: node-modules-cache id: node-modules-cache
if: ${{ inputs.enable-global-node-modules-cache == 'true' }} if: ${{ inputs.use-gh-node-modules-cache == 'true' }}
uses: actions/cache@v3 uses: actions/cache@v3
env: env:
cache-name: node-modules-cache cache-name: node-modules-cache
@@ -5,14 +5,24 @@ inputs:
description: 'packages to cache' description: 'packages to cache'
required: false required: false
type: boolean type: boolean
default: 'dist nxcache' default: 'dist'
persistent-packages:
description: 'cache key'
required: false
type: string
default: 'nxcache'
cache-key-suffix:
description: 'cache key suffix'
required: false
type: string
default: ''
runs: runs:
using: "composite" using: "composite"
steps: steps:
- name: tar and upload artifacts - name: tar and upload artifacts
shell: bash shell: bash
env: env:
REMOTE_PATH: "alfresco-ng2-components/build-cache/${{ github.run_id }}" REMOTE_PATH: "alfresco-ng2-components/build-cache/${{ github.run_id }}"
run: | run: |
packages=( $(echo ${{ inputs.packages }}) ) packages=( $(echo ${{ inputs.packages }}) )
for i in "${packages[@]}"; do for i in "${packages[@]}"; do
@@ -20,5 +30,20 @@ runs:
du -h $i.tar.gz du -h $i.tar.gz
time aws s3 cp --no-progress $i.tar.gz s3://${S3_BUILD_BUCKET_SHORT_NAME}/${REMOTE_PATH}/$i.tar.gz time aws s3 cp --no-progress $i.tar.gz s3://${S3_BUILD_BUCKET_SHORT_NAME}/${REMOTE_PATH}/$i.tar.gz
done done
- name: tar and upload persistent artifacts
shell: bash
env:
REMOTE_PATH: "alfresco-ng2-components/build-cache/${{ hashFiles('**/package-lock.json') }} }}"
run: |
if [ -n "${{ inputs.cache-key-suffix }}" ]; then
REMOTE_PATH="${REMOTE_PATH}-${{ inputs.cache-key-suffix }}"
fi
packages=( $(echo ${{ inputs.persistent-packages }}) )
for i in "${packages[@]}"; do
time tar czf $i.tar.gz $i
du -h $i.tar.gz
echo "pushing persistent cache"
time aws s3 cp --no-progress $i.tar.gz s3://${S3_BUILD_BUCKET_SHORT_NAME}/${REMOTE_PATH}/$i.tar.gz
done
+29 -18
View File
@@ -120,8 +120,8 @@ jobs:
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
id: setup id: setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: true use-gh-node-modules-cache: true
- name: run ci - name: run ci
if: steps.setup.outputs.cache-hit != 'true' if: steps.setup.outputs.cache-hit != 'true'
run: npm ci run: npm ci
@@ -168,13 +168,20 @@ jobs:
fetch-depth: 0 # Fetch all history for all tags and branches fetch-depth: 0 # Fetch all history for all tags and branches
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: true use-gh-nx-cache: false
enable-global-node-modules-cache: true use-gh-node-modules-cache: true
cache-key-suffix: unit-tests-${{ matrix.unit-tests.name }} cache-key-suffix: unit-tests-${{ matrix.unit-tests.name }}
- uses: ./.github/actions/download-cache-and-artifacts
with:
persistent-packages: 'nxcache'
cache-key-suffix: ${{ matrix.unit-tests.name }}
- name: Run unit tests - name: Run unit tests
run: | run: |
/usr/bin/xvfb-run --auto-servernum nx affected:test $NX_CALCULATION_FLAGS --exclude=${{ matrix.unit-tests.exclude }} /usr/bin/xvfb-run --auto-servernum nx affected:test $NX_CALCULATION_FLAGS --exclude=${{ matrix.unit-tests.exclude }}
- uses: ./.github/actions/upload-cache-and-artifacts
with:
persistent-packages: 'nxcache'
cache-key-suffix: ${{ matrix.unit-tests.name }}
lint: lint:
# long timeout required when cache has to be recreated # long timeout required when cache has to be recreated
timeout-minutes: 30 timeout-minutes: 30
@@ -188,14 +195,17 @@ jobs:
fetch-depth: 0 # Fetch all history for all tags and branches fetch-depth: 0 # Fetch all history for all tags and branches
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: true use-gh-nx-cache: false
enable-global-node-modules-cache: true use-gh-node-modules-cache: true
cache-key-suffix: lint cache-key-suffix: lint
- uses: ./.github/actions/download-cache-and-artifacts - uses: ./.github/actions/download-cache-and-artifacts
with: with:
packages: 'node_modules' packages: 'node_modules'
persistent-packages: 'nxcache'
- run: nx affected --target=lint $NX_CALCULATION_FLAGS - run: nx affected --target=lint $NX_CALCULATION_FLAGS
- uses: ./.github/actions/upload-cache-and-artifacts
with:
persistent-packages: 'nxcache'
build-libs: build-libs:
# long timeout required when cache has to be recreated # long timeout required when cache has to be recreated
timeout-minutes: 30 timeout-minutes: 30
@@ -209,18 +219,19 @@ jobs:
fetch-depth: 0 # Fetch all history for all tags and branches fetch-depth: 0 # Fetch all history for all tags and branches
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: true use-gh-nx-cache: false
enable-global-node-modules-cache: true use-gh-node-modules-cache: true
cache-key-suffix: build-libs cache-key-suffix: build-libs
# - uses: ./.github/actions/download-cache-and-artifacts - uses: ./.github/actions/download-cache-and-artifacts
# with: with:
# packages: 'node_modules' persistent-packages: 'nxcache'
- run: nx affected:build $NX_CALCULATION_FLAGS --prod - run: nx affected:build $NX_CALCULATION_FLAGS --prod
- run: nx build demoshell --configuration production - run: nx build demoshell --configuration production
- run: nx affected --target=build-storybook $NX_CALCULATION_FLAGS --configuration ci - run: nx affected --target=build-storybook $NX_CALCULATION_FLAGS --configuration ci
- uses: ./.github/actions/upload-cache-and-artifacts - uses: ./.github/actions/upload-cache-and-artifacts
with: with:
packages: 'dist node_modules' packages: 'dist node_modules'
persistent-packages: 'nxcache'
e2e-storybook: e2e-storybook:
timeout-minutes: 20 timeout-minutes: 20
@@ -234,8 +245,8 @@ jobs:
fetch-depth: 0 # Fetch all history for all fetch-depth: 0 # Fetch all history for all
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: false use-gh-node-modules-cache: false
- uses: ./.github/actions/download-cache-and-artifacts - uses: ./.github/actions/download-cache-and-artifacts
with: with:
packages: 'dist node_modules' packages: 'dist node_modules'
@@ -374,8 +385,8 @@ jobs:
fetch-depth: 0 # Fetch all history for all fetch-depth: 0 # Fetch all history for all
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: false use-gh-node-modules-cache: false
- uses: ./.github/actions/download-cache-and-artifacts - uses: ./.github/actions/download-cache-and-artifacts
with: with:
packages: 'dist node_modules' packages: 'dist node_modules'
+8 -8
View File
@@ -80,8 +80,8 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: false use-gh-node-modules-cache: false
- name: install - name: install
run: | run: |
npm ci npm ci
@@ -108,8 +108,8 @@ jobs:
dry-run-flag: ${{ inputs.dry-run-release }} dry-run-flag: ${{ inputs.dry-run-release }}
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: false use-gh-node-modules-cache: false
- uses: ./.github/actions/download-cache-and-artifacts - uses: ./.github/actions/download-cache-and-artifacts
with: with:
packages: 'dist nxcache node_modules' packages: 'dist nxcache node_modules'
@@ -136,8 +136,8 @@ jobs:
dry-run-flag: ${{ inputs.dry-run-release }} dry-run-flag: ${{ inputs.dry-run-release }}
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: false use-gh-node-modules-cache: false
act: ${{ inputs.dry-run-release }} act: ${{ inputs.dry-run-release }}
- uses: ./.github/actions/download-cache-and-artifacts - uses: ./.github/actions/download-cache-and-artifacts
with: with:
@@ -160,8 +160,8 @@ jobs:
fetch-depth: 0 fetch-depth: 0
- uses: ./.github/actions/setup - uses: ./.github/actions/setup
with: with:
enable-global-nx-cache: false use-gh-nx-cache: false
enable-global-node-modules-cache: false use-gh-node-modules-cache: false
- id: set-dryrun - id: set-dryrun
uses: ./.github/actions/enable-dryrun uses: ./.github/actions/enable-dryrun
with: with: