diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8cf6535..59407f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,8 +17,12 @@ jobs: runs-on: ubuntu-22.04 steps: + # Lerna needs Git tags. https://stackoverflow.com/a/76181083 - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 10 + fetch-tags: true # Read version from 'package.json'; git tags are lost on a merged PR. - name: Read package version @@ -58,15 +62,26 @@ jobs: - name: Build run: yarn build + # TODO: Why do both .npmrc and .yarnrc.yml need updates? - name: Configure yarn to publish packages env: NPM_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }} - # Ignore changes to .yarnrc.yml, see https://github.com/lerna/lerna/issues/2329 run: | + # Ignore changes to .yarnrc.yml, see https://github.com/lerna/lerna/issues/2329 git update-index --assume-unchanged .yarnrc.yml + + # Update .yarnrc.yml yarn config set npmPublishRegistry "https://registry.npmjs.org/" yarn config set npmAuthToken "${NPM_AUTH_TOKEN}" + # Create .npmrc + echo "@carto:registry=https://registry.npmjs.org/" > .npmrc + echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" >> .npmrc + + # Check configuration + npm config get registry + npm view @carto/create-common versions + - name: Publish env: DIST_TAG: ${{ steps.dist-tag.outputs.result }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 10cf687..a93c9c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,9 +33,12 @@ During local development, CSS styles are loaded from a shared `style.css` in the All packages are published together. To create a standard release: -1. Update changelog +1. Update changelog and commit changes -2. Create a new version: +2. Create a new version: `yarn lerna version [ major | minor | patch | prerelease ]` -- Release: `yarn lerna publish [ patch | minor | major ] --force-publish "*"` -- Prerelease: `yarn lerna publish prerelease --dist-tag alpha --force-publish "*"` +3. Push to GitHub: `yarn postversion` + +4. Publish + - If working on `main`, 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. diff --git a/lerna.json b/lerna.json index b3fc778..e98a63e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,15 @@ { "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "0.1.2-alpha.0", - "packages": ["packages/*"], - "npmClient": "yarn" -} + "version": "0.1.2-alpha.7", + "packages": [ + "packages/*" + ], + "npmClient": "yarn", + "command": { + "version": { + "message": "chore(release): %s", + "push": false, + "gitTagVersion": false + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6b3207e..63fa0ce 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,12 @@ "lint": "lerna run lint", "test": "lerna run test", "clean": "rimraf --glob 'packages/*/dist/*' 'sandbox/*'", - "preversion": "yarn lint", - "version": "yarn clean && yarn build", - "postversion": "git push && git push --tags" + "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" }, "devDependencies": { "@types/meow": "^6.0.0", diff --git a/packages/create-angular/package.json b/packages/create-angular/package.json index a4b6522..33173f9 100644 --- a/packages/create-angular/package.json +++ b/packages/create-angular/package.json @@ -4,7 +4,7 @@ "repository": "github:CartoDB/carto-app-templates", "author": "Don McCurdy ", "license": "MIT", - "version": "0.1.2-alpha.0", + "version": "0.1.2-alpha.7", "type": "module", "bin": "./scripts/create.js", "scripts": { @@ -25,7 +25,7 @@ "@angular/router": "^18.2.5", "@auth0/auth0-angular": "^2.2.3", "@carto/api-client": "^0.2.1", - "@carto/create-common": "^0.1.2-alpha.0", + "@carto/create-common": "^0.1.2-alpha.7", "@deck.gl/aggregation-layers": "^9.0.24", "@deck.gl/carto": "^9.0.24", "@deck.gl/core": "^9.0.24", diff --git a/packages/create-common/package.json b/packages/create-common/package.json index 6af577b..f65386f 100644 --- a/packages/create-common/package.json +++ b/packages/create-common/package.json @@ -2,7 +2,7 @@ "name": "@carto/create-common", "packageManager": "yarn@4.2.2", "author": "Don McCurdy ", - "version": "0.1.2-alpha.0", + "version": "0.1.2-alpha.7", "license": "MIT", "type": "module", "sideEffects": false, diff --git a/packages/create-react/package.json b/packages/create-react/package.json index 3d9f667..de10e10 100644 --- a/packages/create-react/package.json +++ b/packages/create-react/package.json @@ -4,7 +4,7 @@ "repository": "github:CartoDB/carto-app-templates", "author": "Don McCurdy ", "license": "MIT", - "version": "0.1.2-alpha.0", + "version": "0.1.2-alpha.7", "type": "module", "bin": "./scripts/create.js", "scripts": { @@ -17,7 +17,7 @@ "dependencies": { "@auth0/auth0-react": "^2.2.4", "@carto/api-client": "^0.2.1", - "@carto/create-common": "^0.1.2-alpha.0", + "@carto/create-common": "^0.1.2-alpha.7", "@deck.gl/aggregation-layers": "^9.0.24", "@deck.gl/carto": "^9.0.24", "@deck.gl/core": "^9.0.24", diff --git a/packages/create-vue/package.json b/packages/create-vue/package.json index fc4aa16..d92875a 100644 --- a/packages/create-vue/package.json +++ b/packages/create-vue/package.json @@ -4,7 +4,7 @@ "repository": "github:CartoDB/carto-app-templates", "author": "Don McCurdy ", "license": "MIT", - "version": "0.1.2-alpha.0", + "version": "0.1.2-alpha.7", "type": "module", "bin": "./scripts/create.js", "scripts": { @@ -16,7 +16,7 @@ "dependencies": { "@auth0/auth0-vue": "^2.3.3", "@carto/api-client": "^0.2.1", - "@carto/create-common": "^0.1.2-alpha.0", + "@carto/create-common": "^0.1.2-alpha.7", "@deck.gl/aggregation-layers": "^9.0.24", "@deck.gl/carto": "^9.0.24", "@deck.gl/core": "^9.0.24", diff --git a/scripts/postversion-commit.js b/scripts/postversion-commit.js new file mode 100644 index 0000000..865a623 --- /dev/null +++ b/scripts/postversion-commit.js @@ -0,0 +1,30 @@ +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('./packages/create-react/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}`); diff --git a/yarn.lock b/yarn.lock index 09ef7db..fb810a9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2442,7 +2442,7 @@ __metadata: "@angular/router": "npm:^18.2.5" "@auth0/auth0-angular": "npm:^2.2.3" "@carto/api-client": "npm:^0.2.1" - "@carto/create-common": "npm:^0.1.2-alpha.0" + "@carto/create-common": "npm:^0.1.2-alpha.7" "@deck.gl/aggregation-layers": "npm:^9.0.24" "@deck.gl/carto": "npm:^9.0.24" "@deck.gl/core": "npm:^9.0.24" @@ -2464,7 +2464,7 @@ __metadata: languageName: unknown linkType: soft -"@carto/create-common@npm:^0.1.2-alpha.0, @carto/create-common@workspace:packages/create-common": +"@carto/create-common@npm:^0.1.2-alpha.7, @carto/create-common@workspace:packages/create-common": version: 0.0.0-use.local resolution: "@carto/create-common@workspace:packages/create-common" dependencies: @@ -2484,7 +2484,7 @@ __metadata: dependencies: "@auth0/auth0-react": "npm:^2.2.4" "@carto/api-client": "npm:^0.2.1" - "@carto/create-common": "npm:^0.1.2-alpha.0" + "@carto/create-common": "npm:^0.1.2-alpha.7" "@deck.gl/aggregation-layers": "npm:^9.0.24" "@deck.gl/carto": "npm:^9.0.24" "@deck.gl/core": "npm:^9.0.24" @@ -2524,7 +2524,7 @@ __metadata: dependencies: "@auth0/auth0-vue": "npm:^2.3.3" "@carto/api-client": "npm:^0.2.1" - "@carto/create-common": "npm:^0.1.2-alpha.0" + "@carto/create-common": "npm:^0.1.2-alpha.7" "@deck.gl/aggregation-layers": "npm:^9.0.24" "@deck.gl/carto": "npm:^9.0.24" "@deck.gl/core": "npm:^9.0.24"