-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): Allow publish by workflow dispatch or PR merge (#16)
- Loading branch information
1 parent
d77361e
commit 8c854da
Showing
2 changed files
with
62 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,74 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: ['*'] | ||
workflow_call: | ||
secrets: | ||
NPM_CARTODB_AUTH_TOKEN: | ||
required: true | ||
workflow_dispatch: | ||
|
||
env: | ||
NODE_VERSION: 20 | ||
CI: true | ||
|
||
jobs: | ||
release: | ||
name: Release [Node.js ${{ matrix.node-version }}] | ||
name: Release | ||
runs-on: ubuntu-22.04 | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
env: | ||
CI: true | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
########################################################################## | ||
# Build | ||
########################################################################## | ||
# 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: Set up Node.js ${{ matrix.node-version }} | ||
- name: Set up Node.js ${{ env.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 | ||
node-version: ${{ env.NODE_VERSION }} | ||
|
||
- name: Test | ||
run: yarn test | ||
|
||
########################################################################## | ||
# Publish | ||
########################################################################## | ||
|
||
- name: Check tag format | ||
id: check-tag-format | ||
uses: nowsprinting/check-version-format-action@v4 | ||
|
||
- name: Exit on invalid tag format | ||
if: '!steps.check-tag-format.outputs.is_valid' | ||
run: echo "Tag must follow SemVer convention. Aborting." && exit 1 | ||
|
||
- name: Get release type | ||
id: get-release-type | ||
# 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 regex = /(alpha|beta)/ | ||
const refName = context.ref.replace('refs/tags/', '') | ||
console.log(`Ref tag: ${refName}`) | ||
const releaseTypeMatch = refName.match(regex) | ||
if (!releaseTypeMatch) { | ||
releaseType = 'latest' | ||
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 { | ||
releaseType = releaseTypeMatch[0] | ||
core.setFailed('Version must follow SemVer convention. Aborting.'); | ||
} | ||
console.log(`Release type: ${releaseType}`) | ||
return releaseType | ||
console.log(`npm dist tag: ${distTag}`) | ||
return distTag | ||
- name: Set version from tag to environment variable | ||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | ||
- name: Install | ||
run: | | ||
corepack enable | ||
yarn install | ||
- name: Ignore changes to .yarnrc.yml | ||
run: git update-index --assume-unchanged .yarnrc.yml | ||
# Build. Tests are run automatically by `yarn prepublish`. | ||
- name: Build | ||
run: yarn build | ||
|
||
- name: Configure yarn to publish packages | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }} | ||
NPM_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }} | ||
# Ignore changes to .yarnrc.yml, see https://github.com/lerna/lerna/issues/2329 | ||
run: | | ||
# Yarn config | ||
git update-index --assume-unchanged .yarnrc.yml | ||
yarn config set npmPublishRegistry "https://registry.npmjs.org/" | ||
yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" | ||
# Create .npmrc file | ||
echo "@carto:registry=https://registry.npmjs.org/" > .npmrc | ||
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc | ||
# Check configuration | ||
npm config get registry | ||
npm view @carto/create-common versions | ||
yarn config set npmAuthToken "${NPM_AUTH_TOKEN}" | ||
- name: Publish package with Lerna | ||
- name: Publish | ||
env: | ||
RELEASE_TYPE: ${{ steps.get-release-type.outputs.result }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }} | ||
DIST_TAG: ${{ steps.dist-tag.outputs.result }} | ||
run: | | ||
set -x | ||
yarn lerna publish from-git --yes --dist-tag ${RELEASE_TYPE} --loglevel verbose | ||
yarn lerna publish from-git --yes --dist-tag ${DIST_TAG} |