Skip to content

Commit cf8acd4

Browse files
authored
Create ci.yml
1 parent a6ad6ff commit cf8acd4

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

.github/workflows/ci.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
name: CI & Release
3+
4+
# Workflow name based on selected inputs. Fallback to default Github naming when expression evaluates to empty string
5+
run-name: >-
6+
${{
7+
inputs.release && inputs.test && 'Build ➤ Test ➤ Publish to NPM' ||
8+
inputs.release && !inputs.test && 'Build ➤ Skip Tests ➤ Publish to NPM' ||
9+
github.event_name == 'workflow_dispatch' && inputs.test && 'Build ➤ Test' ||
10+
github.event_name == 'workflow_dispatch' && !inputs.test && 'Build ➤ Skip Tests' ||
11+
''
12+
}}
13+
14+
on:
15+
pull_request:
16+
push:
17+
branches: [main]
18+
workflow_dispatch:
19+
inputs:
20+
test:
21+
description: 'Run tests'
22+
required: true
23+
default: true
24+
type: boolean
25+
release:
26+
description: 'Publish new release'
27+
required: true
28+
default: false
29+
type: boolean
30+
31+
concurrency:
32+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
33+
cancel-in-progress: true
34+
35+
jobs:
36+
build:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
40+
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
41+
with:
42+
cache: npm
43+
node-version: lts/*
44+
- run: npm ci
45+
- run: npm run typecheck
46+
if: github.event.inputs.test != 'false'
47+
- run: npm run prepublishOnly
48+
49+
test:
50+
needs: build
51+
if: github.event.inputs.test != 'false'
52+
runs-on: ${{ matrix.os }}
53+
strategy:
54+
fail-fast: false
55+
matrix:
56+
os: [macos-latest, ubuntu-latest, windows-latest]
57+
node: [lts/*]
58+
include:
59+
- os: ubuntu-latest
60+
node: lts/-2
61+
- os: ubuntu-latest
62+
node: current
63+
steps:
64+
- name: Set git to use LF
65+
if: matrix.os == 'windows-latest'
66+
run: |
67+
git config --global core.autocrlf false
68+
git config --global core.eol lf
69+
- uses: actions/checkout@v3
70+
- uses: actions/setup-node@v3
71+
with:
72+
cache: npm
73+
node-version: ${{ matrix.node }}
74+
- run: npm i
75+
- run: npm run build
76+
- run: npm test
77+
78+
release:
79+
needs: [build, test]
80+
# only run if opt-in during workflow_dispatch
81+
if: always() && github.event.inputs.release == 'true' && needs.build.result != 'failure' && needs.test.result != 'failure' && needs.test.result != 'cancelled'
82+
runs-on: ubuntu-latest
83+
steps:
84+
- uses: actions/checkout@v3
85+
with:
86+
# Need to fetch entire commit history to
87+
# analyze every commit since last release
88+
fetch-depth: 0
89+
- uses: actions/setup-node@v3
90+
with:
91+
cache: npm
92+
node-version: lts/*
93+
- run: npm ci
94+
# Branches that will release new versions are defined in .releaserc.json
95+
- run: npx semantic-release
96+
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
97+
# e.g. git tags were pushed but it exited before `npm publish`
98+
if: always()
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
102+
# Re-run semantic release with rich logs if it failed to publish for easier debugging
103+
- run: npx semantic-release --dry-run --debug
104+
if: failure()
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

0 commit comments

Comments
 (0)