-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (105 loc) · 4.11 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: CI
on:
push:
branches: [main]
tags: ["*"]
pull_request:
branches: [main]
jobs:
build:
name: Build [Node.js ${{ matrix.node-version }}]
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- node-version: 18.x
publish: false
- node-version: 20.x
publish: true # TODO
- node-version: 22.x
publish: false
env:
CI: true
steps:
- 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 }}
- name: Enable Corepack
run: corepack enable
- name: Install
run: yarn install
- name: Lint
run: yarn lint
- 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:
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'
} else {
releaseType = releaseTypeMatch[0]
}
console.log(`Release type: ${releaseType}`)
return releaseType
- name: Set version from tag to environment variable
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
# TODO: Enable after reaching 1.0.0.
# 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 == 'false' && steps.get-release-type.outputs.result == 'latest'
# run: echo "Tag set may be incorrect. Please, review" && exit 1
# - name: Reset changes
# if: startsWith(github.ref, 'refs/tags/') && matrix.publish
# run: git reset --hard HEAD
- name: Ignore changes to .yarnrc.yml
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
run: git update-index --assume-unchanged .yarnrc.yml
- name: Configure yarn to publish packages
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }}
run: |
# Yarn config
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
- name: Publish package with Lerna
if: startsWith(github.ref, 'refs/tags/') && matrix.publish
env:
RELEASE_TYPE: ${{ steps.get-release-type.outputs.result }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_CARTODB_AUTH_TOKEN }}
run: |
set -x
yarn lerna publish from-git --yes --dist-tag ${RELEASE_TYPE} --loglevel verbose