Skip to content

Commit fc9dec9

Browse files
authored
feat: allow npm for publish and install (#142)
* feat: allow npm for publish and install * docs: explain how to use npm for publish * refactor: pr comments and cursor context * chore: env/input cleanup * refactor: more env stuff * refactor: reduce change * style: spacing to reduce git noise
1 parent 55ed1b0 commit fc9dec9

File tree

6 files changed

+83
-30
lines changed

6 files changed

+83
-30
lines changed

.cursor/rules/yaml-checklist.mdc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
globs: *.yml
3+
alwaysApply: false
4+
---
5+
6+
Moving stuff to Environment Variables for safer scripting
7+
ex: there is an input named `githubTag`. Add an `ENV:` to it like `INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}`
8+
9+
### shell scripts
10+
11+
In github worklows that run shell scripts refer to inputs and outputs via the environment variable convention.
12+
BAD: `RESPONSE=$(npm view .@${{ inputs.githubTag }} version --json --silent || echo "Not published")`
13+
GOOD: `RESPONSE=$(npm view .@$INPUTS_GITHUB_TAG version --json --silent || echo "Not published")`
14+
15+
### script tag
16+
17+
when using `script` from actions/github-script
18+
BAD: `script: core.setFailed("The version '$INPUTS_GITHUB_TAG' has already been published to npm")`
19+
GOOD: `script: core.setFailed(`The version '${process.env.INPUTS_GITHUB_TAG}' has already been published to npm`)`
20+
21+
It's OK to use ${{ foo }} outside of shell script (`run:`) blocks and outside of `script` (example if: statements on a job)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: npm-install-with-retries
2+
description: 'wraps npm install with retries/timeout to handle network failures'
3+
inputs:
4+
ignore-scripts:
5+
default: 'false'
6+
description: 'Skip pre/post install scripts'
7+
runs:
8+
using: composite
9+
steps:
10+
- name: npm install
11+
uses: salesforcecli/github-workflows/.github/actions/retry@main
12+
with:
13+
command: npm install --timeout 600000 ${{ inputs.ignore-scripts == 'true' && '--ignore-scripts' || '' }}

.github/actions/yarnInstallWithRetries/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: yarn-install-with-retries
2-
description: "wraps yarn install with retries/timeout to handle network failures"
2+
description: 'wraps yarn install with retries/timeout to handle network failures'
33
inputs:
44
ignore-scripts:
55
default: 'false'
6-
description: "Skip pre/post install scripts"
6+
description: 'Skip pre/post install scripts'
77
runs:
88
using: composite
99
steps:

.github/workflows/externalNut.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,50 @@ on:
1515
inputs:
1616
# could we get this from pjson?
1717
packageName:
18-
description: "The npm package that this repository publishes. ex: @salesforce/core"
18+
description: 'The npm package that this repository publishes. ex: @salesforce/core'
1919
required: true
2020
type: string
2121
externalProjectGitUrl:
22-
description: "The url that will be cloned. This contains the NUTs you want to run. Ex: https://github.com/salesforcecli/plugin-user"
22+
description: 'The url that will be cloned. This contains the NUTs you want to run. Ex: https://github.com/salesforcecli/plugin-user'
2323
type: string
2424
required: true
2525
command:
2626
required: false
2727
type: string
2828
default: yarn test:nuts
29-
description: "command to execute (ex: yarn test:nuts)"
29+
description: 'command to execute (ex: yarn test:nuts)'
3030
nodeVersion:
3131
required: false
3232
description: version of node to run tests against. Use things like [lts/-1, lts/*, latest] to avoid hardcoding versions
3333
type: string
3434
default: lts/*
3535
os:
3636
required: false
37-
description: "runs-on property, ex: ubuntu-latest, windows-latest"
37+
description: 'runs-on property, ex: ubuntu-latest, windows-latest'
3838
type: string
39-
default: "ubuntu-latest"
39+
default: 'ubuntu-latest'
4040
sfdxExecutablePath:
4141
required: false
4242
description: "Path to sfdx executable to be used by NUTs, defaults to ''"
4343
type: string
4444
preBuildCommands:
4545
required: false
46-
description: "commands to run before the build...for example, to delete known module conflicts"
46+
description: 'commands to run before the build...for example, to delete known module conflicts'
4747
type: string
4848
default: 'echo "no preBuildCommands passed"'
4949
postBuildCommands:
5050
required: false
51-
description: "script to run after the build"
51+
description: 'script to run after the build'
5252
type: string
5353
default: 'echo "no postBuildCommands passed"'
5454
preExternalBuildCommands:
5555
required: false
56-
description: "commands to run before the build of the external repo...for example, to delete known module conflicts"
56+
description: 'commands to run before the build of the external repo...for example, to delete known module conflicts'
5757
type: string
5858
default: 'echo "no preExternalBuildCommands passed"'
5959
preSwapCommands:
6060
required: false
61-
description: "commands to run before ANY modifications happen. For example, changes that modify the lockfile like yarn add or remove need to happen before the action manually swaps the dependency under test"
61+
description: 'commands to run before ANY modifications happen. For example, changes that modify the lockfile like yarn add or remove need to happen before the action manually swaps the dependency under test'
6262
type: string
6363
default: 'echo "no preSwapCommands passed"'
6464
useCache:
@@ -73,10 +73,10 @@ on:
7373
required: false
7474
description: "branch to clone from the repo. Defaults to 'main'"
7575
type: string
76-
default: "main"
76+
default: 'main'
7777
ignoreScripts:
7878
required: false
79-
description: "if true, will run yarn install --ignore-scripts when building package in node_modules"
79+
description: 'if true, will run yarn install --ignore-scripts when building package in node_modules'
8080
type: boolean
8181
default: false
8282

.github/workflows/npmPublish.yml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,29 @@ on:
5050
description: the github release tag that you want to publish as an npm package
5151
required: true
5252
type: string
53+
packageManager:
54+
description: the package manager to use. Defaults to yarn, but can be set to npm
55+
required: false
56+
default: yarn
57+
type: string
5358
jobs:
5459
check-publish:
5560
outputs:
5661
published: ${{ steps.is-published.outputs.published }}
5762
runs-on: ubuntu-latest
63+
env:
64+
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
65+
INPUTS_PACKAGE_MANAGER: ${{ inputs.packageManager }}
5866
steps:
5967
- uses: actions/checkout@v4
6068
with:
6169
ref: ${{ inputs.githubTag }}
62-
70+
- name: Validate package manager
71+
run: |
72+
if [[ "$INPUTS_PACKAGE_MANAGER" != "yarn" && "$INPUTS_PACKAGE_MANAGER" != "npm" ]]; then
73+
echo "Error: packageManager must be 'yarn' or 'npm', got '$INPUTS_PACKAGE_MANAGER'"
74+
exit 1
75+
fi
6376
- uses: actions/setup-node@v4
6477
with:
6578
node-version: ${{ inputs.nodeVersion }}
@@ -76,7 +89,6 @@ jobs:
7689
echo "published=false" >> "$GITHUB_OUTPUT"
7790
fi
7891
env:
79-
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
8092
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
8193

8294
- run: echo "[INFO] Is package published:\ $STEPS_IS_PUBLISHED_PUBLISHED"
@@ -88,8 +100,6 @@ jobs:
88100
uses: actions/github-script@v7
89101
with:
90102
script: core.setFailed(`The version '${process.env.INPUTS_GITHUB_TAG}' has already been published to npm`)
91-
env:
92-
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
93103

94104
ctc-open:
95105
needs: [check-publish]
@@ -103,22 +113,26 @@ jobs:
103113
needs: [check-publish, ctc-open]
104114
if: ${{ always() && needs.check-publish.outputs.published == 'false' && (!inputs.ctc || (inputs.ctc && needs.ctc-open.outputs.changeCaseId)) }}
105115
runs-on: ${{ inputs.runsOn }}
116+
env:
117+
INPUTS_PACKAGE_MANAGER: ${{ inputs.packageManager }}
118+
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
119+
INPUTS_TAG: ${{ inputs.tag }}
106120
steps:
107121
- uses: actions/checkout@v4
108122
with:
109123
ref: ${{ inputs.githubTag }}
110-
111124
- uses: actions/setup-node@v4
112125
with:
113126
node-version: ${{ inputs.nodeVersion }}
114-
cache: yarn
115-
116-
- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
117-
118-
- run: yarn build
119-
127+
cache: ${{ inputs.packageManager }}
128+
- name: Install dependencies with yarn
129+
if: inputs.packageManager == 'yarn'
130+
uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
131+
- name: Install dependencies with npm
132+
if: inputs.packageManager == 'npm'
133+
uses: salesforcecli/github-workflows/.github/actions/npmInstallWithRetries@main
134+
- run: $INPUTS_PACKAGE_MANAGER run build
120135
- run: npm install -g @salesforce/plugin-release-management
121-
122136
- name: NPM Release
123137
run: |
124138
sf-release npm:package:release \
@@ -129,8 +143,6 @@ jobs:
129143
${{ inputs.prerelease && format('--prerelease {0}', github.ref_name) || '' }} \
130144
${{ inputs.sign && '--sign' || '' }}
131145
env:
132-
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
133-
INPUTS_TAG: ${{ inputs.tag }}
134146
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
135147
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
136148
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ jobs:
7979
# NPM_TOKEN: ^&*$
8080
```
8181

82+
works with npm, too
83+
84+
```yml
85+
with:
86+
packageManager: npm
87+
```
88+
8289
### Plugin Signing
8390
8491
Plugins created by Salesforce teams can be signed automatically with `sign:true` if the repo is in [salesforcecli](https://github.com/salesforcecli) or [forcedotcom](https://github.com/forcedotcom) gitub organization.
@@ -135,12 +142,12 @@ on:
135142
# point at specific branches, or a naming convention via wildcard
136143
- prerelease/**
137144
tags-ignore:
138-
- "*"
145+
- '*'
139146
workflow_dispatch:
140147
inputs:
141148
prerelease:
142149
type: string
143-
description: "Name to use for the prerelease: beta, dev, etc. NOTE: If this is already set in the package.json, it does not need to be passed in here."
150+
description: 'Name to use for the prerelease: beta, dev, etc. NOTE: If this is already set in the package.json, it does not need to be passed in here.'
144151
145152
jobs:
146153
release:
@@ -294,7 +301,7 @@ name: automerge
294301
on:
295302
workflow_dispatch:
296303
schedule:
297-
- cron: "56 2,5,8,11 * * *"
304+
- cron: '56 2,5,8,11 * * *'
298305

299306
jobs:
300307
automerge:

0 commit comments

Comments
 (0)