Skip to content

Commit 2801a4a

Browse files
committed
Add project-run capabilities
1 parent 5352ccf commit 2801a4a

7 files changed

Lines changed: 84 additions & 13 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ configuration.
108108

109109
### `project_id`
110110

111-
**Required for `mode=project`** The id of the project to run.
111+
**Required for `mode=project`** (unless `project_name` is given) The id of the
112+
project to run. Takes precedence over `project_name` if both are set.
113+
114+
### `project_name`
115+
116+
**Optional (`mode=project`)** The name of the project to run, used when
117+
`project_id` is not set. Either `project_id` or `project_name` is required for
118+
`mode=project`.
112119

113120
### `test_ids`
114121

__tests__/main.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ describe('action', () => {
180180
'key',
181181
'secret',
182182
'42',
183+
'',
183184
[1, 2, 3],
184185
'',
185186
'dev',
@@ -188,6 +189,42 @@ describe('action', () => {
188189
)
189190
})
190191

192+
it('runs a project by name when no id is given', async () => {
193+
getInputMock.mockImplementation(name => {
194+
if (name === 'project_id') return ''
195+
if (name === 'project_name') return 'my-project'
196+
return projectInputs[name] ?? ''
197+
})
198+
runProjectMock.mockResolvedValue(passedProjectRun)
199+
200+
await main.run()
201+
expect(runProjectMock).toHaveBeenCalledWith(
202+
'key',
203+
'secret',
204+
'',
205+
'my-project',
206+
[],
207+
'',
208+
'dev',
209+
3,
210+
1800
211+
)
212+
expect(setFailedMock).not.toHaveBeenCalled()
213+
})
214+
215+
it('fails when neither project_id nor project_name is given', async () => {
216+
getInputMock.mockImplementation(name => {
217+
if (name === 'project_id') return ''
218+
return projectInputs[name] ?? ''
219+
})
220+
221+
await main.run()
222+
expect(setFailedMock).toHaveBeenCalledWith(
223+
"mode=project requires 'project_id' or 'project_name'"
224+
)
225+
expect(runProjectMock).not.toHaveBeenCalled()
226+
})
227+
191228
it('fails the run when the project run failed', async () => {
192229
runProjectMock.mockResolvedValue({
193230
...passedProjectRun,

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ inputs:
2424
description: 'The destination to call, overriding the test configuration (mode=test)'
2525
required: false
2626
project_id:
27-
description: 'The id of the project to run (required when mode=project)'
27+
description: 'The id of the project to run (mode=project; takes precedence over project_name)'
28+
required: false
29+
project_name:
30+
description: 'The name of the project to run (mode=project; used when project_id is not set)'
2831
required: false
2932
test_ids:
3033
description: 'Comma-separated subset of test ids to run (mode=project, optional)'

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ async function run_test_mode(common) {
9696
* @returns {Promise<void>} Resolves once outputs are set.
9797
*/
9898
async function run_project_mode(common) {
99-
const project_id = core.getInput('project_id', { required: true })
99+
const project_id = core.getInput('project_id', { required: false })
100+
const project_name = core.getInput('project_name', { required: false })
100101
const test_ids = id_list_input('test_ids')
101102

102-
let msg = `Running project '${project_id}'`
103+
if (!project_id && !project_name) {
104+
throw new Error("mode=project requires 'project_id' or 'project_name'")
105+
}
106+
107+
let msg = `Running project '${project_id || project_name}'`
103108
if (test_ids.length) {
104109
msg += ` (tests ${test_ids.join(',')})`
105110
}
@@ -112,6 +117,7 @@ async function run_project_mode(common) {
112117
common.public_key,
113118
common.secret_key,
114119
project_id,
120+
project_name,
115121
test_ids,
116122
common.report_mode,
117123
common.sf_environment,

src/sipfront-api.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ async function run_call_test(
188188
*
189189
* @param {string} public_key The public API key for the Sipfront API.
190190
* @param {string} secret_key The secret API key for the Sipfront API.
191-
* @param {string} project_id The id of the project to run.
191+
* @param {string} project_id The id of the project to run (takes precedence).
192+
* @param {string} project_name The name of the project to run (used if no id).
192193
* @param {number[]} test_ids Optional subset of test ids to run.
193194
* @param {string} report_mode Optional report mode ('full' or 'kiosk').
194195
* @param {string} sf_environment Internal environment selector for testing.
@@ -201,6 +202,7 @@ async function run_project(
201202
public_key,
202203
secret_key,
203204
project_id,
205+
project_name,
204206
test_ids,
205207
report_mode,
206208
sf_environment,
@@ -210,8 +212,12 @@ async function run_project(
210212
const api_base = api_base_for(sf_environment)
211213
const httpc = make_client(public_key, secret_key)
212214

213-
const data = {
214-
id: Number(project_id)
215+
// The API gives `id` precedence over `project.name` when both are present.
216+
const data = {}
217+
if (project_id && String(project_id).length > 0) {
218+
data.id = Number(project_id)
219+
} else if (project_name && project_name.length > 0) {
220+
data['project.name'] = project_name
215221
}
216222
if (report_mode && report_mode.length > 0) {
217223
data['report.mode'] = report_mode

0 commit comments

Comments
 (0)