mirror of
https://github.com/actions/deploy-pages.git
synced 2025-12-09 12:26:11 +00:00
Deprecate 'emit_telemetry' and remove its feature
Since we emit telemetry in a different way, we can remove this feature from the action and prevent unintentional misuse.
This commit is contained in:
@@ -37,7 +37,7 @@ process.on('SIGTERM', cancelHandler)
|
||||
// Main
|
||||
const emitTelemetry = core.getInput('emit_telemetry')
|
||||
if (emitTelemetry === 'true') {
|
||||
require('./pre')
|
||||
// For compatibility, treat the use of this deprecated input as a no-op
|
||||
} else {
|
||||
main()
|
||||
}
|
||||
|
||||
58
src/pre.js
58
src/pre.js
@@ -1,58 +0,0 @@
|
||||
const core = require('@actions/core')
|
||||
const axios = require('axios')
|
||||
const axiosRetry = require('axios-retry')
|
||||
const retryAttempt = 3
|
||||
|
||||
axiosRetry(axios, {
|
||||
retries: retryAttempt,
|
||||
retryDelay: retryCount => {
|
||||
core.info(`retrying to send pages telemetry with attempt: ${retryCount}`)
|
||||
return retryCount * 1000 // time interval between retries, with 1s, 2s, 3s
|
||||
},
|
||||
|
||||
// retry on error greater than 500
|
||||
retryCondition: error => {
|
||||
return error.response.status >= 500
|
||||
}
|
||||
})
|
||||
|
||||
const { Deployment } = require('./deployment')
|
||||
|
||||
async function emitTelemetry() {
|
||||
// All variables we need from the runtime are set in the Deployment constructor
|
||||
const deployment = new Deployment()
|
||||
const telemetryUrl = `${deployment.githubApiUrl}/repos/${deployment.repositoryNwo}/pages/telemetry`
|
||||
const conclusion = core.getInput('conclusion') || null
|
||||
core.info(`Sending telemetry for run id ${deployment.workflowRun}: ${conclusion}`)
|
||||
await axios
|
||||
.post(
|
||||
telemetryUrl,
|
||||
{ github_run_id: deployment.workflowRun, conclusion },
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
Authorization: `Bearer ${deployment.githubToken}`,
|
||||
'Content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
)
|
||||
.catch(err => {
|
||||
if (err.response.status !== 200) {
|
||||
throw new Error(
|
||||
`failed to emit metric with status code: ${err.response.status} after ${retryAttempt} retry attempts`
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await emitTelemetry()
|
||||
} catch (error) {
|
||||
core.error('failed to emit pages build telemetry')
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
module.exports = { emitTelemetry }
|
||||
@@ -1,64 +0,0 @@
|
||||
const core = require('@actions/core')
|
||||
const process = require('process')
|
||||
const axios = require('axios')
|
||||
|
||||
const { emitTelemetry } = require('./pre')
|
||||
|
||||
describe('emitTelemetry', () => {
|
||||
beforeAll(() => {
|
||||
process.env.ACTIONS_RUNTIME_URL = 'my-url'
|
||||
process.env.GITHUB_RUN_ID = '123'
|
||||
process.env.ACTIONS_RUNTIME_TOKEN = 'a-token'
|
||||
process.env.GITHUB_REPOSITORY = 'actions/is-awesome'
|
||||
process.env.GITHUB_TOKEN = 'gha-token'
|
||||
process.env.GITHUB_SHA = '123abc'
|
||||
process.env.GITHUB_ACTOR = 'monalisa'
|
||||
process.env.GITHUB_ACTION = '__monalisa/octocat'
|
||||
process.env.GITHUB_ACTION_PATH = 'something'
|
||||
process.env.INPUT_CONCLUSION = 'success'
|
||||
|
||||
jest.spyOn(core, 'setOutput').mockImplementation(param => {
|
||||
return param
|
||||
})
|
||||
|
||||
jest.spyOn(core, 'setFailed').mockImplementation(param => {
|
||||
return param
|
||||
})
|
||||
// Mock error/warning/info/debug
|
||||
jest.spyOn(core, 'error').mockImplementation(jest.fn())
|
||||
jest.spyOn(core, 'warning').mockImplementation(jest.fn())
|
||||
jest.spyOn(core, 'info').mockImplementation(jest.fn())
|
||||
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||
})
|
||||
|
||||
it('will send telemetry to github api', done => {
|
||||
process.env.GITHUB_SHA = 'valid-build-version'
|
||||
|
||||
axios.post = jest.fn().mockResolvedValue({
|
||||
status: 200,
|
||||
data: {
|
||||
status: 'succeed'
|
||||
}
|
||||
})
|
||||
|
||||
emitTelemetry()
|
||||
|
||||
expect(axios.post).toBeCalledWith(
|
||||
'https://api.github.com/repos/actions/is-awesome/pages/telemetry',
|
||||
{
|
||||
github_run_id: process.env.GITHUB_RUN_ID,
|
||||
conclusion: 'success'
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/vnd.github.v3+json',
|
||||
Authorization: 'Bearer ',
|
||||
'Content-type': 'application/json'
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
expect(core.setFailed).not.toHaveBeenCalled()
|
||||
done()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user