Skip to content

Commit e8d02e6

Browse files
Merge pull request #317 from snehaljha-sf/pipeline_fix_check
fix: skipped scripts for yarn install
2 parents 51fc3fc + 0835312 commit e8d02e6

File tree

2 files changed

+156
-1
lines changed

2 files changed

+156
-1
lines changed

.github/workflows/npmPublish.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
on:
2+
workflow_call:
3+
secrets:
4+
NPM_TOKEN:
5+
description: npm token
6+
AWS_ACCESS_KEY_ID:
7+
description: AWS access key id. Only required if sign = true
8+
AWS_SECRET_ACCESS_KEY:
9+
description: AWS secret access key. Only required if sign = true
10+
11+
inputs:
12+
tag:
13+
required: false
14+
description: tag used to publish to npm
15+
default: latest
16+
type: string
17+
sign:
18+
required: false
19+
description: signs the package using sf-release if set to true
20+
default: false
21+
type: boolean
22+
dryrun:
23+
required: false
24+
description: if true, the job will run but will not publish to npm or push to git
25+
default: false
26+
type: boolean
27+
prerelease:
28+
required: false
29+
description: if true, it will use the version <version>-<branch>.0
30+
type: boolean
31+
default: false
32+
nodeVersion:
33+
description: version of node to use. It's better to specify latest, lts/* or lts/-1 than to hardode numbers
34+
type: string
35+
default: lts/*
36+
required: false
37+
ctc:
38+
description: |
39+
Use CTC. Requires environment to contain
40+
SF_CHANGE_CASE_SFDX_AUTH_URL, SF_CHANGE_CASE_TEMPLATE_ID, SF_CHANGE_CASE_CONFIGURATION_ITEM.
41+
Also requires a static ip runner (you can't use ubuntu-latest)
42+
type: boolean
43+
required: false
44+
runsOn:
45+
description: the runner. Only needed if you need a non-public runner (ex, for git checkout from IP restricted private repo)
46+
default: ubuntu-latest
47+
required: false
48+
type: string
49+
githubTag:
50+
description: the github release tag that you want to publish as an npm package
51+
required: true
52+
type: string
53+
jobs:
54+
check-publish:
55+
outputs:
56+
published: ${{ steps.is-published.outputs.published }}
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v4
60+
with:
61+
ref: ${{ inputs.githubTag }}
62+
63+
- uses: actions/setup-node@v4
64+
with:
65+
node-version: ${{ inputs.nodeVersion }}
66+
67+
- name: Is published
68+
id: is-published
69+
run: |
70+
RESPONSE=$(npm view .@$INPUTS_GITHUB_TAG version --json --silent || echo "Not published")
71+
72+
# The response is wrapped in double quotes, so we need to compare it with (escaped) quotes
73+
if [ "$RESPONSE" = "\"$INPUTS_GITHUB_TAG\"" ]; then
74+
echo "published=true" >> "$GITHUB_OUTPUT"
75+
else
76+
echo "published=false" >> "$GITHUB_OUTPUT"
77+
fi
78+
env:
79+
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
80+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
81+
82+
- run: echo "[INFO] Is package published:\ $STEPS_IS_PUBLISHED_PUBLISHED"
83+
env:
84+
STEPS_IS_PUBLISHED_PUBLISHED: ${{ steps.is-published.outputs.published }}
85+
86+
- name: Fail if published
87+
if: steps.is-published.outputs.published == 'true'
88+
uses: actions/github-script@v7
89+
with:
90+
script: core.setFailed(`The version '${process.env.INPUTS_GITHUB_TAG}' has already been published to npm`)
91+
env:
92+
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
93+
94+
ctc-open:
95+
needs: [check-publish]
96+
if: inputs.ctc && needs.check-publish.outputs.published == 'false'
97+
uses: salesforcecli/github-workflows/.github/workflows/ctcOpen.yml@main
98+
with:
99+
githubTag: ${{ inputs.githubTag }}
100+
secrets: inherit
101+
102+
npm-publish:
103+
needs: [check-publish, ctc-open]
104+
if: ${{ always() && needs.check-publish.outputs.published == 'false' && (!inputs.ctc || (inputs.ctc && needs.ctc-open.outputs.changeCaseId)) }}
105+
runs-on: ${{ inputs.runsOn }}
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
ref: ${{ inputs.githubTag }}
110+
111+
- uses: actions/setup-node@v4
112+
with:
113+
node-version: ${{ inputs.nodeVersion }}
114+
cache: yarn
115+
116+
- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
117+
with:
118+
ignore-scripts: true
119+
120+
- run: yarn build
121+
122+
- run: npm install -g @salesforce/plugin-release-management
123+
124+
- name: NPM Release
125+
run: |
126+
sf-release npm:package:release \
127+
--githubtag "$INPUTS_GITHUB_TAG" \
128+
--npmtag "$INPUTS_TAG" \
129+
--no-install \
130+
${{ inputs.dryrun && '--dryrun' || '' }} \
131+
${{ inputs.prerelease && format('--prerelease {0}', github.ref_name) || '' }} \
132+
${{ inputs.sign && '--sign' || '' }}
133+
env:
134+
INPUTS_GITHUB_TAG: ${{ inputs.githubTag }}
135+
INPUTS_TAG: ${{ inputs.tag }}
136+
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
137+
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
138+
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}}
139+
140+
ctcCloseSuccess:
141+
needs: [ctc-open, npm-publish]
142+
if: needs.ctc-open.result == 'success' && needs.npm-publish.result == 'success' && needs.ctc-open.outputs.changeCaseId
143+
uses: salesforcecli/github-workflows/.github/workflows/ctcClose.yml@main
144+
secrets: inherit
145+
with:
146+
changeCaseId: ${{needs.ctc-open.outputs.changeCaseId}}
147+
148+
ctcCloseFail:
149+
needs: [ctc-open, npm-publish]
150+
if: always() && inputs.ctc && needs.ctc-open.outputs.changeCaseId && (needs.ctc-open.result != 'success' || needs.npm-publish.result != 'success')
151+
uses: salesforcecli/github-workflows/.github/workflows/ctcClose.yml@main
152+
secrets: inherit
153+
with:
154+
changeCaseId: ${{ needs.ctc-open.outputs.changeCaseId }}
155+
status: Not Implemented

.github/workflows/onRelease.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
id: distTag
2727

2828
npm:
29-
uses: salesforcecli/github-workflows/.github/workflows/npmPublish.yml@main
29+
uses: ./.github/workflows/npmPublish.yml
3030
needs: [getDistTag]
3131
with:
3232
ctc: true

0 commit comments

Comments
 (0)