-
Notifications
You must be signed in to change notification settings - Fork 8
157 lines (137 loc) · 5.24 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: ci
on:
push:
branches:
- master
- 1.[0-9]+.x
tags:
- "*"
pull_request:
branches:
- master
- 1.[0-9]+.x
env:
TZ: "Europe/Brussels"
MAIN_NODEJS: "20"
NPM_VERSION: "10.x"
LOGS_DIR: /tmp/ngx-form-errors/logs
LOGS_FILE: /tmp/ngx-form-errors/logs/build-perf.log
HUSKY: 0
jobs:
build-test:
name: Build and Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: ["20"]
os: [ubuntu-latest]
experimental: [false]
# Mark following configurations as "experimental" and allow to continue in case of error
# See documentation: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-new-combinations
include:
- os: macos-latest
node_version: 20
experimental: true
steps:
# Some actions should be executed only in one environment.
# This variable determines if it is the main environment, it means the same than the one we have internally.
- name: Set environment variable 'IS_MAIN_ENVIRONMENT'
run: |
if [[ '${{ matrix.node_version }}' == '${{ env.MAIN_NODEJS }}' ]] && [[ '${{ matrix.os }}' == 'ubuntu-latest' ]]; then
echo "IS_MAIN_ENVIRONMENT=1" >> $GITHUB_ENV
else
echo "IS_MAIN_ENVIRONMENT=0" >> $GITHUB_ENV
fi
# See: https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
# See: https://github.com/marketplace/actions/setup-node-js-environment
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
# See: https://github.com/marketplace/actions/cache
# See doc: https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules-${{ matrix.node_version }}-${{ matrix.os }}
with:
# npm cache files are stored in `~/.npm` on Linux
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install npm ${{ env.NPM_VERSION }}
run: npm i -g npm@${{ env.NPM_VERSION }}
- name: List main variables
run: |
echo "Commit SHA : ${GITHUB_SHA}"
echo "Reference : ${GITHUB_REF}"
echo "Head branch : ${GITHUB_HEAD_REF}"
echo "Base branch : ${GITHUB_BASE_REF}"
echo "Build number: ${GITHUB_RUN_NUMBER}"
echo "Repository : ${GITHUB_REPOSITORY}"
echo "Event : ${GITHUB_EVENT_NAME}"
echo "Author : ${GITHUB_ACTOR}"
echo "Main ENV : ${{ env.IS_MAIN_ENVIRONMENT }}"
NODE_VERSION="$(node -v)"
echo "Node version: $NODE_VERSION"
# This ensures that we are authenticated without requiring to have an actual .npmrc file within the project
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Install dependencies
run: |
npm ci
npm run install:ci:demo:ng-previous
npm run install:ci:demo:ng-latest
- name: Linting and testing
run: |
npm run lint:all
npm run test:ci:all
- name: Generate docs coverage
run: npm run docs:coverage
if: env.IS_MAIN_ENVIRONMENT == 1
# See: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload ngx-form-errors dist folder
uses: actions/upload-artifact@v4
with:
name: ngx-form-errors-dist
path: dist
if: env.IS_MAIN_ENVIRONMENT == 1
# See: https://github.com/marketplace/actions/coveralls-github-action
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: "reports/coverage/lcov.info"
if: env.IS_MAIN_ENVIRONMENT == 1
release:
name: Release
runs-on: "ubuntu-latest"
needs: build-test
if: startsWith(github.ref, 'refs/tags/')
steps:
# See: https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
# See: https://github.com/marketplace/actions/setup-node-js-environment
- name: Use Node.js ${{ env.MAIN_NODEJS }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.MAIN_NODEJS }}
- name: Install npm ${{ env.NPM_VERSION }}
run: npm i -g npm@${{ env.NPM_VERSION }}
# See: https://github.com/marketplace/actions/download-a-build-artifact
- uses: actions/download-artifact@v4
with:
name: ngx-form-errors-dist
path: dist
- name: Create file & folder for GitHub Actions logs
run: |
# cfr scripts/_ghactions-group.sh
mkdir -p $LOGS_DIR
touch $LOGS_FILE
- name: Release
run: npm run release:publish
- name: Save logs
run: bash ./scripts/ci/print-logs.sh