-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (73 loc) · 2.89 KB
/
main.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
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
env:
# Setting an environment variable with the value of a configuration variable
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PACKAGE_NAME: 'unknown'
PACKAGE_VERSION: 'unknown'
NPM: 'pnpm'
NPM_VERSION: 'unknown'
HAVE_COVERAGE_SCRIPT: false
HAVE_VALIDATE_SCRIPT: false
HAVE_LINT_SCRIPT: false
HAVE_UNIT_TEST_SCRIPT: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: dcarbone/install-jq-action@v2
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
if: env.NPM == 'pnpm'
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Read package information
run: |
echo "PACKAGE_NAME=$(cat package.json | jq -r .name)" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV
echo "HAVE_COVERAGE_SCRIPT=$(jq 'if .scripts.coverage == null then false else true end' package.json)" >> $GITHUB_ENV
echo "HAVE_VALIDATE_SCRIPT=$(jq 'if .scripts.validate == null then false else true end' package.json)" >> $GITHUB_ENV
echo "HAVE_LINT_SCRIPT=$(jq 'if .scripts.lint == null then false else true end' package.json)" >> $GITHUB_ENV
echo "HAVE_UNIT_TEST_SCRIPT=$(jq 'if .scripts.test == null then false else true end' package.json)" >> $GITHUB_ENV
- name: Get current npmjs version for ${{env.PACKAGE_NAME}}
run: |
echo "NPM_VERSION=$(curl -s https://registry.npmjs.org/${{ env.PACKAGE_NAME }} | jq -r '."dist-tags".latest')" >> $GITHUB_ENV
- name: Install dependencies
run: ${{ env.NPM }} install
- name: Run validate
if: env.HAVE_VALIDATE_SCRIPT == 'true'
run: ${{ env.NPM }} run validate
- name: Run unit tests
if: env.HAVE_UNIT_TEST_SCRIPT == 'true'
run: ${{ env.NPM }} test
- name: Run linter checks
if: env.HAVE_LINT_SCRIPT == 'true'
run: ${{ env.NPM }} run lint
- name: Run and publish code coverage
if: |
github.ref == 'refs/heads/master' &&
env.CC_TEST_REPORTER_ID != '' &&
env.HAVE_COVERAGE_SCRIPT == 'true'
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ env.CC_TEST_REPORTER_ID }}
with:
coverageCommand: ${{ env.NPM }} run coverage
# npm publish when PR done
- name: Publish ${{env.PACKAGE_NAME}} ${{env.PACKAGE_VERSION}}
run: ${{ env.NPM }} publish --no-git-checks --access public
if: |
github.ref == 'refs/heads/master' &&
env.NPM_TOKEN != '' &&
env.PACKAGE_VERSION != env.NPM_VERSION
env:
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}