Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): Update build system #17

Merged
merged 8 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

env:
CI: true

jobs:
##########################################################################
# Build
##########################################################################

build:
name: Build [Node.js ${{ matrix.node-version }}]
runs-on: ubuntu-22.04

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install
run: |
corepack enable
yarn install

- name: Lint
run: yarn lint

- name: Build
run: yarn build

- name: Test
run: yarn test

##########################################################################
# Release precheck
##########################################################################

release_precheck:
name: 'Release (precheck)'
needs: build
if: |
github.ref_name == 'master' &&
startsWith(github.event.head_commit.message, 'chore(release)')
uses: ./.github/workflows/release.yml
secrets: inherit
71 changes: 71 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Release

on:
workflow_call:
secrets:
NPM_CARTODB_AUTH_TOKEN:
required: true
workflow_dispatch:

env:
NODE_VERSION: 20
CI: true

jobs:
release:
name: Release
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4

# Read version from 'package.json'; git tags are lost on a merged PR.
- name: Read package version
id: version
run: echo "PKG_VERSION=v$(npm pkg get version | xargs)" >> $GITHUB_OUTPUT

- name: Set up Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

# Determine whether to tag the release as 'latest' or 'alpha'.
- name: Assign dist tag
id: dist-tag
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const version = '${{ steps.version.outputs.PKG_VERSION }}'
console.log(`version: ${version}`)
if (version.match(/^v\d+\.\d+\.\d+$/)) {
distTag = 'latest'
} else if (version.match(/^v\d+\.\d+\.\d+/)) {
distTag = 'alpha'
} else {
core.setFailed('Version must follow SemVer convention. Aborting.');
}
console.log(`npm dist tag: ${distTag}`)
return distTag

- name: Install
run: |
corepack enable
yarn install

# Build. Tests are run automatically by `yarn prepublish`.
- name: Build
run: yarn build

- name: Configure yarn to publish packages
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }}
run: |
yarn config set npmPublishRegistry "https://registry.npmjs.org/"
yarn config set npmAuthToken "${NPM_AUTH_TOKEN}"

- name: Publish
env:
DIST_TAG: ${{ steps.dist-tag.outputs.result }}
run: yarn npm publish --tag ${DIST_TAG}
34 changes: 0 additions & 34 deletions .github/workflows/test.yml

This file was deleted.

11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ test/**/*-failed.png

tsconfig.tsbuildinfo

dist-demo/
dist-bundle.js

test/**/yarn.lock
yarn-error.log
package-lock.json

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

.vscode/
.project
.idea
Expand Down
17 changes: 0 additions & 17 deletions .ocularrc.js

This file was deleted.

1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
19 changes: 17 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Contributing

_Contributions are subject to CARTO's [community contributions policy](https://carto.com/contributions/)._

## Local development requirements

- Yarn v4+
- Node.js v18+

## Quickstart

To install and build `quadbin-js` locally from source:
Expand All @@ -19,6 +28,12 @@ yarn test

## Releases

1. Create a new version: `yarn version [ major | minor | patch | prerelease ]`
1. Update changelog

2. Create a new version: `yarn version [ major | minor | patch | prerelease ]`

3. Commit, tag, and push to GitHub: `yarn postversion`

