|
| 1 | + |
| 2 | +name: Setup Action |
| 3 | +description: Checkout, setup node and dependencies |
| 4 | +inputs: |
| 5 | + node-version: |
| 6 | + description: 'The node version to use' |
| 7 | + required: false |
| 8 | + default: '18' |
| 9 | + playwright-enabled: |
| 10 | + description: 'Enable Playwright?' |
| 11 | + required: false |
| 12 | + default: 'false' |
| 13 | + turbo-enabled: |
| 14 | + description: 'Enable Turbo?' |
| 15 | + required: false |
| 16 | + default: 'true' |
| 17 | + turbo-cache-dir: |
| 18 | + description: 'The cache dir to use for Turbo' |
| 19 | + required: false |
| 20 | + default: './.turbo-cache' |
| 21 | + turbo-signature: |
| 22 | + description: 'The signature to use for Turbo' |
| 23 | + required: false |
| 24 | + turbo-remote-only: |
| 25 | + description: 'Only use remote cache?' |
| 26 | + required: false |
| 27 | + default: 'true' |
| 28 | + turbo-team: |
| 29 | + description: 'The team to use for Turbo remote auth' |
| 30 | + required: true |
| 31 | + turbo-token: |
| 32 | + description: 'The token to use for Turbo remote auth' |
| 33 | + required: true |
| 34 | + |
| 35 | +runs: |
| 36 | + using: "composite" |
| 37 | + steps: |
| 38 | + - name: Configure Turborepo |
| 39 | + id: turbo |
| 40 | + uses: actions/github-script@v6 |
| 41 | + env: |
| 42 | + # envs are required to pass inputs to the script |
| 43 | + ENABLED: ${{ inputs.turbo-enabled }} |
| 44 | + CACHE_DIR: ${{ inputs.turbo-cache-dir }} |
| 45 | + REMOTE_ONLY: ${{ inputs.turbo-remote-only }} |
| 46 | + SIGNATURE: ${{ inputs.turbo-signature }} |
| 47 | + TEAM: ${{ inputs.turbo-team }} |
| 48 | + TOKEN: ${{ inputs.turbo-token }} |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const os = require('os') |
| 52 | + const cpus = |
| 53 | + typeof os.availableParallelism === "function" |
| 54 | + ? os.availableParallelism() |
| 55 | + : os.cpus().length; |
| 56 | +
|
| 57 | + const { ENABLED, CACHE_DIR, SIGNATURE, REMOTE_ONLY, TEAM, TOKEN } = process.env |
| 58 | +
|
| 59 | + core.exportVariable('TURBO_ARGS', |
| 60 | + [ |
| 61 | + '--output-logs=new-only', |
| 62 | + `--cache-dir=${CACHE_DIR}`, |
| 63 | + `--concurrency=${cpus}` |
| 64 | + ].join(' ') |
| 65 | + ) |
| 66 | +
|
| 67 | + if (ENABLED === 'true') { |
| 68 | + core.exportVariable('TURBO_TEAM', TEAM) |
| 69 | + core.exportVariable('TURBO_TOKEN', TOKEN) |
| 70 | + core.exportVariable('TURBO_REMOTE_ONLY', REMOTE_ONLY) |
| 71 | + } |
| 72 | +
|
| 73 | + if (SIGNATURE && SIGNATURE !== '') { |
| 74 | + core.exportVariable('TURBO_REMOTE_CACHE_SIGNATURE_KEY', SIGNATURE) |
| 75 | + } |
| 76 | +
|
| 77 | + core.exportVariable('FORCE_COLOR', '1') |
| 78 | +
|
| 79 | + - name: Turborepo CLI Args |
| 80 | + shell: bash |
| 81 | + run: echo $TURBO_ARGS |
| 82 | + |
| 83 | + - name: Setup NodeJS ${{ inputs.node-version }} |
| 84 | + uses: actions/setup-node@v3 |
| 85 | + with: |
| 86 | + node-version: ${{ inputs.node-version }} |
| 87 | + |
| 88 | + - name: Cache node_modules |
| 89 | + uses: actions/cache@v3 |
| 90 | + id: npm-cache |
| 91 | + with: |
| 92 | + path: ./node_modules |
| 93 | + key: ${{ runner.os }}-node-${{ inputs.node-version }}-node-modules-${{ hashFiles('**/package-lock.json') }} |
| 94 | + |
| 95 | + - name: Install NPM Dependencies |
| 96 | + if: steps.npm-cache.outputs.cache-hit != 'true' |
| 97 | + run: npm ci --audit=false --fund=false |
| 98 | + shell: bash |
| 99 | + |
| 100 | + - name: Get Playwright Version |
| 101 | + if: inputs.playwright-enabled == 'true' |
| 102 | + shell: bash |
| 103 | + id: playwright-version |
| 104 | + run: echo "VERSION=$(node -e "console.log($(npm ls @playwright/test --json).dependencies['@playwright/test'].version)")" >> "$GITHUB_OUTPUT" |
| 105 | + |
| 106 | + - name: Cache Playwright Binaries |
| 107 | + if: inputs.playwright-enabled == 'true' |
| 108 | + uses: actions/cache@v3 |
| 109 | + id: playwright-cache |
| 110 | + with: |
| 111 | + path: ~/.cache/ms-playwright |
| 112 | + key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-playwright-${{ steps.playwright-version.outputs.VERSION }} |
| 113 | + |
| 114 | + - name: Install Playwright Browsers |
| 115 | + if: inputs.playwright-enabled == 'true' && steps.playwright-cache.outputs.cache-hit != 'true' |
| 116 | + shell: bash |
| 117 | + run: npx playwright install --with-deps |
0 commit comments