From 4dc3f2344db2fc6b1973ccf6df69f0fc239ba7f8 Mon Sep 17 00:00:00 2001 From: Chris Gervang Date: Tue, 21 May 2024 17:15:27 -0700 Subject: [PATCH] chore(core) publish NPM packages from CI Signed-off-by: Chris Gervang --- .github/workflows/release.yml | 68 +++++++++++++++++++++++++++++++++++ package.json | 5 +-- scripts/verify-changelog.js | 13 +++++++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 scripts/verify-changelog.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..8ab1d315 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: release + +on: + push: + tags: + - v* + +jobs: + check_branch: + runs-on: ubuntu-latest + outputs: + should_build: ${{ steps.permitted.outputs.result }} + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Fetch remote branches + run: | + git fetch origin --depth=1 + + - name: Check if on permitted branch + id: permitted + run: | + result= + branchName=$(git branch -a --contains $GITHUB_SHA | grep 'remotes/origin/' || echo "") + if [[ $branchName == *"master" || $branchName == *"-release" ]]; then + result=true + fi + echo "result=${result}" >> "$GITHUB_OUTPUT" + + release: + runs-on: ubuntu-latest + needs: check_branch + permissions: + contents: write + + if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_build }} + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} + + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Use Node.js + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 + with: + node-version: '18.x' + + - name: Create GitHub release entry + run: | + body=$(node scripts/github-release.js) && + curl \ + -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/visgl/deck.gl/releases \ + -d "${body}" \ + -H "Authorization: token ${GITHUB_TOKEN}" + + - name: Login to NPM + run: npm config set "//registry.npmjs.org/:_authToken=${NPM_ACCESS_TOKEN}" + + - name: Install dependencies + run: yarn + + - name: Publish to NPM + run: npx ocular-publish from-git diff --git a/package.json b/package.json index 066e5337..c310a170 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,11 @@ "bootstrap": "yarn && ocular-bootstrap", "clean": "ocular-clean", "build": "npm run clean && ocular-build && lerna run build", - "version": "ocular-build core", + "version": "node scripts/verify-changelog.js && git add CHANGELOG.md", "lint": "ocular-lint", "cover": "ocular-test cover", - "publish": "ocular-publish", + "publish-beta": "ocular-publish version-only-beta", + "publish-prod": "ocular-publish version-only-prod", "test": "ocular-test", "test-ci": "ocular-lint && ocular-test node && ocular-test cover", "test-fast": "ocular-test fast", diff --git a/scripts/verify-changelog.js b/scripts/verify-changelog.js new file mode 100644 index 00000000..db57c811 --- /dev/null +++ b/scripts/verify-changelog.js @@ -0,0 +1,13 @@ +/** + * Verifies that CHANGELOG has been updated before publishing a new version + */ +import {readFileSync} from 'fs'; + +const {version} = JSON.parse(readFileSync('lerna.json')); + +const changelog = readFileSync('CHANGELOG.md', 'utf-8'); +const header = changelog.match(new RegExp(`^###.*\\b${version}\\b.*$`, 'm')); +if (!header) { + console.error(`Cannot find an entry for ${version} in CHANGELOG.md`); + process.exit(1); +}