Skip to content

Commit

Permalink
Merge pull request #6 from CartoDB/feature/sc-420243/ci-configuration
Browse files Browse the repository at this point in the history
🛠️ Automatically publish releases to NPM
  • Loading branch information
miguelangelmorenochacon authored Jul 17, 2024
2 parents a22bd8a + 9533457 commit c8a0cc2
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 24 deletions.
104 changes: 81 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,105 @@ name: CI
on:
push:
branches: [main]
tags: ['*']

pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
name: Build [Node.js ${{ matrix.node-version }}]
runs-on: ubuntu-22.04

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
include:
- node-version: 18.x
publish: false
- node-version: 20.x
publish: true # Publish on npm
- node-version: 22.x
publish: false

env:
CI: true

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
- name: Checkout
uses: actions/checkout@v4

##########################################################################
# Build
##########################################################################

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: corepack enable
- run: yarn install
- run: yarn build
- run: yarn test

lint:
runs-on: ubuntu-latest
- name: Enable Corepack
run: corepack enable

strategy:
matrix:
node-version: [22.x]
- name: Install
run: yarn install

env:
CI: true
- name: Lint
run: yarn lint

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- name: Build
run: yarn build

- name: Test
run: yarn test

##########################################################################
# Publish
##########################################################################

- name: Check tag format
id: check-tag-format
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
uses: nowsprinting/check-version-format-action@v4

- name: Exit on invalid tag format
if: startsWith(github.ref, 'refs/tags/') && !steps.check-tag-format.outputs.is_valid && matrix.publish
run: echo "Tag must follow SemVer convention. Aborting." && exit 1

- name: Get release type
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
id: get-release-type
uses: actions/github-script@v7
with:
node-version: ${{ matrix.node-version }}
- run: corepack enable
- run: yarn install
- run: yarn lint
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'
} else {
releaseType = releaseTypeMatch[0]
}
console.log(`Release type: ${releaseType}`)
return releaseType
# This may indicate that the tag set has a typo, e.g., alpah, betta, etc.
- name: Verify tag format
if: !steps.check-tag-format.outputs.is_stable && steps.get-release-type.outputs.result == 'latest'
run: echo "Tag set may be incorrect. Please, review" && exit 1

- name: Configure yarn to publish packages
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
env:
# The following token has been manually issued in the CartoDB
# organization for npmjs.com
NODE_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }}
run: |
yarn config set npmPublishRegistry "https://registry.npmjs.org/"
yarn config set npmAuthToken "${NODE_AUTH_TOKEN}"
- name: Publish package
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
env:
RELEASE_TYPE: ${{ steps.get-release-type.outputs.result }}
run: yarn npm publish --tag ${RELEASE_TYPE}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carto/api-client",
"version": "0.0.1-2",
"version": "0.0.35",
"publishConfig": {
"access": "public",
"tag": "alpha"
Expand Down

0 comments on commit c8a0cc2

Please sign in to comment.