From 125a822d1dc338161018105637669568f6c4e98d Mon Sep 17 00:00:00 2001 From: Don McCurdy Date: Wed, 2 Oct 2024 12:27:32 -0400 Subject: [PATCH] chore(release): v0.2.1-alpha.12 (#19) --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 26 +++++++++++++++----------- package.json | 8 +++++--- scripts/postversion-commit.js | 26 +++++++++++++------------- yarn.lock | 3 ++- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a49d675..dd2ba4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,5 +55,5 @@ jobs: if: | github.ref == 'ref/head/main' && github.event_name == 'push' && - contains(github.event.head_commit.message, 'chore(release)') + startsWith(github.event.head_commit.message, 'chore(release)') uses: ./.github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e81b3a9..a9f762b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,21 +11,25 @@ jobs: name: Release runs-on: ubuntu-22.04 + # Fetching tags: https://stackoverflow.com/a/76181083 steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 10 + fetch-tags: true - - name: Retrieve version - id: version - run: | - echo "TAG_NAME=$(git tag --points-at HEAD)" >> $GITHUB_OUTPUT - - # - uses: actions-ecosystem/action-get-latest-tag@v1 - # id: version + # Step output: https://stackoverflow.com/a/65616499 + # Reading latest tag: https://stackoverflow.com/a/33733020 + - name: Read git tag + id: git-tag + run: echo "TAG_NAME=$(git tag --points-at HEAD)" >> $GITHUB_OUTPUT - # - name: Validate version from git tag - # if: steps.version.outputs.is_valid != 'true' - # run: echo "Tag must follow SemVer convention. Aborting." && exit 1 + - name: Verify git tag + env: + GIT_TAG: ${{ steps.git-tag.outputs.TAG_NAME }} + if: startsWith(env.GIT_TAG, 'v') == false + run: echo "Missing or invalid git tag; aborting" && exit 1 - name: Set up Node.js ${{ env.NODE_VERSION }} uses: actions/setup-node@v4 @@ -38,7 +42,7 @@ jobs: with: result-encoding: string script: | - const gitTag = '${{ steps.version.outputs.TAG_NAME }}' + const gitTag = '${{ steps.git-tag.outputs.TAG_NAME }}' console.log(`git tag: ${gitTag}`) if (gitTag.match(/^v\d+\.\d+\.\d+$/)) { distTag = 'latest' diff --git a/package.json b/package.json index e4366a5..cefadbf 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "repository": "github:CartoDB/carto-api-client", "author": "Don McCurdy ", "packageManager": "yarn@4.3.1", - "version": "0.2.0", + "version": "0.2.1-alpha.12", "license": "MIT", "publishConfig": { "access": "public", @@ -40,7 +40,7 @@ "clean": "rimraf build/*", "postversion": "yarn postversion:check && yarn postversion:commit && yarn postversion:push", "postversion:check": "yarn lint && yarn test", - "postversion:commit": "VERSION=v$npm_package_version && node scripts/postversion-commit.js", + "postversion:commit": "node scripts/postversion-commit.js", "postversion:push": "git push && git push --tags", "prepublish": "yarn lint && yarn test", "prepack": "yarn clean && yarn build" @@ -84,6 +84,7 @@ "react-dom": "^18.3.1", "react-map-gl": "^7.1.7", "rimraf": "^3.0.2", + "semver": "^7.6.3", "svelte": "^4.2.17", "typescript": "~5.3.3", "vite": "^5.2.10", @@ -97,5 +98,6 @@ "@turf/invariant": "^7.1.0", "@turf/union": "^7.1.0", "@types/geojson": "^7946.0.14" - } + }, + "stableVersion": "0.2.0" } diff --git a/scripts/postversion-commit.js b/scripts/postversion-commit.js index 2482221..9bf4bf5 100644 --- a/scripts/postversion-commit.js +++ b/scripts/postversion-commit.js @@ -1,27 +1,27 @@ import {execSync} from 'node:child_process'; -import assert from 'node:assert/strict'; +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. */ -const version = process.env.VERSION; - -assert.match( - version, - /^v\d+\.\d+\.\d+[a-zA-Z0-9\._-]*$/, - 'Missing or invalid process.env.VERSION' -); - -const currentBranch = execSync('git rev-parse --abbrev-ref HEAD') - .toString() - .trim(); +// 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}"`); +} -if (currentBranch === 'main') { +// 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 ac00547..1075605 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1486,6 +1486,7 @@ __metadata: react-dom: "npm:^18.3.1" react-map-gl: "npm:^7.1.7" rimraf: "npm:^3.0.2" + semver: "npm:^7.6.3" svelte: "npm:^4.2.17" typescript: "npm:~5.3.3" vite: "npm:^5.2.10" @@ -8760,7 +8761,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.3.5, semver@npm:^7.5.3, semver@npm:^7.5.4": +"semver@npm:^7.3.5, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.3": version: 7.6.3 resolution: "semver@npm:7.6.3" bin: