Skip to content

Commit

Permalink
fix(continuous-integration): disable NX local cache check
Browse files Browse the repository at this point in the history
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
  • Loading branch information
neilime committed Mar 19, 2024
1 parent 1ccfed6 commit b9f3275
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 91 deletions.
84 changes: 9 additions & 75 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,14 @@ jobs:

- id: setup-node
uses: ./self-workflow/actions/setup-node

- id: has-installed-dependencies
uses: ./self-workflow/actions/has-installed-dependencies
with:
dependencies: |
dependencies-cache: |
nx
prettier
- name: ♻️ NX cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).nx == true
uses: actions/cache@v4.0.1
with:
path: node_modules/.cache/nx
key: ${{ runner.os }}-cache-nx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-nx-
- name: ♻️ Prettier cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).prettier == true
uses: actions/cache@v4.0.1
with:
path: node_modules/.cache/prettier
key: ${{ runner.os }}-cache-prettier-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-prettier-
- run: ${{ steps.setup-node.outputs.run-script-command }} lint
env:
NX_REJECT_UNKNOWN_LOCAL_CACHE: "0"

build:
name: 🏗️ Build
Expand All @@ -213,44 +194,12 @@ jobs:

- id: setup-node
uses: ./self-workflow/actions/setup-node

- id: has-installed-dependencies
uses: ./self-workflow/actions/has-installed-dependencies
with:
dependencies: |
dependencies-cache: |
nx
gatsby
storybook
- name: ♻️ NX cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).nx == true
uses: actions/cache@v4.0.1
with:
path: .nx/cache
key: ${{ runner.os }}-cache-nx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-nx-
- name: ♻️ Gatsby cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).gatsby == true
uses: actions/cache@v4.0.1
with:
path: |
.cache
public
key: ${{ runner.os }}-cache-gatsby-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-gatsby-
- name: ♻️ Storybook cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).storybook == true
uses: actions/cache@v4.0.1
with:
path: node_modules/.cache/storybook
key: ${{ runner.os }}-cache-storybook-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-storybook-
- run: |
BUILD_COMMANDS="${{ needs.setup.outputs.build-commands }}"
Expand All @@ -266,6 +215,8 @@ jobs:
echo -e "\n - Running $COMMAND"
${{ steps.setup-node.outputs.run-script-command }} "$COMMAND"
done
env:
NX_REJECT_UNKNOWN_LOCAL_CACHE: "0"
- if: needs.setup.outputs.build-artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -304,32 +255,15 @@ jobs:

- id: setup-node
uses: ./self-workflow/actions/setup-node

