You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Unit Testing (nodejs) with SonarCloud and Conditional Triggers
18
+
# Test and Analyze with Triggers and SonarCloud
19
19
20
-
This action runs unit tests and optionally runs analysis, including coverage, using[SonarCloud](https://sonarcloud.io). SonarCloud can be configured to comment on pull requests or stop failing workflows.
20
+
This action runs tests, dependent on triggers, optionally sending results and coverage to[SonarCloud](https://sonarcloud.io). Test and SonarCloud can be configured to comment on pull requests or stop failing workflows.
21
21
22
22
Conditional triggers are used to determine whether tests need to be run. If triggers are matched, then the appropriate code has changed and should be tested. Tests always run if no triggers are provided. Untriggered runs do little other than report a success.
23
23
@@ -30,7 +30,7 @@ Only nodejs (JavaScript, TypeScript) is supported by this action. Please see ou
30
30
with:
31
31
### Required
32
32
33
-
# Commands to run unit tests
33
+
# Commands to run tests
34
34
# Please configure your app to generate coverage (coverage/lcov.info)
35
35
commands: |
36
36
npm ci
@@ -54,7 +54,7 @@ Only nodejs (JavaScript, TypeScript) is supported by this action. Please see ou
54
54
55
55
# Sonar token
56
56
# Available from sonarcloud.io or your organization administrator
57
-
# BCGov i.e. https://github.com/BCDevOps/devops-requests/issues/new/choose
# Provide an unpopulated token for pre-setup, section will be skipped
59
59
sonar_token:
60
60
description: ${{ secrets.SONAR_TOKEN }}
@@ -78,20 +78,25 @@ Only nodejs (JavaScript, TypeScript) is supported by this action. Please see ou
78
78
# Useful for consuming non-default branches, like in testing
79
79
# Defants to empty, cloning the default branch
80
80
branch: ""
81
+
82
+
# Bash array of events for limiting triggers, otherwise trigger automatically
83
+
# E.g. ("pull_request" "push" "workflow_dispatch")
84
+
# Defaults to only using triggers with pull requests
85
+
triggers_event: "('pull_request')"
81
86
```
82
87
83
88
# Example, Single Directory with SonarCloud Analysis
84
89
85
-
Run unit tests and provide results to SonarCloud. This is a full workflow that runs on pull requests, merge to main and workflow_dispatch. Use a GitHub Action secret to provide ${{ secrets.SONAR_TOKEN }}.
90
+
Run tests and provide results to SonarCloud. This is a full workflow that runs on pull requests, merge to main and workflow_dispatch. Use a GitHub Action secret to provide ${{ secrets.SONAR_TOKEN }}.
86
91
87
92
The specified triggers will be used to decide whether this job runs tests and analysis or just exists successfully.
88
93
89
-
Create or modify a GitHub workflow, like below. E.g. `./github/workflows/unit-tests.yml`
94
+
Create or modify a GitHub workflow, like below. E.g. `./github/workflows/tests.yml`
90
95
91
96
Note: Provde an unpopulated SONAR_TOKEN until one is provisioned. SonarCloud will only run once populated, allowing for pre-setup.
92
97
93
98
```yaml
94
-
name: Unit Tests and Analysis
99
+
name: Test and Analyze
95
100
96
101
on:
97
102
pull_request:
@@ -109,7 +114,7 @@ concurrency:
109
114
110
115
jobs:
111
116
tests:
112
-
name: Run Unit Tests and Analyse
117
+
name: Test and Analyze
113
118
runs-on: ubuntu-22.04
114
119
steps:
115
120
- uses: bcgov-nr/action-test-and-analyse@main
@@ -127,14 +132,14 @@ jobs:
127
132
triggers: ('frontend/' 'charts/frontend')
128
133
```
129
134
130
-
# Example, Only Running Unit Tests (No SonarCloud), No Triggers
135
+
# Example, Only Running Tests (No SonarCloud), No Triggers
131
136
132
-
No triggers are provided so unit tests will always run. SonarCloud is skipped.
137
+
No triggers are provided so tests will always run. SonarCloud is skipped.
133
138
134
139
```yaml
135
140
jobs:
136
141
tests:
137
-
name: Run Unit Tests and Analyse
142
+
name: Test and Analyze
138
143
runs-on: ubuntu-22.04
139
144
steps:
140
145
- uses: bcgov-nr/action-test-and-analyse@main
@@ -148,12 +153,12 @@ jobs:
148
153
149
154
# Example, Matrix / Multiple Directories with Sonar Cloud and Triggers
150
155
151
-
Unit test and analyze projects in multiple directories in parallel. This time `repository` and `branch` are provided. Please note how secrets must be passed in to composite Actions using the secrets[matrix.variable] syntax.
156
+
Test and analyze projects in multiple directories in parallel. This time `repository` and `branch` are provided. Please note how secrets must be passed in to composite Actions using the secrets[matrix.variable] syntax.
@@ -194,6 +199,10 @@ After sign up, a token should be available from your project on the [SonarCloud]
194
199
195
200
E.g. https://sonarcloud.io/project/configuration?id={<PROJECT>}&analysisMode=GitHubActions
196
201
202
+
# Triggers and Triggers_Event
203
+
204
+
Triggers are used to limit test running to only appropriate files are changed. This is generally not desirable outside of pull requests, so `triggers_event` defaults to `("pull_request")`. Override this behaviour by specifying a bash array using any of the many, many [event types GitHub provides](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push), e.g. `("branch_protection_rule" "workflow_dispatch" "push")`.
205
+
197
206
# Feedback
198
207
199
208
Please contribute your ideas! [Issues] and [pull requests] are appreciated.
0 commit comments