-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
144 lines (120 loc) · 4.34 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
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
name: Test and Analyze with Triggers and SonarCloud
description: Run node tests based on triggers, optional SonarCloud
branding:
icon: check-square
color: blue
inputs:
### Required
commands:
description: Commands to run tests, start with '|' for multi-line
required: true
dir:
description: App/package directory
required: true
node_version:
description: Node version to use
required: true
### Typical / recommended
cache:
description: Package manager for caching; e.g. npm, yarn, pnpm
default: npm
sonar_args:
# https://docs.sonarcloud.io/advanced-setup/analysis-parameters/
description: SonarCloud command line arguments
default: |
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=bcgov_${{ github.repository }}
sonar_token:
description: Sonar token, provide unpopulated token for pre-setup (will skip)
triggers:
description: Paths (array) used to trigger a build; e.g. ('./backend/' './frontend/)
### Usually a bad idea / not recommended
diff_branch:
description: Branch to diff against
default: ${{ github.event.repository.default_branch }}
repository:
description: Non-default repository to clone (used for testing this action)
default: ${{ github.repository }}
branch:
description: Non-default branch to clone (used for testing this action)
default: ""
triggers_event:
description: Events (array) to use with triggers; e.g. ("pull_request" "push" "workflow_dispatch")
default: "('pull_request')"
runs:
using: composite
steps:
- name: Warnings for breaking changes
shell: bash
run: |
# Warnings for breaking changes
# node_version now required
if [ -z "${{ inputs.node_version }}" ]; then
echo -e "\nnode_version now required. Previous default: 16."
echo -e "\n\tAction: add a node_version parameter\n"
exit 1
fi
# sonar_project_token renamed sonar_token
if [ ! -z "${{ inputs.sonar_project_token }}" ]; then
echo -e "\nsonar_project_token renamed. Please correct this and try again."
echo -e "\n\tAction: rename sonar_project_token to sonar_token\n"
exit 1
fi
#
if [ ! -z "${{ inputs.sonar_comment_token }}" ]; then
echo -e "\nsonar_comment_token deprecated. Please correct this and try again."
echo -e "\n\tAction: remove sonar_comment_token parameter\n"
exit 1
fi
# Send triggers to diff action
- id: diff
uses: bcgov-nr/action-diff-triggers@v0.2.0
with:
triggers: ${{ inputs.triggers }}
diff_branch: ${{ inputs.diff_branch }}
# Shallow clone is faster, but SonarCloud requires a full clone
- uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
# Setup node and cache dir
- uses: actions/setup-node@v4
if: steps.diff.outputs.triggered == 'true'
with:
node-version: ${{ inputs.node_version }}
cache: ${{ inputs.cache }}
cache-dependency-path: ${{ inputs.dir }}/package-lock.json
# Run tests, hopefully generating coverage for SonarCloud
- if: steps.diff.outputs.triggered == 'true'
shell: bash
working-directory: ${{ inputs.dir }}
run: |
# Run Tests
${{ inputs.commands }}
### Optional SonarCloud
# If sonar_token
- if: inputs.sonar_token && steps.diff.outputs.triggered == 'true'
uses: SonarSource/sonarcloud-github-action@v4.0.0
env:
SONAR_TOKEN: ${{ inputs.sonar_token }}
with:
projectBaseDir: ${{ inputs.dir }}
args: >
${{ inputs.sonar_args }}
### Cleanup
# Fix - Docker can take file ownership, causing a cleanup fail
- shell: bash
if: steps.diff.outputs.triggered == 'true'
id: get_uid
run: |
# User for workstation ownership reset/fix
echo "uid=$(id -u ${USER})" >> $GITHUB_OUTPUT
- uses: peter-murray/reset-workspace-ownership-action@v1
if: steps.diff.outputs.triggered == 'true'
with:
user_id: ${{ steps.get_uid.outputs.uid }}
# Fix - Clone for action.yml and other verifications
- name: Checkout Action repo to pass tests
if: always() && inputs.repository != github.repository
uses: actions/checkout@v4