Skip to content

Commit

Permalink
chore(release): v0.2.1-alpha.12 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Oct 2, 2024
1 parent 31a49ec commit 125a822
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 15 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"repository": "github:CartoDB/carto-api-client",
"author": "Don McCurdy <[email protected]>",
"packageManager": "[email protected]",
"version": "0.2.0",
"version": "0.2.1-alpha.12",
"license": "MIT",
"publishConfig": {
"access": "public",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -97,5 +98,6 @@
"@turf/invariant": "^7.1.0",
"@turf/union": "^7.1.0",
"@types/geojson": "^7946.0.14"
}
},
"stableVersion": "0.2.0"
}
26 changes: 13 additions & 13 deletions scripts/postversion-commit.js
Original file line number Diff line number Diff line change
@@ -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}`);
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 125a822

Please sign in to comment.