|
| 1 | +# Note: This is a composite GitHub Actions, it should do all env setup, caching an so on, so other pipelines can just compose their own stuff on top of that. |
| 2 | +# Docs: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action |
| 3 | + |
| 4 | +name: Configure Environment |
| 5 | +description: Shared configuration for checkout, Node.js and package manager |
| 6 | +inputs: |
| 7 | + nodeVersion: |
| 8 | + description: Node.js version to use |
| 9 | + required: true |
| 10 | + default: '20' |
| 11 | + workingDirectory: |
| 12 | + description: Working directory |
| 13 | + required: false |
| 14 | + default: ./ |
| 15 | + packageManager: |
| 16 | + description: Package manager |
| 17 | + required: false |
| 18 | + default: yarn |
| 19 | + packageManagerVersion: |
| 20 | + description: Package manager version |
| 21 | + required: false |
| 22 | + default: '' |
| 23 | + |
| 24 | +runs: |
| 25 | + using: composite |
| 26 | + steps: |
| 27 | + - name: Cancel Previous Runs |
| 28 | + uses: styfle/cancel-workflow-action@0.12.1 |
| 29 | + continue-on-error: true |
| 30 | + with: |
| 31 | + access_token: ${{ github.token }} |
| 32 | + |
| 33 | + - name: check pnpm version |
| 34 | + shell: bash |
| 35 | + id: pnpm |
| 36 | + if: inputs.packageManager == 'pnpm' |
| 37 | + working-directory: ${{ inputs.workingDirectory }} |
| 38 | + run: | |
| 39 | + PNPM_VERSION=${PNPM_VERSION:-9.0.6} |
| 40 | + PKG_JSON=$(cat package.json | jq -r '.packageManager' | awk -F@ '{print $2}') |
| 41 | + if [ ! -z $PKG_JSON ]; then |
| 42 | + PNPM_VERSION=$PKG_JSON |
| 43 | + fi |
| 44 | + if [ ! -z {{inputs.packageManager}} ]; then |
| 45 | + PNPM_VERSION=${{ inputs.packageManagerVersion }} |
| 46 | + fi |
| 47 | + echo "Using PNPM version $PNPM_VERSION" |
| 48 | + echo "version=$PNPM_VERSION" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Setup ${{ inputs.packageManager }} |
| 51 | + id: pnpm_setup |
| 52 | + if: inputs.packageManager == 'pnpm' |
| 53 | + uses: pnpm/action-setup@v4.0.0 |
| 54 | + with: |
| 55 | + version: ${{ steps.pnpm.outputs.version }} |
| 56 | + run_install: false |
| 57 | + package_json_file: ${{ inputs.workingDirectory }}/package.json |
| 58 | + |
| 59 | + - name: setup node |
| 60 | + uses: actions/setup-node@v4 |
| 61 | + with: |
| 62 | + node-version: ${{ inputs.nodeVersion }} |
| 63 | + cache: ${{ inputs.packageManager }} |
| 64 | + cache-dependency-path: | |
| 65 | + **/pnpm-lock.yaml |
| 66 | + **/yarn.lock |
| 67 | + patches/** |
| 68 | +
|
| 69 | + - name: yarn install |
| 70 | + shell: bash |
| 71 | + if: inputs.packageManager == 'yarn' && inputs.packageManagerVersion == '' |
| 72 | + run: yarn install --ignore-engines --frozen-lockfile --immutable |
| 73 | + working-directory: ${{ inputs.workingDirectory }} |
| 74 | + |
| 75 | + - name: modern yarn install |
| 76 | + shell: bash |
| 77 | + if: inputs.packageManager == 'yarn' && inputs.packageManagerVersion == 'modern' |
| 78 | + run: corepack enable && yarn |
| 79 | + working-directory: ${{ inputs.workingDirectory }} |
| 80 | + |
| 81 | + - name: pnpm install |
| 82 | + shell: bash |
| 83 | + if: inputs.packageManager == 'pnpm' |
| 84 | + run: pnpm install --frozen-lockfile |
| 85 | + working-directory: ${{ inputs.workingDirectory }} |
0 commit comments