|
1 | | -name: 'NPM Setup' |
2 | | -description: 'Sets up Node.js and installs NPM dependencies with caching' |
| 1 | +name: "NPM Setup" |
| 2 | +description: "Sets up Node.js and installs NPM dependencies with caching" |
3 | 3 |
|
4 | 4 | inputs: |
5 | 5 | runner: |
6 | | - description: 'Runner to use' |
| 6 | + description: "Runner to use" |
7 | 7 | required: true |
8 | 8 | node-version: |
9 | | - description: 'Node.js version to use' |
| 9 | + description: "Node.js version to use" |
10 | 10 | required: true |
11 | 11 | workspace: |
12 | | - description: 'Key for the cache' |
| 12 | + description: "Key for the cache" |
13 | 13 | required: true |
14 | 14 |
|
15 | 15 | outputs: |
16 | 16 | workspace_path: |
17 | 17 | description: "Full path to the workspace directory" |
18 | 18 | value: ${{ steps.set-env.outputs.workspace_path }} |
19 | | - |
| 19 | + |
20 | 20 | runs: |
21 | 21 | using: "composite" |
22 | 22 | steps: |
23 | | - - name: Install NodeJS ${{ inputs.node-version }} |
24 | | - uses: actions/setup-node@v4 |
25 | | - with: |
26 | | - node-version: ${{ inputs.node-version }} |
27 | | - |
28 | | - - name: Set cache configuration |
29 | | - shell: bash |
30 | | - id: set-env |
31 | | - run: | |
32 | | - if [ "${{ inputs.workspace }}" = "testcontainers" ]; then |
33 | | - echo "CACHE_PATHS<<EOF" >> $GITHUB_ENV |
34 | | - echo "node_modules" >> $GITHUB_ENV |
35 | | - echo "packages/testcontainers/node_modules" >> $GITHUB_ENV |
36 | | - echo "EOF" >> $GITHUB_ENV |
37 | | - echo "WORKSPACE_PATH=packages/testcontainers" >> $GITHUB_ENV |
38 | | - echo "workspace_path=packages/testcontainers" >> "$GITHUB_OUTPUT" |
39 | | - else |
40 | | - echo "CACHE_PATHS<<EOF" >> $GITHUB_ENV |
41 | | - echo "node_modules" >> $GITHUB_ENV |
42 | | - echo "packages/testcontainers/node_modules" >> $GITHUB_ENV |
43 | | - echo "packages/modules/${{ inputs.workspace }}/node_modules" >> $GITHUB_ENV |
44 | | - echo "EOF" >> $GITHUB_ENV |
45 | | - echo "WORKSPACE_PATH=packages/modules/${{ inputs.workspace }}" >> $GITHUB_ENV |
46 | | - echo "workspace_path=packages/modules/${{ inputs.workspace }}" >> "$GITHUB_OUTPUT" |
47 | | - fi |
48 | | - |
49 | | - - uses: actions/cache/restore@v4 |
50 | | - id: npm-cache |
51 | | - with: |
52 | | - path: ${{ env.CACHE_PATHS }} |
53 | | - key: ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}-${{ hashFiles('package-lock.json', 'packages/testcontainers/package-lock.json', format('packages/modules/{0}/package-lock.json', inputs.workspace)) }} |
54 | | - restore-keys: | |
55 | | - ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}- |
56 | | - ${{ inputs.runner }}-node-${{ inputs.node-version }}- |
| 23 | + - name: Install NodeJS ${{ inputs.node-version }} |
| 24 | + uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: ${{ inputs.node-version }} |
| 27 | + |
| 28 | + - name: Set cache configuration |
| 29 | + shell: bash |
| 30 | + id: set-env |
| 31 | + run: | |
| 32 | + if [ "${{ inputs.workspace }}" = "testcontainers" ]; then |
| 33 | + echo "CACHE_PATHS<<EOF" >> $GITHUB_ENV |
| 34 | + echo "node_modules" >> $GITHUB_ENV |
| 35 | + echo "packages/testcontainers/node_modules" >> $GITHUB_ENV |
| 36 | + echo "EOF" >> $GITHUB_ENV |
| 37 | + echo "WORKSPACE_PATH=packages/testcontainers" >> $GITHUB_ENV |
| 38 | + echo "workspace_path=packages/testcontainers" >> "$GITHUB_OUTPUT" |
| 39 | + else |
| 40 | + echo "CACHE_PATHS<<EOF" >> $GITHUB_ENV |
| 41 | + echo "node_modules" >> $GITHUB_ENV |
| 42 | + echo "packages/testcontainers/node_modules" >> $GITHUB_ENV |
| 43 | + echo "packages/modules/${{ inputs.workspace }}/node_modules" >> $GITHUB_ENV |
| 44 | + echo "EOF" >> $GITHUB_ENV |
| 45 | + echo "WORKSPACE_PATH=packages/modules/${{ inputs.workspace }}" >> $GITHUB_ENV |
| 46 | + echo "workspace_path=packages/modules/${{ inputs.workspace }}" >> "$GITHUB_OUTPUT" |
| 47 | + fi |
| 48 | +
|
| 49 | + - uses: actions/cache/restore@v4 |
| 50 | + id: npm-cache |
| 51 | + with: |
| 52 | + path: ${{ env.CACHE_PATHS }} |
| 53 | + key: ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}-${{ hashFiles('package-lock.json', 'packages/testcontainers/package-lock.json', format('packages/modules/{0}/package-lock.json', inputs.workspace)) }} |
| 54 | + restore-keys: | |
| 55 | + ${{ inputs.runner }}-node-${{ inputs.node-version }}-${{ inputs.workspace }}- |
| 56 | + ${{ inputs.runner }}-node-${{ inputs.node-version }}- |
57 | 57 |
|
58 | | - - name: Install dependencies |
59 | | - if: steps.npm-cache.outputs.cache-hit != 'true' |
60 | | - shell: bash |
61 | | - run: npm ci --workspace ${{ env.WORKSPACE_PATH }} --include-workspace-root |
| 58 | + - name: Install dependencies |
| 59 | + if: steps.npm-cache.outputs.cache-hit != 'true' |
| 60 | + shell: bash |
| 61 | + run: npm ci --workspace ${{ env.WORKSPACE_PATH }} --include-workspace-root |
62 | 62 |
|
63 | | - - name: Cache npm |
64 | | - if: steps.npm-cache.outputs.cache-hit != 'true' |
65 | | - uses: actions/cache/save@v4 |
66 | | - with: |
67 | | - path: ${{ env.CACHE_PATHS }} |
68 | | - key: ${{ steps.npm-cache.outputs.cache-primary-key }} |
| 63 | + - name: Cache npm |
| 64 | + if: steps.npm-cache.outputs.cache-hit != 'true' |
| 65 | + uses: actions/cache/save@v4 |
| 66 | + with: |
| 67 | + path: ${{ env.CACHE_PATHS }} |
| 68 | + key: ${{ steps.npm-cache.outputs.cache-primary-key }} |
0 commit comments