Skip to content

Commit 7d9f5a7

Browse files
author
Daniel Genis
committed
feat: publish only to github
1 parent 9e9c96d commit 7d9f5a7

8 files changed

Lines changed: 62 additions & 126 deletions

File tree

.github.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local util = import '.github/jsonnet/index.jsonnet';
22

33
util.workflowJavascriptPackage(
4-
repositories=['github', 'gynzy'],
4+
repositories=['github'],
55
packageManager='pnpm',
66
branch='main',
77
isPublicFork=true,

.github/jsonnet/GIT_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
48fa11c3a7d9df1e16a1cf7e86505945b0b7b6a2
1+
545ab086d65446b210d470713a69ba3beecf28e9

.github/jsonnet/complete-workflows.jsonnet

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ local yarn = import 'yarn.jsonnet';
1212
* 2. 'publish-prod' - Production package publishing on branch push
1313
* 3. 'pr' - Pull request preview publishing and testing
1414
*
15-
* @param {array} [repositories=['gynzy']] - The repositories to publish to
15+
* @param {array} [repositories=['github']] - The repositories to publish to
1616
* @param {boolean} [isPublicFork=true] - Whether the repository is a public fork (affects runner selection)
1717
* @param {boolean} [checkVersionBump=true] - Whether to assert if the version was bumped (recommended)
1818
* @param {jobs} [testJob=null] - A job to be run during PR to assert tests. Can be an array of jobs
19-
* @param {string} [branch='main'] - The branch to run the publish-prod job on
19+
* @param {string} [branch='main'] - The branch that triggers the publish-prod job; publishes the package <VERSION> specified in package.json and sets latest tag
2020
* @param {string} [packageManager='yarn'] - Package manager to use ('yarn' or 'pnpm')
2121
* @param {string} [image=null] - Docker image override for publish jobs; null uses the PM-specific default
2222
* @param {array} [buildSteps=null] - Build steps override; null uses the PM-specific default. Pass `[]` to skip build.
2323
* @returns {workflows} - Complete set of GitHub Actions workflows for JavaScript package lifecycle
2424
*/
2525
workflowJavascriptPackage(
26-
repositories=['gynzy'],
26+
repositories=['github'],
2727
isPublicFork=true,
2828
checkVersionBump=true,
2929
testJob=null,
@@ -37,8 +37,8 @@ local yarn = import 'yarn.jsonnet';
3737
else [base.step('build', 'yarn build')];
3838
local effectiveBuildSteps = if buildSteps != null then buildSteps else defaultBuildSteps;
3939
local publishJob = if packageManager == 'pnpm'
40-
then pnpm.pnpmPublishJob(repositories=repositories, runsOn=runsOn, image=image, buildSteps=effectiveBuildSteps)
41-
else yarn.yarnPublishJob(repositories=repositories, runsOn=runsOn, image=image, buildSteps=effectiveBuildSteps);
40+
then pnpm.pnpmPublishJob(repositories=repositories, runsOn=runsOn, image=image, buildSteps=effectiveBuildSteps, publishBranch=branch)
41+
else yarn.yarnPublishJob(repositories=repositories, runsOn=runsOn, image=image, buildSteps=effectiveBuildSteps, publishBranch=branch);
4242
local previewJob = if packageManager == 'pnpm'
4343
then pnpm.pnpmPublishPreviewJob(repositories=repositories, runsOn=runsOn, checkVersionBump=checkVersionBump, image=image, buildSteps=effectiveBuildSteps)
4444
else yarn.yarnPublishPreviewJob(repositories=repositories, runsOn=runsOn, checkVersionBump=checkVersionBump, image=image, buildSteps=effectiveBuildSteps);

.github/jsonnet/newrelic.jsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local pnpm = import 'pnpm.jsonnet';
1010
*
1111
* @param {array} apps - Array of application objects containing deployment information
1212
* @param {string} [cacheName=null] - Name of the cache to use for yarn/pnpm dependencies
13-
* @param {string} [source='gynzy'] - Registry source ('gynzy' or 'github') for npm packages
13+
* @param {string} [source='github'] - Registry source ('gynzy' or 'github') for npm packages
1414
* @param {string} [image='mirror.gcr.io/node:20.17'] - Docker image to use for the job
1515
* @param {boolean} [useCredentials=false] - Whether to use Docker registry credentials
1616
* @param {string} [packageManager='yarn'] - Package manager to use ('yarn' or 'pnpm')
@@ -20,7 +20,7 @@ local pnpm = import 'pnpm.jsonnet';
2020
postReleaseToNewRelicJob(
2121
apps,
2222
cacheName=null,
23-
source='gynzy',
23+
source='github',
2424
image='mirror.gcr.io/node:20.17',
2525
useCredentials=false,
2626
packageManager='yarn',

.github/jsonnet/pnpm.jsonnet

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ local yarn = import 'yarn.jsonnet';
6262
* @param {string} [ref=null] - Git ref to checkout (branch, tag, or commit)
6363
* @param {boolean} [prod=false] - Whether to install only production dependencies
6464
* @param {string} [workingDirectory=null] - Directory to run operations in
65-
* @param {string} [source='gynzy'] - Registry source ('gynzy' or 'github')
65+
* @param {string} [source='github'] - Registry source ('gynzy' or 'github')
6666
* @param {array} [pnpmInstallArgs=[]] - Additional arguments for pnpm install command
6767
* @param {boolean} [setupPnpm=true] - Whether to set up and install pnpm itself before installing all packages
6868
* @param {boolean} [blobless=null] - Whether to perform a blobless clone (--filter=blob:none); null uses checkout default
@@ -77,7 +77,7 @@ local yarn = import 'yarn.jsonnet';
7777
ref=null,
7878
prod=false,
7979
workingDirectory=null,
80-
source='gynzy',
80+
source='github',
8181
pnpmInstallArgs=[],
8282
setupPnpm=true,
8383
blobless=null,
@@ -182,12 +182,13 @@ local yarn = import 'yarn.jsonnet';
182182
* @param {array} [pnpmInstallArgs=[]] - Additional arguments for pnpm install
183183
* @param {string} [auditLevel='moderate'] - Minimum severity level to fail the job ('low', 'moderate', 'high', 'critical')
184184
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
185+
* @param {string} [source='github'] - Where to install @gynzy packages from ('github', 'gynzy')
185186
* @param {boolean} [blobless=null] - Whether to perform a blobless clone (--filter=blob:none); null uses checkout default
186187
* @param {number} [retryAttempts=null] - Number of additional checkout attempts on failure; null uses checkout default
187188
* @param {number} [cloneTimeout=null] - Timeout for git clone operation in minutes; null uses checkout default
188189
* @returns {workflows} - Complete GitHub Actions pipeline configuration
189190
*/
190-
pnpmAuditPipeline(cacheName=null, image=null, setupPnpm=true, pnpmInstallArgs=[], auditLevel='moderate', runsOn=null, blobless=null, retryAttempts=null, cloneTimeout=null)::
191+
pnpmAuditPipeline(cacheName=null, image=null, setupPnpm=true, pnpmInstallArgs=[], auditLevel='moderate', runsOn=null, source=null, blobless=null, retryAttempts=null, cloneTimeout=null)::
191192
base.pipeline(
192193
'pnpm-audit',
193194
[
@@ -201,6 +202,7 @@ local yarn = import 'yarn.jsonnet';
201202
ref='${{ github.event.pull_request.head.sha }}',
202203
setupPnpm=setupPnpm,
203204
pnpmInstallArgs=pnpmInstallArgs,
205+
source=source,
204206
blobless=blobless,
205207
retryAttempts=retryAttempts,
206208
cloneTimeout=cloneTimeout,
@@ -217,9 +219,15 @@ local yarn = import 'yarn.jsonnet';
217219
*
218220
* @param {boolean} [isPr=true] - Whether this is a PR build (affects versioning)
219221
* @param {string} [ifClause=null] - Conditional expression to determine if step should run
222+
* @param {string} [publishBranch=null] - The branch that triggers the publish-prod job; publishes the package <VERSION> specified in package.json and sets latest tag. When null, defaults to `main`/`master`
220223
* @returns {steps} - Array containing a single step object
221224
*/
222-
pnpmPublish(isPr=true, ifClause=null)::
225+
pnpmPublish(isPr=true, ifClause=null, publishBranch=null)::
226+
local branchCheck =
227+
if publishBranch == null then
228+
'( "${GITHUB_REF_NAME}" == "main" || "${GITHUB_REF_NAME}" == "master" )'
229+
else
230+
'"${GITHUB_REF_NAME}" == "' + publishBranch + '"';
223231
base.step(
224232
'publish',
225233
|||
@@ -240,7 +248,7 @@ local yarn = import 'yarn.jsonnet';
240248
echo "Setting tag/version for release/tag build.";
241249
PUBLISHVERSION=$VERSION;
242250
TAG="latest";
243-
elif [[ "${GITHUB_REF_TYPE}" == "branch" && ( "${GITHUB_REF_NAME}" == "main" || "${GITHUB_REF_NAME}" == "master" ) ]] || [[ "${GITHUB_EVENT_NAME}" == "deployment" ]]; then
251+
elif [[ "${GITHUB_REF_TYPE}" == "branch" && %s ]] || [[ "${GITHUB_EVENT_NAME}" == "deployment" ]]; then
244252
echo "Setting tag/version for release/tag build.";
245253
PUBLISHVERSION=$VERSION;
246254
TAG="latest";
@@ -253,7 +261,7 @@ local yarn = import 'yarn.jsonnet';
253261
254262
mv package.json.bak package.json;
255263
';
256-
|||,
264+
||| % branchCheck,
257265
env={} + (if isPr then { PR_NUMBER: '${{ github.event.number }}' } else {}),
258266
ifClause=ifClause,
259267
),
@@ -264,12 +272,13 @@ local yarn = import 'yarn.jsonnet';
264272
* @param {boolean} isPr - Whether this is a PR build (affects versioning)
265273
* @param {array} repositories - List of repository types ('gynzy' or 'github')
266274
* @param {string} [ifClause=null] - Conditional expression to determine if steps should run
275+
* @param {string} [publishBranch=null] - The branch that triggers the publish-prod job; publishes the package <VERSION> specified in package.json and sets latest tag. When null, defaults to `main`/`master`
267276
* @returns {steps} - Array of step objects for publishing to all repositories
268277
*/
269-
pnpmPublishToRepositories(isPr, repositories, ifClause=null)::
278+
pnpmPublishToRepositories(isPr, repositories, ifClause=null, publishBranch=null)::
270279
(std.flatMap(function(repository)
271-
if repository == 'gynzy' then [yarn.setGynzyNpmToken(ifClause=ifClause), self.pnpmPublish(isPr=isPr, ifClause=ifClause)]
272-
else if repository == 'github' then [yarn.setGithubNpmToken(ifClause=ifClause), self.pnpmPublish(isPr=isPr, ifClause=ifClause)]
280+
if repository == 'gynzy' then [yarn.setGynzyNpmToken(ifClause=ifClause), self.pnpmPublish(isPr=isPr, ifClause=ifClause, publishBranch=publishBranch)]
281+
else if repository == 'github' then [yarn.setGithubNpmToken(ifClause=ifClause, tokenSecret='GITHUB_TOKEN'), self.pnpmPublish(isPr=isPr, ifClause=ifClause, publishBranch=publishBranch)]
273282
else error 'Unknown repository type given.',
274283
repositories)),
275284

@@ -281,7 +290,7 @@ local yarn = import 'yarn.jsonnet';
281290
* @param {string} [gitCloneRef='${{ github.event.pull_request.head.sha }}'] - Git reference to checkout
282291
* @param {array} [buildSteps=null] - Build steps; null defaults to `[pnpm run build]`. Pass `[]` to skip build.
283292
* @param {boolean} [checkVersionBump=true] - Whether to check if package version was bumped
284-
* @param {array} [repositories=['gynzy']] - List of repositories to publish to
293+
* @param {array} [repositories=['github']] - List of repositories to publish to
285294
* @param {boolean|string} [onChangedFiles=false] - Whether to only run on changed files (or glob pattern)
286295
* @param {string} [changedFilesHeadRef=null] - Head reference for changed files comparison
287296
* @param {string} [changedFilesBaseRef=null] - Base reference for changed files comparison
@@ -294,7 +303,7 @@ local yarn = import 'yarn.jsonnet';
294303
gitCloneRef='${{ github.event.pull_request.head.sha }}',
295304
buildSteps=null,
296305
checkVersionBump=true,
297-
repositories=['gynzy'],
306+
repositories=['github'],
298307
onChangedFiles=false,
299308
changedFilesHeadRef=null,
300309
changedFilesBaseRef=null,
@@ -327,25 +336,27 @@ local yarn = import 'yarn.jsonnet';
327336
* @param {boolean} [useCredentials=false] - Whether to use Docker registry credentials
328337
* @param {string} [gitCloneRef='${{ github.sha }}'] - Git reference to checkout
329338
* @param {array} [buildSteps=null] - Build steps; null defaults to `[pnpm run build]`. Pass `[]` to skip build.
330-
* @param {array} [repositories=['gynzy']] - List of repositories to publish to
339+
* @param {array} [repositories=['github']] - List of repositories to publish to
331340
* @param {boolean|string} [onChangedFiles=false] - Whether to only run on changed files (or glob pattern)
332341
* @param {string} [changedFilesHeadRef=null] - Head reference for changed files comparison
333342
* @param {string} [changedFilesBaseRef=null] - Base reference for changed files comparison
334343
* @param {string} [ifClause=null] - Conditional expression to determine if job should run
335344
* @param {string} [runsOn=null] - Runner type to use
345+
* @param {string} [publishBranch=null] - The branch that triggers the publish-prod job; publishes the package <VERSION> specified in package.json and sets latest tag. When null, defaults to `main`/`master`
336346
* @returns {jobs} - GitHub Actions job definition
337347
*/
338348
pnpmPublishJob(
339349
image='mirror.gcr.io/node:24',
340350
useCredentials=false,
341351
gitCloneRef='${{ github.sha }}',
342352
buildSteps=null,
343-
repositories=['gynzy'],
353+
repositories=['github'],
344354
onChangedFiles=false,
345355
changedFilesHeadRef=null,
346356
changedFilesBaseRef=null,
347357
ifClause=null,
348358
runsOn=null,
359+
publishBranch=null,
349360
)::
350361
local effectiveBuildSteps = if buildSteps == null then [base.step('build', 'pnpm run build')] else buildSteps;
351362
local stepIfClause = (if onChangedFiles != false then "steps.changes.outputs.package == 'true'" else null);
@@ -358,7 +369,7 @@ local yarn = import 'yarn.jsonnet';
358369
[self.checkoutAndPnpm(ref=gitCloneRef, fullClone=false, source=repositories[0], pnpmInstallArgs=['--frozen-lockfile'])] +
359370
(if onChangedFiles != false then misc.testForChangedFiles({ package: onChangedFiles }, headRef=changedFilesHeadRef, baseRef=changedFilesBaseRef) else []) +
360371
(if onChangedFiles != false then std.map(function(step) std.map(function(s) s { 'if': stepIfClause }, step), effectiveBuildSteps) else effectiveBuildSteps) +
361-
self.pnpmPublishToRepositories(isPr=false, repositories=repositories, ifClause=stepIfClause),
372+
self.pnpmPublishToRepositories(isPr=false, repositories=repositories, ifClause=stepIfClause, publishBranch=publishBranch),
362373
permissions={ packages: 'write', contents: 'read', 'pull-requests': 'read' },
363374
ifClause=ifClause,
364375
),

0 commit comments

Comments
 (0)