From 669685ed4052353725cb92df8a4c1e07c4128808 Mon Sep 17 00:00:00 2001 From: alina sireneva Date: Sun, 24 Mar 2024 01:31:44 +0300 Subject: [PATCH] ci: improved release flow --- .github/workflows/release.yaml | 10 ++++++---- scripts/publish.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5b0746a6..17efe2ff 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -35,6 +35,8 @@ jobs: git config user.name "mtcute-bot" git config user.email mtcute-bot@tei.su npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} + - name: Verify NPM token + run: npm whoami - name: Find packages to publish id: find run: node scripts/find-updated-packages.js ${{ inputs.kind }} ${{ inputs.packages }} @@ -44,15 +46,15 @@ jobs: - name: Bump versions id: bump run: node scripts/bump-version.js ${{ inputs.kind }} ${{ steps.find.outputs.modified }} - - name: Commit version bumps - run: | - git commit -am "v${{ steps.bump.outputs.version }}" - git push - name: Build packages and publish to NPM id: build env: GH_RELEASE: 1 run: node scripts/publish.js ${{ steps.find.outputs.modified }} + - name: Commit version bumps + run: | + git commit -am "v${{ steps.bump.outputs.version }}" + git push - name: GitHub Release uses: ncipollo/release-action@v1 with: diff --git a/scripts/publish.js b/scripts/publish.js index 305e30ec..a7399cf2 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -91,6 +91,7 @@ async function main(arg = process.argv[2]) { console.log('[i] Using registry %s', REGISTRY) const publishedPkgs = [] + const failedPkgs = [] if (arg === 'all' || arg === 'updated') { for (const pkg of listPackages()) { @@ -102,16 +103,37 @@ async function main(arg = process.argv[2]) { continue } - await publishSinglePackage(pkg) - publishedPkgs.push(pkg) + try { + await publishSinglePackage(pkg) + publishedPkgs.push(pkg) + } catch (e) { + console.error('[!] Failed to publish %s:', pkg) + console.error(e) + failedPkgs.push(pkg) + } } } else { for (const pkg of arg.split(',')) { - await publishSinglePackage(pkg) - publishedPkgs.push(pkg) + try { + await publishSinglePackage(pkg) + publishedPkgs.push(pkg) + } catch (e) { + console.error('[!] Failed to publish %s:', pkg) + console.error(e) + failedPkgs.push(pkg) + } } } + if (failedPkgs.length > 0) { + console.error('[!] Failed to publish packages:') + + for (const pkg of failedPkgs) { + console.error(' - %s', pkg) + } + process.exit(1) + } + if (process.env.GH_RELEASE) { // we should also generate tgz files for all published packages // for a github release, and also generate a title