Skip to content

Commit

Permalink
Update action code
Browse files Browse the repository at this point in the history
  • Loading branch information
arikmaor committed May 6, 2022
1 parent a8f8b86 commit a6030e7
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
import * as core from '@actions/core'
import {wait} from './wait'
import * as exec from '@actions/exec'
import * as github from '@actions/github'

async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
const deployedRevision = core.getInput('deployed_revision')
if (!deployedRevision) {
throw new Error('deployed_revision is required!')
}
core.debug(`Deployed revision: ${deployedRevision}`)

core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
const nextRevision = core.getInput('next_revision') || github.context.sha
core.debug(`Next revision: ${nextRevision}`)

try {
exec.exec('git', ['log', deployedRevision])
exec.exec('git', ['log', nextRevision])
} catch (error) {
core.warning(
`One of the revisions doesnt exists, returning empty lists${
error instanceof Error ? `: ${error.message}` : ''
}`
)
return
}

const newCommitsCount = getNumberOrCommits(deployedRevision, nextRevision)
const removedCommitsCount = getNumberOrCommits(
nextRevision,
deployedRevision
)

core.info(newCommitsCount.toString())
core.info(removedCommitsCount.toString())

core.setOutput('time', new Date().toTimeString())
} catch (error) {
Expand All @@ -17,3 +41,16 @@ async function run(): Promise<void> {
}

run()

function getNumberOrCommits(base: string, head: string): number {
let count = 0
exec.exec('git', ['log', `${base}..${head}`], {
listeners: {
stdline(line) {
count++
core.info(line)
}
}
})
return count
}

0 comments on commit a6030e7

Please sign in to comment.