Skip to content

Release

Release #5

Workflow file for this run

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:
# 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
id: version
run: echo "PKG_VERSION=v$(npm pkg get version -w @carto/create-react | jq '.[]' | xargs)" >> $GITHUB_OUTPUT
- name: Read git tag
id: git-tag
run: echo "GIT_TAG=$(git tag --points-at HEAD)" >> $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
# 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 }}
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
# Git tags are required for 'lerna publish from-git', so if the tag is
# missing (as after a pull request merge), we need to re-create it.
# TODO: Consider `git push --tags`?
- name: Update git tag
if: '!${{ steps.git-tag.outputs.GIT_TAG }}'
env:
PKG_VERSION: ${{ steps.version.outputs.PKG_VERSION }}
run: |
git tag -a ${PKG_VERSION} -m ${PKG_VERSION}
- name: Publish
env:
DIST_TAG: ${{ steps.dist-tag.outputs.result }}
run: |
yarn lerna publish from-git --yes --dist-tag ${DIST_TAG}