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
14 changes: 10 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8737,14 +8737,20 @@ const core = __nccwpck_require__(186);

async function run() {
const SERVICEID = core.getInput('service-id') || process.env.SERVICEID;
const APIKEY = core.getInput('api-key') || process.env.APIKEY;
const APIKEY = core.getInput('api-key') || process.env.APIKEY;

const response = await fetch('https://api.render.com/v1/services/' + SERVICEID + '/deploys', {
method: 'POST',
headers: { 'Authorization': `Bearer ${APIKEY}`}
})
})

core.info(`Response received: ${response.status}`)
response.json().then(data => {
if (response.ok) {
core.info(`Deploy ${data.status} - Commit: ${data.commit.message}`)
} else {
core.setFailed(`Deploy error: ${data.message} (status code ${response.status})`)
}
});
}

run().catch(e => core.setFailed(e.message));
Expand Down
14 changes: 10 additions & 4 deletions src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ const core = require('@actions/core');

async function run() {
const SERVICEID = core.getInput('service-id') || process.env.SERVICEID;
const APIKEY = core.getInput('api-key') || process.env.APIKEY;
const APIKEY = core.getInput('api-key') || process.env.APIKEY;

const response = await fetch('https://api.render.com/v1/services/' + SERVICEID + '/deploys', {
method: 'POST',
headers: { 'Authorization': `Bearer ${APIKEY}`}
})
})

core.info(`Response received: ${response.status}`)
response.json().then(data => {
if (response.ok) {
core.info(`Deploy ${data.status} - Commit: ${data.commit.message}`)
} else {
core.setFailed(`Deploy error: ${data.message} (status code ${response.status})`)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing an issue here. It seems like it is an issue with the Render API not behaving like the documentation suggests.

Docs show that a 401 error should return the error object like other error responses

image

However, it seems that a 401 unauthorized never returns JSON. Just the string "Unauthorized". This results in an error I noticed when getting this setup.

Run dylanfm/render-deploy-action@status-fails
undefined:1
Unauthorized
^

SyntaxError: Unexpected token U in JSON at position 0
    at JSON.parse (<anonymous>)
    at Response.json (/home/runner/work/_actions/dylanfm/render-deploy-action/status-fails/dist/index.js:6968:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

If the API docs aren't right for this particular error case, maybe the code needs a special case for 401 responses that doesn't expect JSON.

Comparison to another error using curl shows that at least 404 errors do return JSON (although not the "id" property from docs).

$ curl --request POST --url https://api.render.com/v1/services/serviceId/deploys --header 'Accept: application/json' --header 'Content-Type: application/json' --header 'Authorization: Bearer abc'
Unauthorized
$ curl --request POST --url https://api.render.com/v1/services/serviceId/deploys --header 'Accept: application/json' --header 'Content-Type: application/json' --header 'Authorization: Bearer rnd_aRealKey'
{"message":"not found: service serviceId"}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great spot, I've raised it with our engineering team. It does seem that the Unauthorized one is the only one that returns plain text which isn't as it's documented.

}
});
}

run().catch(e => core.setFailed(e.message));