|
| 1 | +name: Setup CI |
| 2 | +description: Setup CI environment |
| 3 | + |
| 4 | +inputs: |
| 5 | + cache-build: |
| 6 | + description: 'Should cache the build' |
| 7 | + required: false |
| 8 | + default: 'true' |
| 9 | + cache-key-build: |
| 10 | + description: 'Cache key for the build' |
| 11 | + required: false |
| 12 | + default: '' |
| 13 | + cache-node-modules: |
| 14 | + description: 'Should cache node_modules' |
| 15 | + required: false |
| 16 | + default: 'true' |
| 17 | + cache-e2e-node-modules: |
| 18 | + description: 'Should cache node_modules for E2E' |
| 19 | + required: false |
| 20 | + default: 'true' |
| 21 | + cache-key-for-node-modules: |
| 22 | + description: 'Cache key for node_modules' |
| 23 | + required: false |
| 24 | + default: '' |
| 25 | + cache-key-for-e2e-node-modules: |
| 26 | + description: 'Cache key for E2E node_modules' |
| 27 | + required: false |
| 28 | + default: '' |
| 29 | + restore-build-cache: |
| 30 | + description: 'Should restore the build cache' |
| 31 | + required: false |
| 32 | + default: 'true' |
| 33 | + restore-node-modules-cache: |
| 34 | + description: 'Should restore the node_modules cache' |
| 35 | + required: false |
| 36 | + default: 'true' |
| 37 | + restore-e2e-node-modules-cache: |
| 38 | + description: 'Should restore the node_modules cache for E2E' |
| 39 | + required: false |
| 40 | + default: 'true' |
| 41 | + |
| 42 | +outputs: |
| 43 | + final-cache-key-build: |
| 44 | + description: 'The final build cache key' |
| 45 | + value: ${{ steps.determine-cache-key-build.outputs.final-cache-key-build }} |
| 46 | + |
| 47 | +runs: |
| 48 | + using: composite |
| 49 | + steps: |
| 50 | + - name: Determine build cache key |
| 51 | + id: determine-cache-key-build |
| 52 | + shell: bash |
| 53 | + env: |
| 54 | + FINAL_BUILD_CACHE_KEY: ${{ inputs.cache-key-build || format('build-cache-{0}-{1}', runner.os, hashFiles('yarn.lock', 'src/**/*', 'babel.config.cjs.cjs', 'babel.config.esm.cjs', 'package.json', 'tsconfig.output.types.json', 'tsconfig.partial.base.json', 'tsconfig.scope.src.json')) }} |
| 55 | + run: echo "final-cache-key-build=$(echo "$FINAL_BUILD_CACHE_KEY")" >> $GITHUB_OUTPUT |
| 56 | + |
| 57 | + - name: Determine node_modules cache key |
| 58 | + id: determine-cache-key-for-node-modules |
| 59 | + shell: bash |
| 60 | + env: |
| 61 | + FINAL_NODE_MODULES_CACHE_KEY: ${{ inputs.cache-key-for-node-modules || format('node-modules-cache-{0}-{1}', runner.os, hashFiles('yarn.lock')) }} |
| 62 | + run: echo "final-cache-key-for-node-modules=$(echo "$FINAL_NODE_MODULES_CACHE_KEY")" >> $GITHUB_OUTPUT |
| 63 | + |
| 64 | + - name: Determine node_modules cache key for E2E |
| 65 | + id: determine-cache-key-for-e2e-node-modules |
| 66 | + shell: bash |
| 67 | + env: |
| 68 | + FINAL_E2E_NODE_MODULES_CACHE_KEY: ${{ inputs.cache-key-for-e2e-node-modules || format('e2e-node-modules-cache-{0}-{1}', runner.os, hashFiles('e2e/yarn.lock')) }} |
| 69 | + run: echo "final-cache-key-for-e2e-node-modules=$(echo "$FINAL_E2E_NODE_MODULES_CACHE_KEY")" >> $GITHUB_OUTPUT |
| 70 | + |
| 71 | + - name: Setup Node.js LTS |
| 72 | + uses: actions/setup-node@v4 |
| 73 | + with: |
| 74 | + node-version: lts/* |
| 75 | + registry-url: 'https://registry.npmjs.org' |
| 76 | + |
| 77 | + - name: Enable Corepack |
| 78 | + shell: bash |
| 79 | + run: corepack enable |
| 80 | + |
| 81 | + - name: Restore build cache |
| 82 | + id: restore-build-cache |
| 83 | + if: ${{ inputs.restore-build-cache == 'true' }} |
| 84 | + uses: actions/cache/restore@v4 |
| 85 | + with: |
| 86 | + path: dist |
| 87 | + key: ${{ steps.determine-cache-key-build.outputs.final-cache-key-build }} |
| 88 | + |
| 89 | + - name: Restore node_modules cache |
| 90 | + id: restore-node-modules-cache |
| 91 | + if: ${{ inputs.restore-node-modules-cache == 'true' }} |
| 92 | + uses: actions/cache/restore@v4 |
| 93 | + with: |
| 94 | + path: node_modules |
| 95 | + key: ${{ steps.determine-cache-key-for-node-modules.outputs.final-cache-key-for-node-modules }} |
| 96 | + |
| 97 | + - name: Restore node_modules cache for E2E |
| 98 | + id: restore-e2e-node-modules-cache |
| 99 | + if: ${{ inputs.restore-e2e-node-modules-cache == 'true' }} |
| 100 | + uses: actions/cache/restore@v4 |
| 101 | + with: |
| 102 | + path: e2e/node_modules |
| 103 | + key: ${{ steps.determine-cache-key-for-e2e-node-modules.outputs.final-cache-key-for-e2e-node-modules }} |
| 104 | + |
| 105 | + - name: Install dependencies |
| 106 | + id: install-dependencies |
| 107 | + if: ${{ steps.restore-node-modules-cache.outputs.cache-hit != 'true' }} |
| 108 | + shell: bash |
| 109 | + run: yarn install --immutable |
| 110 | + |
| 111 | + - name: Install E2E dependencies |
| 112 | + id: install-e2e-dependencies |
| 113 | + if: ${{ steps.restore-e2e-node-modules-cache.outputs.cache-hit != 'true' }} |
| 114 | + shell: bash |
| 115 | + run: yarn e2e:yarn install --immutable |
| 116 | + |
| 117 | + - name: Cache node_modules |
| 118 | + id: cache-node-modules |
| 119 | + if: ${{ inputs.cache-node-modules == 'true' && steps.restore-node-modules-cache.outputs.cache-hit != 'true' && steps.install-dependencies.conclusion == 'success' }} |
| 120 | + uses: actions/cache/save@v4 |
| 121 | + with: |
| 122 | + path: node_modules |
| 123 | + key: ${{ steps.determine-cache-key-for-node-modules.outputs.final-cache-key-for-node-modules }} |
| 124 | + |
| 125 | + - name: Cache node_modules for E2E |
| 126 | + id: cache-e2e-node-modules |
| 127 | + if: ${{ inputs.cache-e2e-node-modules == 'true' && steps.restore-e2e-node-modules-cache.outputs.cache-hit != 'true' && steps.install-e2e-dependencies.conclusion == 'success' }} |
| 128 | + uses: actions/cache/save@v4 |
| 129 | + with: |
| 130 | + path: e2e/node_modules |
| 131 | + key: ${{ steps.determine-cache-key-for-e2e-node-modules.outputs.final-cache-key-for-e2e-node-modules }} |
| 132 | + |
| 133 | + - name: Prepare |
| 134 | + if: ${{ steps.restore-build-cache.outputs.cache-hit != 'true' }} |
| 135 | + shell: bash |
| 136 | + run: yarn prepare |
| 137 | + |
| 138 | + - name: Prepare E2E |
| 139 | + if: ${{ steps.restore-e2e-node-modules-cache.outputs.cache-hit != 'true' }} |
| 140 | + shell: bash |
| 141 | + run: yarn e2e:yarn prepare |
| 142 | + |
| 143 | + - name: Build types |
| 144 | + id: build-types |
| 145 | + if: steps.restore-build-cache.outputs.cache-hit != 'true' |
| 146 | + shell: bash |
| 147 | + run: yarn build::types |
| 148 | + |
| 149 | + - name: Build CJS |
| 150 | + id: build-cjs |
| 151 | + if: steps.restore-build-cache.outputs.cache-hit != 'true' |
| 152 | + shell: bash |
| 153 | + run: yarn build::cjs |
| 154 | + |
| 155 | + - name: Build ESM |
| 156 | + id: build-esm |
| 157 | + if: steps.restore-build-cache.outputs.cache-hit != 'true' |
| 158 | + shell: bash |
| 159 | + run: yarn build::esm |
| 160 | + |
| 161 | + - name: Update package exports |
| 162 | + id: update-package-exports |
| 163 | + if: steps.restore-build-cache.outputs.cache-hit != 'true' |
| 164 | + shell: bash |
| 165 | + run: yarn exports:update |
| 166 | + |
| 167 | + - name: Cache build |
| 168 | + id: cache-build |
| 169 | + if: ${{ inputs.cache-build == 'true' && steps.restore-build-cache.outputs.cache-hit != 'true' && steps.build-cjs.conclusion == 'success' && steps.build-esm.conclusion == 'success' && steps.build-types.conclusion == 'success' && steps.update-package-exports.conclusion == 'success' }} |
| 170 | + uses: actions/cache/save@v4 |
| 171 | + with: |
| 172 | + path: dist |
| 173 | + key: ${{ steps.determine-cache-key-build.outputs.final-cache-key-build }} |
0 commit comments