-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
111 lines (99 loc) · 3.24 KB
/
action.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
name: '@actalog/node-ci'
description: 'CI pipeline for Node.js: setup, conditional scripts, SonarCloud, artifacts, and PR reports.'
author: Gabriel Rufino <[email protected]>
branding:
icon: refresh-ccw
color: green
inputs:
except:
required: false
default: ''
github-token:
required: false
node-version:
required: false
default: 20
sonar-token:
required: false
runs:
using: 'composite'
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: 'npm'
- id: scripts
run: |
scripts=$(cat package.json | jq -c '.scripts | keys')
echo "scripts=$scripts" >> $GITHUB_OUTPUT
shell: bash
- run: npm ci || npm install
shell: bash
- id: build
if: ${{ contains(steps.scripts.outputs.scripts, 'build') && !contains(inputs.except, 'build') }}
run: npm run build
shell: bash
- id: lint
if: ${{ contains(steps.scripts.outputs.scripts, 'lint') && !contains(inputs.except, 'lint') }}
run: npm run lint
shell: bash
- id: test
if: ${{ contains(steps.scripts.outputs.scripts, 'test') && !contains(inputs.except, 'test') }}
run: npm test
shell: bash
- run: npm run test:e2e
if: ${{ contains(steps.scripts.outputs.scripts, 'test:e2e') && !contains(inputs.except, 'test:e2e') }}
shell: bash
- run: npm run test:cov
if: ${{ contains(steps.scripts.outputs.scripts, 'test:cov') && !contains(inputs.except, 'test') }}
shell: bash
- if: ${{ inputs.sonar-token && inputs.github-token }}
uses: SonarSource/sonarcloud-github-action@master
continue-on-error: true
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
GITHUB_TOKEN: ${{ inputs.github-token }}
- uses: actions/upload-artifact@v4
with:
name: node-ci
path: |
dist
coverage
if-no-files-found: ignore
continue-on-error: true
- if: ${{ always() && github.event_name == 'pull_request' }}
id: info
run: |
size=$(du -sh node_modules | cut -f1)
echo "size=$size" >> $GITHUB_OUTPUT
{
echo 'outdated<<EOF'
echo "$(npm outdated)"
echo 'EOF'
} >> $GITHUB_OUTPUT
shell: bash
continue-on-error: true
- if: ${{ always() && github.event_name == 'pull_request' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
# Node CI
Node CI completed!
## Steps
| Step | Status |
| --------- | -------------------------- |
| **Build** | ${{ steps.build.outcome }} |
| **Lint** | ${{ steps.lint.outcome }} |
| **Test** | ${{ steps.test.outcome }} |
## Statistics
* **node_modules size:** ${{ steps.info.outputs.size }}
## Outdated packages
```
${{ steps.info.outputs.outdated || 'No outdated packages' }}
```
## Environment
* **Runner OS:** ${{ runner.os }}
* **Runner Arch:** ${{ runner.arch }}
* **Node version:** ${{ inputs.node-version }}
continue-on-error: true