Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ In the above snippet, the `project_id` and `api_key` are being fetched from the

`check_interval`: The interval in **seconds** of which the action should check the status of running tests. (Recommended to not make this too short so you will not be spamming TestProject APIs)

`wait_for_tests`: Whether the action should wait for the tests to complete (pass/fail) or if it should just start them and complete the action. (Default = `true`)
`wait_for_tests`: Whether the action should wait for the tests to complete (pass/fail) or if it should just start them and complete the action. (Default = `true`)

### More optional params for changing targeted application url. Use these two params together (useful for devs who build PR / dynamic envs for testing phase):

`api_id`: appId for application associated with project_id. Use in conjunction with app_url below. (Default = `0`)

`app_url`: Update appId with new url to target. (Default = `` empty string)

13 changes: 10 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ inputs:
wait_for_tests:
description: 'Should the action wait for tests to finish before continuing'
required: false
default: 'true'

default: true
app_id:
description: 'Application ID so we can update/pass target app url'
required: false
default: '0'
app_url:
description: 'app url (target)'
required: false
default: ''
branding:
icon: 'check-circle'
color: 'green'
color: 'green'
42 changes: 42 additions & 0 deletions execute-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,25 @@ const API_HEADER = {
const CHECK_INTERVAL = parseInt(strip(process.env.INPUT_CHECK_INTERVAL)) * 1000
const WAIT_FOR_TESTS = strip(process.env.INPUT_WAIT_FOR_TESTS) === 'true' || strip(process.env.INPUT_WAIT_FOR_TESTS) === true

const API_URL_APP = `https://api.testproject.io/v2/projects/${ strip(process.env.INPUT_PROJECT_ID) }/applications/${ strip(process.env.INPUT_APP_ID) }`

// Keep track of all jobs
const jobsStatus = []

async function main() {

//update application url if optional defaults changed - SteveDevOps
if ( parseInt(strip(process.env.INPUT_APP_ID)) != 0 && strip(process.env.INPUT_APP_URL) != '' ) {

core.info(`Attempting to change application url to ${ strip(process.env.INPUT_APP_URL) } for appId ${ strip(process.env.INPUT_APP_ID) }`)

await updateAppUrl().catch( err => {
core.setFailed(`Unable to update appId with new url.`)
console.log(err)
return
})

}

core.info(`Getting a list of all jobs in project ${ strip(process.env.INPUT_PROJECT_ID) }`)

Expand Down Expand Up @@ -52,6 +67,33 @@ async function getJobs() {
return jobs.data
}


/**
* updates application url for project_id if INPUT_APP_ID AND INPUT_APP_URL are passed - SteveDevOps
*/

async function updateAppUrl() {

const params = JSON.stringify({

"url": strip(process.env.INPUT_APP_URL),

});

await axios ({
method: 'put',
url: API_URL_APP,
headers: API_HEADER,
body: params
}).catch( err => {
core.setFailed(`Execution failed for changing appId via post to ${ API_URL_APP } `)
console.log(err)
return
})

}


/**
* Executes all the jobs passed in the parameter and adds them to the `jobsStatus` array
* @param {*} jobs Array of jobs to execute
Expand Down