- id: has-installed-dependencies
uses: ./self-workflow/actions/has-installed-dependencies
with:
dependencies: |
dependencies-cache: |
nx
jest
- name: ♻️ Get Jest cache dir
id: jest-cache-dir-path
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).jest == true
run: |
JEST_CACHE_DIR=$(${{ steps.setup-node.outputs.run-script-command }} jest --showConfig | grep -oP '(?<="cacheDirectory": ")[^"]+(?=")')
echo "dir=$JEST_CACHE_DIR" >> "$GITHUB_OUTPUT"
- name: ♻️ Test cache
if: steps.jest-cache-dir-path.outputs.dir
uses: actions/cache@v4.0.1
with:
path: ${{ steps.jest-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-test-${{ github.sha }}
restore-keys: |
${{ runner.os }}-test-
- run: ${{ steps.setup-node.outputs.run-script-command }} test:ci
env:
CI: "true"
NX_REJECT_UNKNOWN_LOCAL_CACHE: "0"

- name: 📊 Code coverage
if: inputs.coverage == 'codecov'
Expand Down
36 changes: 36 additions & 0 deletions actions/dependencies-cache/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!-- start title -->

# GitHub Action: Dependencies cache

<!-- end title -->
<!-- start description -->

Action to setup dependencies cache managment.

<!-- end description -->
<!-- start contents -->
<!-- end contents -->
<!-- start usage -->

```yaml
- uses: hoverkraft-tech/ci-github-nodejs/actions/dependencies-cache@0.3.0
with:
dependencies: |
nx
jest
```
<!-- end usage -->
<!-- start inputs -->
## Inputs
| **Input** | **Description** | **Default** | **Required** |
| ----------------------------- | ----------------------------------------------------------- | ----------- | ------------ |
| **<code>dependencies</code>** | List of dependencies for which the cache should be managed. | | **true** |
<!-- end inputs -->
<!-- start outputs -->
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
85 changes: 85 additions & 0 deletions actions/dependencies-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: "Dependencies cache"
description: "Action to setup dependencies cache managment."
author: Hoverkraft
branding:
icon: archive
color: gray-dark

inputs:
dependencies:
description: "List of dependencies for which the cache should be managed."
required: true

runs:
using: "composite"
steps:
- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: mkdir -p ./self-dependencies-cache-action/ && cp -r $GITHUB_ACTION_PATH/../* ./self-dependencies-cache-action/

- id: has-installed-dependencies
if: inputs.dependencies != ''
uses: ./self-dependencies-cache-action/has-installed-dependencies
with:
dependencies: ${{ inputs.dependencies }}

- name: ♻️ NX cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).nx == true
uses: actions/cache@v4.0.1
with:
path: node_modules/.cache/nx
key: ${{ runner.os }}-cache-nx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-nx-
- name: ♻️ Prettier cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).prettier == true
uses: actions/cache@v4.0.1
with:
path: node_modules/.cache/prettier
key: ${{ runner.os }}-cache-prettier-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-prettier-
- name: ♻️ Gatsby cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).gatsby == true
uses: actions/cache@v4.0.1
with:
path: |
.cache
public
key: ${{ runner.os }}-cache-gatsby-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-gatsby-
- name: ♻️ Storybook cache
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).storybook == true
uses: actions/cache@v4.0.1
with:
path: node_modules/.cache/storybook
key: ${{ runner.os }}-cache-storybook-${{ github.sha }}
restore-keys: |
${{ runner.os }}-cache-storybook-
- name: ♻️ Get Jest cache dir
id: jest-cache-dir-path
if: fromJson(steps.has-installed-dependencies.outputs.installed-dependencies).jest == true
shell: bash
run: |
JEST_CACHE_DIR=$(${{ steps.setup-node.outputs.run-script-command }} jest --showConfig | grep -oP '(?<="cacheDirectory": ")[^"]+(?=")')
echo "dir=$JEST_CACHE_DIR" >> "$GITHUB_OUTPUT"
- name: ♻️ Test cache
if: steps.jest-cache-dir-path.outputs.dir
uses: actions/cache@v4.0.1
with:
path: ${{ steps.jest-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-test-${{ github.sha }}
restore-keys: |
${{ runner.os }}-test-
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
- shell: bash
if: always()
run: |
rm -fr ./self-dependencies-cache-action
10 changes: 7 additions & 3 deletions actions/has-installed-dependencies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ Action to check if dependencies have been installed according to the package man
<!-- end usage -->
<!-- start inputs -->
## Inputs
| **Input** | **Description** | **Default** | **Required** |
| ----------------------------- | -------------------------- | ----------- | ------------ |
| **<code>dependencies</code>** | The dependencies to check. | | **true** |
<!-- end inputs -->
<!-- start outputs -->
| \***\*Output\*\*** | \***\*Description\*\*** | \***\*Default\*\*** | \***\*Required\*\*** |
| ----------------------------------- | ----------------------------------------------------------------------------- | ------------------- | -------------------- |
| <code>installed-dependencies</code> | A map of dependencies and the status weither they have been installed or not. | undefined | undefined |
## Outputs
| **Output** | **Description** | **Default** | **Required** |
| ----------------------------------- | ----------------------------------------------------------------------------- | ----------- | ------------ |
| <code>installed-dependencies</code> | A map of dependencies and the status weither they have been installed or not. | undefined | undefined |
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
Expand Down
6 changes: 0 additions & 6 deletions actions/setup-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@ Action to setup NodeJS and install dependencies according to the package manager

```yaml
- uses: hoverkraft-tech/ci-github-nodejs/actions/setup-node@v0.1.0
with:
```
<!-- end usage -->
<!-- start inputs -->
<!-- end inputs -->
<!-- start outputs -->
| \***\*Output\*\*** | \***\*Description\*\*** | \***\*Default\*\*** | \***\*Required\*\*** |
| ------------------------------- | ---------------------------------------------------- | ------------------- | -------------------- |
| <code>run-script-command</code> | The command to run a script in the package.json file | undefined | undefined |
<!-- end outputs -->
<!-- start [.github/ghadocs/examples/] -->
<!-- end [.github/ghadocs/examples/] -->
26 changes: 19 additions & 7 deletions actions/setup-node/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ branding:
icon: settings
color: gray-dark

inputs:
dependencies-cache:
description: "List of dependencies for which the cache should be managed"
required: false
default: ""

outputs:
run-script-command:
description: "The command to run a script in the package.json file"
Expand All @@ -14,16 +20,11 @@ runs:
steps:
- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: mkdir -p ./self-actions/ && cp -r $GITHUB_ACTION_PATH/../* ./self-actions/
run: mkdir -p ./self-setup-node-action/ && cp -r $GITHUB_ACTION_PATH/../* ./self-setup-node-action/

- id: get-package-manager
if: inputs.package-manager == ''
uses: ./self-actions/get-package-manager

- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: |
rm -fr ./self-actions
uses: ./self-setup-node-action/get-package-manager

- id: prepare-variables
shell: bash
Expand Down Expand Up @@ -60,3 +61,14 @@ runs:

- shell: bash
run: ${{ steps.prepare-variables.outputs.install-command }}

- if: inputs.dependencies-cache != ''
uses: ./self-setup-node-action/dependencies-cache
with:
dependencies: ${{ inputs.dependencies-cache }}

# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
- shell: bash
if: always()
run: |
rm -fr ./self-setup-node-action

0 comments on commit b9f3275

Please sign in to comment.