Skip to content

Commit 0ffc5c8

Browse files
authored
chore: Add composite setup action for pnpm (#6507)
* chore: Add composite setup action for pnpm * simplify setup action * chore: Rename npm-token to registry-token in setup action * chore: Remove default values for registry-url and registry-token in setup action * chore: Enhance registry URL resolution logic in setup action * chore: Skip lifecycle scripts during pnpm install and rebuild after token removal * simplify error printing * Improve registry resolution
1 parent df84426 commit 0ffc5c8

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

.github/actions/setup/action.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: setup
2+
description: Setup repo, node and pnpm.
3+
inputs:
4+
node-version:
5+
description: 'Node.js version'
6+
default: '22'
7+
registry-url:
8+
description: 'The registry URL to use for npm packages. Defaults to the SAP Artifactory mirror when npm-token is provided, otherwise npmjs.'
9+
registry-token:
10+
description: 'The auth token for the npm registry'
11+
pnpm-version:
12+
description: 'PNPM version'
13+
default: '10'
14+
pnpm-install-args:
15+
description: 'Arguments to pass to pnpm install'
16+
default: '--frozen-lockfile'
17+
package-manager-cache:
18+
description: 'Whether to enable caching for pnpm. Set to false to disable caching.'
19+
default: 'true'
20+
ref:
21+
description: 'The GitHub ref to checkout'
22+
default: ${{ github.ref }}
23+
token:
24+
description: 'The GitHub token to use for checkout'
25+
default: ${{ github.token }}
26+
persist-credentials:
27+
description: 'Whether to configure the token or SSH key with the local git config'
28+
default: false
29+
30+
runs:
31+
using: 'composite'
32+
steps:
33+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
34+
with:
35+
ref: ${{ inputs.ref }}
36+
token: ${{ inputs.token }}
37+
persist-credentials: ${{ inputs.persist-credentials }}
38+
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
39+
with:
40+
version: ${{ inputs.pnpm-version }}
41+
- id: resolve-registry-url
42+
shell: bash
43+
run: |
44+
if [[ -n "$REGISTRY_URL" ]]; then
45+
echo "url=$REGISTRY_URL" >> $GITHUB_OUTPUT
46+
elif [[ "$REPO" == "SAP/ai-sdk-js" || "$REPO" == "SAP/cloud-sdk-js" ]]; then
47+
if [[ -n "$REGISTRY_TOKEN" ]]; then
48+
echo "url=https://common.repositories.cloud.sap/artifactory/api/npm/build.releases.npm/" >> $GITHUB_OUTPUT
49+
else
50+
echo "::error::The input 'registry-token' is required when 'registry-url' is not provided."
51+
exit 1
52+
fi
53+
else
54+
echo "url=https://registry.npmjs.org" >> $GITHUB_OUTPUT
55+
fi
56+
env:
57+
REGISTRY_URL: ${{ inputs.registry-url }}
58+
REGISTRY_TOKEN: ${{ inputs.registry-token }}
59+
REPO: ${{ github.repository }}
60+
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
61+
with:
62+
node-version: ${{ inputs.node-version }}
63+
registry-url: ${{ steps.resolve-registry-url.outputs.url }}
64+
cache: 'pnpm'
65+
package-manager-cache: ${{ inputs.package-manager-cache }}
66+
# Install dependencies without lifecycle scripts.
67+
- run: pnpm install --ignore-scripts ${{ inputs.pnpm-install-args }}
68+
shell: bash
69+
env:
70+
NODE_AUTH_TOKEN: ${{ inputs.registry-token }}
71+
# Run lifecycle scripts after removing the registry token from the environment.
72+
- run: pnpm rebuild
73+
shell: bash

0 commit comments

Comments
 (0)