2. Execute `yarn publish`
4. Publish
- If working on `master`, the previous step will automatically create and push a branch. Open a pull request, get any required approvals, and merge. Merged pull requests with commit messages beginning `chore(release)` will trigger a release automatically.
- If working on a branch, a commit for the release will be pushed to the branch. You'll then need to [manually run a workflow](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow), “Release”, selecting the target branch in the menu.
63 changes: 34 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
"description": "Utility functions for working with Quadbins",
"license": "MIT",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"umd:main": "dist/umd/index.js",
"types": "dist/types/index.d.ts",
"source": "./src/index.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.esm.js",
"umd:main": "./dist/index.umd.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs"
},
"./*": "./*"
},
Expand All @@ -26,43 +27,47 @@
"url": "https://github.com/CartoDB/quadbin-js.git"
},
"scripts": {
"clean": "rm -rf dist/*",
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types && yarn build:umd",
"build:cjs": "tsc -p tsconfig/tsconfig.cjs.json && mv dist/cjs/index.js dist/cjs/index.cjs",
"build:esm": "tsc -p tsconfig/tsconfig.esm.json",
"build:types": "tsc -p tsconfig/tsconfig.types.json",
"build:umd": "webpack --config tsconfig/webpack.config.cjs",
"clean": "rm -rf \"dist/*\"",
"build": "microbundle --name quadbin --format cjs,modern,umd --no-compress",
"build:watch": "microbundle watch --name quadbin --format cjs,modern,umd --no-compress",
"lint": "prettier --check src",
"test": "yarn lint && yarn test-fast",
"test-fast": "ts-node node_modules/tape/bin/tape test/**/*.spec.js",
"prepublishOnly": "yarn build"
"test-fast": "tsx node_modules/tape/bin/tape test/**/*.spec.js",
"postversion": "yarn postversion:check && yarn postversion:commit && yarn postversion:push",
"postversion:check": "yarn lint && yarn test",
"postversion:commit": "node scripts/postversion-commit.js",
"postversion:push": "git push && git push --tags",
"prepublish": "yarn lint && yarn test",
"prepack": "yarn clean && yarn build"
},
"browser": {
"jsdom": false
},
"devDependencies": {
"@babel/register": "^7.13.0",
"@types/geojson": "^7946.0.14",
"babel-loader": "^8.0.0",
"babel-preset-minify": "^0.5.0",
"prettier": "^2.4.1",
"@types/geojson": "^7946.0.15",
"@types/semver": "^7",
"microbundle": "^0.15.1",
"prettier": "^3.4.2",
"semver": "^7.6.3",
"tape": "^5.3.0",
"ts-loader": "^9.2.5",
"ts-node": "^10.9.2",
"typescript": "^4.4.4",
"webpack": "^5.52.1",
"webpack-cli": "^4.8.0"
"tsx": "^4.19.2",
"typescript": "^5.7.3"
},
"engines": {
"node": ">=14"
"node": ">=18"
},
"browserslist": [
"defaults",
"not IE 11",
"node >= 18"
],
"dependencies": {
"@mapbox/tile-cover": "3.0.1",
"@math.gl/web-mercator": "^4.1.0"
},
"packageManager": "yarn@1.22.22",
"packageManager": "yarn@4.3.1",
"volta": {
"node": "14.21.3",
"yarn": "1.22.22"
"node": "20.18.2",
"yarn": "4.3.1"
}
}
27 changes: 27 additions & 0 deletions scripts/postversion-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {execSync} from 'node:child_process';
import {readFile} from 'node:fs/promises';
import {resolve} from 'node:path';
import {valid} from 'semver';

/**
* Utility for committing and tagging a release commit in
* git, called as part of the `yarn postversion` script.
*/

// Read and validate pkg.version.
const pkgJSON = await readFile(resolve('./package.json'), 'utf-8');
const version = 'v' + JSON.parse(pkgJSON).version;
if (!valid(version)) {
throw new Error(`Invalid version, "${version}"`);
}

// Check out a branch if cutting a version from 'main'.
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
if (branch === 'main') {
execSync(`git checkout -b 'release/${version}'`);
}

// Commit and tag.
execSync('git add -u');
execSync(`git commit -m 'chore(release): ${version}'`);
execSync(`git tag -a ${version} -m ${version}`);
12 changes: 6 additions & 6 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ test('Quadbin getParent', async t => {
});

// Zoom:26 test not agreeing with Python
import PointGeometry from './data/PointGeometry.json' assert {type: 'json'};
import MultiPointGeometry from './data/MultiPointGeometry.json' assert {type: 'json'};
import LineStringGeometry from './data/LineStringGeometry.json' assert {type: 'json'};
import PolygonGeometry from './data/PolygonGeometry.json' assert {type: 'json'};
import PolygonAntimeridianGeometry from './data/PolygonAntimeridianGeometry.json' assert {type: 'json'};
import MultiPolygonGeometry from './data/MultiPolygonGeometry.json' assert {type: 'json'};
import PointGeometry from './data/PointGeometry.json' with {type: 'json'};
import MultiPointGeometry from './data/MultiPointGeometry.json' with {type: 'json'};
import LineStringGeometry from './data/LineStringGeometry.json' with {type: 'json'};
import PolygonGeometry from './data/PolygonGeometry.json' with {type: 'json'};
import PolygonAntimeridianGeometry from './data/PolygonAntimeridianGeometry.json' with {type: 'json'};
import MultiPolygonGeometry from './data/MultiPolygonGeometry.json' with {type: 'json'};
const testCases = [
PointGeometry,
MultiPointGeometry,
Expand Down
10 changes: 0 additions & 10 deletions tsconfig.build.json

This file was deleted.

8 changes: 0 additions & 8 deletions tsconfig/tsconfig.cjs.json

This file was deleted.

Loading