Skip to content

Commit 2dbc3d0

Browse files
authored
chore: make manual publishing a bit better (#2666)
* chore: make manual publishing a bit better * chore: update docs * chore: add more publishing scripts info
1 parent 7a67506 commit 2dbc3d0

2 files changed

Lines changed: 53 additions & 29 deletions

File tree

gulpfile.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function checkLicenses() {
4848
/**
4949
* Prepare for publishing. Must be run before any manual publish command.
5050
*
51-
* Clones blockly-samples, runs build and tests, logs into npm publish service.
51+
* Clones blockly-samples, runs build and tests.
5252
* @param {Function} done Completed callback.
5353
*/
5454
function prepareForPublish(done) {
@@ -82,11 +82,6 @@ function prepareForPublish(done) {
8282
console.log('Testing all plugins.');
8383
execSync('npm run test', {cwd: releaseDir, stdio: 'inherit'});
8484

85-
// Login to npm.
86-
console.log('Logging in to npm.');
87-
execSync(`npm login`, {
88-
stdio: 'inherit',
89-
});
9085
done();
9186
}
9287

@@ -100,16 +95,15 @@ function exitIfNoReleaseDir(releaseDir, done) {
10095
if (!fs.existsSync(releaseDir)) {
10196
console.error(
10297
`No release directory ${releaseDir} exists. ` +
103-
`Did you run 'npm run publish:prepare'?`,
98+
`blockly-samples may not have been cloned correctly.`,
10499
);
105100
done();
106101
process.exit(1);
107102
}
108103
}
109104

110105
/**
111-
* This script does not log into the npm publish service. If you haven't run
112-
* the prepare script recently, publishing will fail for that reason.
106+
* Publishes plugins using lerna. MUST be run after `prepareForPublish`.
113107
* @param {boolean=} force True for forcing all plugins to publish, even ones
114108
* that have not changed.
115109
* @returns {Function} Gulp task.
@@ -141,8 +135,8 @@ function publish(force) {
141135
* @param {Function} done Completed callback.
142136
* @returns {Function} Gulp task.
143137
*/
144-
function publishManual(done) {
145-
return publish(false)(done);
138+
function prepareAndPublish(done) {
139+
return gulp.series(prepareForPublish, publish(false))(done);
146140
}
147141

148142
/**
@@ -151,8 +145,8 @@ function publishManual(done) {
151145
* @param {Function} done Completed callback.
152146
* @returns {Function} Gulp task.
153147
*/
154-
function forcePublish(done) {
155-
return publish(true)(done);
148+
function prepareAndForcePublish(done) {
149+
return gulp.series(prepareForPublish, publish(true))(done);
156150
}
157151

158152
/**
@@ -178,6 +172,16 @@ function publishFromPackage(done) {
178172
done();
179173
}
180174

175+
/**
176+
* Publishes plugins that haven't been previously uploaded to npm.
177+
* Also runs the prepare scripts to ensure plugins have been built and tested before publishing.
178+
* @param {Function} done Completed callback.
179+
* @returns {Function} Gulp task.
180+
*/
181+
function prepareAndPublishFromPackage(done) {
182+
return gulp.series(prepareForPublish, publishFromPackage)(done);
183+
}
184+
181185
/**
182186
* Runs lerna version to check which version numbers would be updated.
183187
* The version numbers will not be pushed and no tags or releases will
@@ -202,6 +206,15 @@ function checkVersions(done) {
202206
done();
203207
}
204208

209+
/**
210+
* Runs prepareForPublish and then checkVersions.
211+
* @param {Function} done Completed callback.
212+
* @returns {Function} Gulp task.
213+
*/
214+
function prepareAndCheckVersions(done) {
215+
return gulp.series(prepareForPublish, checkVersions)(done);
216+
}
217+
205218
/**
206219
* Deploy all plugins to gh-pages.
207220
* @param {string=} repo The repo to deploy to.
@@ -312,10 +325,10 @@ module.exports = {
312325
deployUpstream: deployToGhPagesUpstream,
313326
predeploy: predeployTasks.predeployAll,
314327
prepareForPublish: prepareForPublish,
315-
publishManual: publishManual,
316-
forcePublish: forcePublish,
317-
publishFromPackage: publishFromPackage,
318-
checkVersions: checkVersions,
328+
publishManual: prepareAndPublish,
329+
forcePublish: prepareAndForcePublish,
330+
publishFromPackage: prepareAndPublishFromPackage,
331+
checkVersions: prepareAndCheckVersions,
319332
testGhPagesBeta: testGhPagesLocally(true),
320333
testGhPages: testGhPagesLocally(false),
321334
};

scripts.md

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,55 +52,66 @@ This script builds all files needed to deploy plugins and examples to GitHub Pag
5252

5353
This script installs a beta version of Blockly, builds all files needed to deploy plugins and examples to GitHub Pages, then starts a local server with that content.
5454

55+
## Publishing scripts
56+
57+
Note that publishing via the command line is not preferred. You should
58+
use the GitHub Action workflow whenever possible, which can handle
59+
publishing all plugins as well as recovering from the partially-published
60+
state (publishing unpublished plugins only).
61+
62+
Note that none of these scripts will handle npm authentication. You need to
63+
configure an npm authentication token before you can use these scripts.
64+
65+
Full publishing documentation can be found in the internal team documentation.
66+
5567
### `npm run publish:prepare`
5668

5769
This script will clone a copy of blockly-samples to a directory called `dist`,
58-
run `npm ci`, build and test all plugins, and then log in to the npm publishing
59-
service. It must be run before any of the other manual publishing commands are
60-
run.
70+
run `npm ci`, then build and test all plugins.
6171

6272
If any plugin fails to build or some tests fail, this script should fail. Since
6373
nothing has been pushed to npm or github, you can simply correct the error and
6474
try again.
6575

76+
This script will be run automatically before any of the other publish scripts,
77+
so you do not need to run it manually first.
78+
6679
### `npm run publish:manual`
6780

68-
This script assumes that you have already run `npm run publish:prepare`. It will
81+
This script will first run `npm run publish:prepare`. It will
6982
publish all of the changed plugins since the last release, using the `dist`
7083
directory. It runs the lerna command that uses conventional commits to determine
7184
a new version number for each plugin, and publishes the new versions to npm and
72-
to a github release and tag. Plugins do not automatically build themselves
73-
before publishing. You must have run `npm run publish:prepare` script ahead of
74-
time for this reason.
85+
to a github release and tag.
7586

7687
If there is some error with npm while running this command, you may end up in a
7788
state where some plugins have been published to npm and not others, after lerna
7889
has already tagged the new releases. You can recover from this state by fixing
79-
the error, and then running `npm run publish:prepare` again followed by
90+
the error, and then running either
8091
`npm run publish:unpublishedOnly` or `npm run publish:force`.
8192

8293
### `npm run publish:unpublishedOnly`
8394

84-
This script assumes that you have already run `npm run publish:prepare`. It uses the `dist`
95+
This script will first run `npm run publish:prepare`. It uses the `dist`
8596
directory created in that script. It uses lerna to check each plugin to see if the version
8697
in `package.json` matches the version on npm. If a version is not yet on npm, it will publish
8798
that plugin without updating its version number. Thus, this script should only be used
8899
after `lerna version` has been run in some form (most commonly, during a run of
89100
`npm run publish:manual` that subsequently failed).
90101

91-
If this script fails, correct the error and re-run `npm run publish:prepare` and
102+
If this script fails, correct the error and re-run
92103
`npm run publish:unpublishedOnly`.
93104

94105
### `npm run publish:force`
95106

96-
This script assumes you have already run `npm run publish:prepare`. It will use lerna
107+
This script will first run `npm run publish:prepare`. It will use lerna
97108
to force publish all packages, even those that have not changed. You can use this
98109
if you run into publishing problems to recover from error states, but you should prefer
99110
to use `npm run publish:unpublishedOnly` if possible.
100111

101112
### `npm run publish:checkVersions`
102113

103-
This script assumes you have already run `npm run publish:prepare`. It will run `lerna
114+
This script will first run `npm run publish:prepare`. It will run `lerna
104115
version` to generate the new version numbers using conventional commits that would be
105116
created during a full publish action, but it will not actually push the changes nor
106117
create any tags. This can be used to check which plugins would be published and under

0 commit comments

Comments
 (0)