From a5f2b9faebe7b9f315a572916d9a80fa9c05471b Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 30 Jun 2024 15:15:11 +0200 Subject: [PATCH 1/2] Introduce a GitHub Actions workflow for publishing a release This commit migrates this functionality away from the bots. Note that the NPM token must be configured as a repository secret before this workflow can execute. The following resources are relevant for this patch: - Publishing packages to the NPM registry: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry - Creating secrets for a repository: https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository --- .github/workflows/publish_release.yml | 38 ++++++++++++++++++++++ gulpfile.mjs | 45 ++------------------------- 2 files changed, 40 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/publish_release.yml diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml new file mode 100644 index 0000000000000..741fdf0fb4a83 --- /dev/null +++ b/.github/workflows/publish_release.yml @@ -0,0 +1,38 @@ +name: Publish release +on: + release: + types: [published] +permissions: + contents: read + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [lts/*] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm install + + - name: Build the `pdfjs-dist` library + run: npx gulp dist + + - name: Publish the `pdfjs-dist` library to NPM + run: npm publish ./build/dist + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/gulpfile.mjs b/gulpfile.mjs index 58fc024049397..475c7bd3ea2be 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -2240,7 +2240,7 @@ function packageJson() { } gulp.task( - "dist-pre", + "dist", gulp.series( "generic", "generic-legacy", @@ -2368,7 +2368,7 @@ gulp.task( gulp.task( "dist-install", - gulp.series("dist-pre", function createDistInstall(done) { + gulp.series("dist", function createDistInstall(done) { let distPath = DIST_DIR; const opts = {}; const installPath = process.env.PDFJS_INSTALL_PATH; @@ -2381,47 +2381,6 @@ gulp.task( }) ); -gulp.task( - "dist", - gulp.series("dist-pre", function createDist(done) { - const VERSION = getVersionJSON().version; - - console.log(); - console.log("### Committing changes"); - - let reason = process.env.PDFJS_UPDATE_REASON; - // Attempt to work-around the broken link, see https://github.com/mozilla/pdf.js/issues/10391 - if (typeof reason === "string") { - const reasonParts = - /^(See )(mozilla\/pdf\.js)@tags\/(v\d+\.\d+\.\d+)\s*$/.exec(reason); - - if (reasonParts) { - reason = - reasonParts[1] + - "https://github.com/" + - reasonParts[2] + - "/releases/tag/" + - reasonParts[3]; - } - } - const message = - "PDF.js version " + VERSION + (reason ? " - " + reason : ""); - safeSpawnSync("git", ["add", "*"], { cwd: DIST_DIR }); - safeSpawnSync("git", ["commit", "-am", message], { cwd: DIST_DIR }); - safeSpawnSync("git", ["tag", "-a", "v" + VERSION, "-m", message], { - cwd: DIST_DIR, - }); - - console.log(); - console.log("Done. Push with"); - console.log( - " cd " + DIST_DIR + "; git push --tags " + DIST_REPO_URL + " master" - ); - console.log(); - done(); - }) -); - gulp.task( "mozcentralbaseline", gulp.series(createBaseline, function createMozcentralBaseline(done) { From dddb74d5e4d422b2be80ee93c26396830be2cfb3 Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Sun, 30 Jun 2024 15:47:14 +0200 Subject: [PATCH 2/2] Fix `npm publish` warnings about the `package.json` format This commit removes the following warnings from the `npm publish` output: ``` npm warn publish npm auto-corrected some errors in your package.json when publishing. Please run "npm pkg fix" to address these errors. npm warn publish errors corrected: npm warn publish Removed invalid "scripts" npm warn publish "repository.url" was normalized to "git+https://github.com/mozilla/pdfjs-dist.git" ``` For the "scripts" section it turns out that if the package doesn't have any scripts it's expected to explicitly set it to an empty object; refer to https://github.com/npm/cli/issues/6918 and https://github.com/denoland/dnt/pull/414. --- gulpfile.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gulpfile.mjs b/gulpfile.mjs index 475c7bd3ea2be..49dce5da39a68 100644 --- a/gulpfile.mjs +++ b/gulpfile.mjs @@ -2226,11 +2226,12 @@ function packageJson() { }, repository: { type: "git", - url: DIST_REPO_URL, + url: `git+${DIST_REPO_URL}.git`, }, engines: { node: ">=18", }, + scripts: {}, }; return createStringSource(