From b9f3275fbcc72b01e43cd7c41986b230b838536d Mon Sep 17 00:00:00 2001 From: Emilien Escalle Date: Tue, 19 Mar 2024 11:44:24 +0100 Subject: [PATCH] fix(continuous-integration): disable NX local cache check Signed-off-by: Emilien Escalle --- .github/workflows/continuous-integration.yml | 84 +++---------------- actions/dependencies-cache/README.md | 36 +++++++++ actions/dependencies-cache/action.yml | 85 ++++++++++++++++++++ actions/has-installed-dependencies/README.md | 10 ++- actions/setup-node/README.md | 6 -- actions/setup-node/action.yml | 26 ++++-- 6 files changed, 156 insertions(+), 91 deletions(-) create mode 100644 actions/dependencies-cache/README.md create mode 100644 actions/dependencies-cache/action.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9c91b52..443f977 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -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 @@ -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 }}" @@ -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 @@ -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' diff --git a/actions/dependencies-cache/README.md b/actions/dependencies-cache/README.md new file mode 100644 index 0000000..1be3f84 --- /dev/null +++ b/actions/dependencies-cache/README.md @@ -0,0 +1,36 @@ + + +# GitHub Action: Dependencies cache + + + + +Action to setup dependencies cache managment. + + + + + + +```yaml +- uses: hoverkraft-tech/ci-github-nodejs/actions/dependencies-cache@0.3.0 + with: + dependencies: | + nx + jest +``` + + + + +## Inputs + +| **Input** | **Description** | **Default** | **Required** | +| ----------------------------- | ----------------------------------------------------------- | ----------- | ------------ | +| **dependencies** | List of dependencies for which the cache should be managed. | | **true** | + + + + + + diff --git a/actions/dependencies-cache/action.yml b/actions/dependencies-cache/action.yml new file mode 100644 index 0000000..197063b --- /dev/null +++ b/actions/dependencies-cache/action.yml @@ -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 diff --git a/actions/has-installed-dependencies/README.md b/actions/has-installed-dependencies/README.md index 1be4689..f06e2e8 100644 --- a/actions/has-installed-dependencies/README.md +++ b/actions/has-installed-dependencies/README.md @@ -22,6 +22,8 @@ Action to check if dependencies have been installed according to the package man +## Inputs + | **Input** | **Description** | **Default** | **Required** | | ----------------------------- | -------------------------- | ----------- | ------------ | | **dependencies** | The dependencies to check. | | **true** | @@ -29,9 +31,11 @@ Action to check if dependencies have been installed according to the package man -| \***\*Output\*\*** | \***\*Description\*\*** | \***\*Default\*\*** | \***\*Required\*\*** | -| ----------------------------------- | ----------------------------------------------------------------------------- | ------------------- | -------------------- | -| installed-dependencies | A map of dependencies and the status weither they have been installed or not. | undefined | undefined | +## Outputs + +| **Output** | **Description** | **Default** | **Required** | +| ----------------------------------- | ----------------------------------------------------------------------------- | ----------- | ------------ | +| installed-dependencies | A map of dependencies and the status weither they have been installed or not. | undefined | undefined | diff --git a/actions/setup-node/README.md b/actions/setup-node/README.md index 5269101..8b18634 100644 --- a/actions/setup-node/README.md +++ b/actions/setup-node/README.md @@ -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: ``` - -| \***\*Output\*\*** | \***\*Description\*\*** | \***\*Default\*\*** | \***\*Required\*\*** | -| ------------------------------- | ---------------------------------------------------- | ------------------- | -------------------- | -| run-script-command | The command to run a script in the package.json file | undefined | undefined | - diff --git a/actions/setup-node/action.yml b/actions/setup-node/action.yml index 7547136..c0fbf7b 100644 --- a/actions/setup-node/action.yml +++ b/actions/setup-node/action.yml @@ -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" @@ -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 @@ -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