Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update action dependencies #42

Closed
wants to merge 1 commit into from
Closed
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
47,006 changes: 14,262 additions & 32,744 deletions dist/main/index.js

Large diffs are not rendered by default.

46,916 changes: 14,209 additions & 32,707 deletions dist/post/index.js

Large diffs are not rendered by default.

8,669 changes: 8,444 additions & 225 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"author": "radiantspace",
"license": "MIT",
"dependencies": {
"@actions/core": "1.2.6",
"@actions/github": "2.2.0",
"@actions/core": "1.10.0",
"@actions/github": "5.1.1",
"@slack/web-api": "^5.11.0"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions src/complete.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { context, GitHub } from '@actions/github'
import { context, getOctokit } from '@actions/github'
import { DeploymentStatus } from './utils'

export async function complete (
client: GitHub,
client: ReturnType<typeof getOctokit>,
deploymentId: number,
status: DeploymentStatus
): Promise<void> {
const statuses = await client.repos.listDeploymentStatuses({
const statuses = await client.rest.repos.listDeploymentStatuses({
...context.repo,
deployment_id: deploymentId
})
Expand All @@ -20,7 +20,7 @@ export async function complete (
)}`
)

const statusResult = await client.repos.createDeploymentStatus({
const statusResult = await client.rest.repos.createDeploymentStatus({
...context.repo,
deployment_id: deploymentId,
state: status,
Expand Down
39 changes: 27 additions & 12 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { context, GitHub } from '@actions/github'
import { context, getOctokit } from '@actions/github'
import { DeploymentStatus } from './utils'

async function invalidatePreviousDeployments (
client: GitHub,
client: ReturnType<typeof getOctokit>,
environment: string
): Promise<void> {
const deployments = await client.repos.listDeployments({
const deployments = await client.rest.repos.listDeployments({
...context.repo,
ref: context.ref,
environment
})

await Promise.all(
deployments.data.map(async deployment => {
const statuses = await client.repos.listDeploymentStatuses({
const statuses = await client.rest.repos.listDeploymentStatuses({
...context.repo,
deployment_id: deployment.id
})
Expand All @@ -30,7 +30,7 @@ async function invalidatePreviousDeployments (
// invalidate the deployment
if (lastStatus?.state === 'success') {
console.log(`invalidating deployment: ${JSON.stringify(deployment, null, 2)}`)
await client.repos.createDeploymentStatus({
await client.rest.repos.createDeploymentStatus({
...context.repo,
deployment_id: deployment.id,
state: 'inactive',
Expand All @@ -42,20 +42,26 @@ async function invalidatePreviousDeployments (
)
}

async function getMainSha (client: GitHub, branch: string): Promise<string> {
async function getMainSha (client: ReturnType<typeof getOctokit>, branch: string): Promise<string> {
try {
const response = await client.repos.getBranch({ ...context.repo, branch })
const response = await client.rest.repos.getBranch({
...context.repo,
branch
})
const sha = response.data.commit.sha
console.log(`${branch} branch sha: ${sha}`)
return sha
} catch (error) {
console.error(error.message)
if (error instanceof Error) {
console.error(error.message)
}

return `no_${branch}`
}
}

export async function create (
client: GitHub,
client: ReturnType<typeof getOctokit>,
logUrl: string,
description: string,
initialStatus: DeploymentStatus,
Expand All @@ -68,9 +74,12 @@ export async function create (
// get main branch sha to store in payload
const mainBranchSha = await getMainSha(client, mainBranch)

const payload = JSON.stringify({ actor: context.actor, main_sha: mainBranchSha })
const payload = JSON.stringify({
actor: context.actor,
main_sha: mainBranchSha
})

const deployment = await client.repos.createDeployment({
const deployment = await client.rest.repos.createDeployment({
...context.repo,
ref: context.ref,
required_contexts: [],
Expand All @@ -81,15 +90,21 @@ export async function create (
payload
})

if (deployment.status !== 201) {
throw new Error('failed to create deployment')
}

console.log(`created deployment: ${JSON.stringify(deployment.data, null, 2)}`)

const status = await client.repos.createDeploymentStatus({
const status = await client.rest.repos.createDeploymentStatus({
...context.repo,
deployment_id: deployment.data.id,
state: initialStatus,
log_url: logUrl,
environment_url: environmentUrl
})

console.log(`created deployment status: ${JSON.stringify(status.data, null, 2)}`)

return deployment.data.id.toString()
}
8 changes: 4 additions & 4 deletions src/delete-all.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { context, GitHub } from '@actions/github'
import { context, getOctokit } from '@actions/github'

export async function deleteAll (
client: GitHub,
client: ReturnType<typeof getOctokit>,
environment: string
): Promise<void> {
const deployments = await client.repos.listDeployments({
const deployments = await client.rest.repos.listDeployments({
...context.repo,
environment
})
Expand All @@ -13,7 +13,7 @@ export async function deleteAll (
// invalidate deployment first
// since we can't delete active deployment
console.log(`invalidate deployment: ${deployment.id}`)
await client.repos.createDeploymentStatus({
await client.rest.repos.createDeploymentStatus({
...context.repo,
deployment_id: deployment.id,
state: 'failure'
Expand Down
6 changes: 3 additions & 3 deletions src/delete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { context, GitHub } from '@actions/github'
import { context, getOctokit } from '@actions/github'

export async function deleteDeployment (
client: GitHub,
client: ReturnType<typeof getOctokit>,
deploymentId: number
): Promise<void> {
// invalidate deployment first
// since we can't delete active deployment
console.log(`invalidate deployment: ${deploymentId}`)
const status = await client.repos.createDeploymentStatus({
const status = await client.rest.repos.createDeploymentStatus({
...context.repo,
deployment_id: deploymentId,
state: 'failure'
Expand Down
22 changes: 17 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ export async function run (): Promise<void> {
deploymentId = getInput(DEPLOYMENT_ID_STATE_NAME, { required: shouldRequireDeploymentId }) ?? '0'
console.log(`deploymentId: ${deploymentId}`)
} catch (error) {
core.error(error)
if (error instanceof Error || typeof error === 'string') {
core.error(error)
}

core.setFailed(`Wrong parameters given: ${JSON.stringify(error, null, 2)}`)
throw error
}
console.log('\n')

const client = new github.GitHub(token, { previews: ['ant-man', 'flash'] })
const client = github.getOctokit(token, { previews: ['ant-man', 'flash'] })

console.log('### run ###')

Expand All @@ -78,7 +81,10 @@ export async function run (): Promise<void> {
core.saveState(DEPLOYMENT_ID_STATE_NAME, deploymentId) // for internal use
core.setOutput(DEPLOYMENT_ID_STATE_NAME, deploymentId) // keep that output for external dependencies
} catch (error) {
core.error(error)
if (error instanceof Error || typeof error === 'string') {
core.error(error)
}

core.setFailed(`Create deployment failed: ${JSON.stringify(error, null, 2)}`)
throw error
}
Expand All @@ -90,7 +96,10 @@ export async function run (): Promise<void> {
Number(deploymentId)
)
} catch (error) {
core.error(error)
if (error instanceof Error || typeof error === 'string') {
core.error(error)
}

core.setFailed(`Delete deployment failed: ${JSON.stringify(error, null, 2)}`)
throw error
}
Expand All @@ -102,7 +111,10 @@ export async function run (): Promise<void> {
environment
)
} catch (error) {
core.error(error)
if (error instanceof Error || typeof error === 'string') {
core.error(error)
}

core.setFailed(`Delete all deployments failed: ${JSON.stringify(error, null, 2)}`)
throw error
}
Expand Down
15 changes: 11 additions & 4 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ export async function post (): Promise<void> {
deploymentConfidenceUrl = getInput('deployment_confidence_url') ?? ''
console.log(`deployment confidence dashboard URL: ${deploymentConfidenceUrl}`)
} catch (error) {
core.error(error)
if (error instanceof Error || typeof error === 'string') {
core.error(error)
}

core.setFailed(`Wrong parameters given: ${JSON.stringify(error, null, 2)}`)
throw error
}
console.log('\n')
console.log('### post ###')

const client = new github.GitHub(token, { previews: ['ant-man', 'flash'] })
const client = github.getOctokit(token, { previews: ['ant-man', 'flash'] })
const status: DeploymentStatus = jobStatus === 'success' ? 'success' : 'failure'
console.log(`status: ${status}`)

Expand All @@ -71,11 +74,15 @@ export async function post (): Promise<void> {
try {
await complete(client, Number(deploymentId), status)
} catch (error) {
if (error.name === 'HttpError' && error.status === 404) {
if (error instanceof Error && error.name === 'HttpError' && (error as { status?: unknown }).status === 404) {
console.log('Couldn\'t complete a deployment: not found')
return
}
core.error(error)

if (error instanceof Error || typeof error === 'string') {
core.error(error)
}

core.setFailed(`Complete deployment failed: ${JSON.stringify(error, null, 2)}`)
throw error
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export async function postSlackNotification (
await slackClient.chat.postMessage(slackParams)
console.log(`Slack message posted to channel: ${slackChannel}`)
} catch (error) {
core.error(error)
if (error instanceof Error || typeof error === 'string') {
core.error(error)
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ describe('create', () => {

const postDeployment = nock('https://api.github.com')
.post('/repos/owner/repo/deployments')
.reply(200, postDeploymentReply)
.reply(201, postDeploymentReply)

const postStatus = nock('https://api.github.com')
.post('/repos/owner/repo/deployments/42/statuses')
.reply(200, postStatusReply)
.reply(201, postStatusReply)

// act
await main.run()
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('create', () => {
await main.run()
expect('this should not be reached').toEqual('')
} catch (error) {
expect(error.message).toEqual("{\"resource\":\"DeploymentStatus\",\"code\":\"custom\",\"field\":\"environment_url\",\"message\":\"environment_url must use http(s) scheme\"}")
expect(error.message).toEqual("environment_url must use http(s) scheme")
}

// assert
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('complete', () => {

const postDeploymentStatus = nock('https://api.github.com')
.post('/repos/owner/repo/deployments/42/statuses')
.reply(200, postStatusReply)
.reply(201, postStatusReply)

const slack = nock('https://slack.com')
.post('/api/chat.postMessage', body => body.text.includes('<@fake-actor>'))
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('delete-all', () => {

const postStatus = nock('https://api.github.com')
.post('/repos/owner/repo/deployments/42/statuses')
.reply(200, postStatusReply)
.reply(201, postStatusReply)

const deleteDeployment = nock('https://api.github.com')
.delete('/repos/owner/repo/deployments/42')
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('delete', () => {
// arrange
const postStatus = nock('https://api.github.com')
.post('/repos/owner/repo/deployments/42/statuses')
.reply(200, { deployment_url: 'https://api.github.com/repos/owner/repo/deployments/42' })
.reply(201, { deployment_url: 'https://api.github.com/repos/owner/repo/deployments/42' })

const deleteDeployment = nock('https://api.github.com')
.delete('/repos/owner/repo/deployments/42')
Expand Down