-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e795cc
commit 822a168
Showing
5 changed files
with
203 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Get Last Commit Hash' | ||
description: 'Gets the commit hash of the most recent successful run.' | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' | ||
inputs: | ||
workflow_name: | ||
description: The name of the workflow in question | ||
required: true | ||
branch: | ||
description: The name of the branch | ||
required: true | ||
github_token: | ||
description: The GitHub Token | ||
required: true | ||
outputs: | ||
commit_hash: # id of output | ||
description: 'The commit hash of the most recent successful run' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
|
||
async function go() { | ||
const {GITHUB_RUN_ID} = process.env | ||
|
||
const octokit = github.getOctokit(core.getInput('github_token')) | ||
const { | ||
repo: {owner, repo}, | ||
} = github.context | ||
|
||
const {data: current_run} = await octokit.actions.getWorkflowRun({ | ||
owner, | ||
repo, | ||
run_id: Number(GITHUB_RUN_ID), | ||
}) | ||
|
||
const { | ||
data: {workflow_runs}, | ||
} = await octokit.actions.listWorkflowRuns({ | ||
owner, | ||
repo, | ||
workflow_id: String(current_run.workflow_id), | ||
status: 'success', | ||
branch: current_run.head_branch, | ||
event: 'push', | ||
}) | ||
|
||
const headCommits = workflow_runs.map(run => { | ||
return run.head_commit | ||
}) | ||
|
||
const sortedHeadCommits = headCommits.sort((a, b) => { | ||
const dateA = new Date(a.timestamp) | ||
const dateB = new Date(b.timestamp) | ||
if (dateA < dateB) return -1 | ||
if (dateA > dateB) return 1 | ||
return 0 | ||
}) | ||
|
||
const lastSuccessCommitHash = | ||
sortedHeadCommits[sortedHeadCommits.length - 1].id | ||
|
||
core.setOutput('commit_hash', lastSuccessCommitHash) | ||
} | ||
|
||
go().then( | ||
() => core.info('Get Last Commit Hash Complete.'), | ||
error => { | ||
core.setFailed(error.message) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: 'Skip deploy' | ||
description: 'Outputs a variable to indicate whether deploy should be skipped' | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' | ||
inputs: | ||
start_commit: | ||
description: The starting commit to compare | ||
required: true | ||
deploy_regex: | ||
description: If any changed file matches this regex, it will deploy | ||
default: '.*' | ||
required: false | ||
skip_regex: | ||
description: | ||
Any of the files that match the deploy_regex will be further filtered with | ||
skip_regex. Deploy will be skipped if no files are left. | ||
required: true | ||
outputs: | ||
content_only: | ||
description: | ||
'"true" if only content was changed between the given commits and "false" | ||
if anything else was changed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// HT: @alexanderson1993 for creating the first version of this action ❤ | ||
|
||
const core = require('@actions/core') | ||
const github = require('@actions/github') | ||
|
||
async function go() { | ||
const skipRegexes = JSON.parse(github.getOctokit(core.getInput('skip_regex'))) | ||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/') | ||
const workflowName = core.getInput('workflow_name') | ||
|
||
const {data: repoWorkflows} = await octokit.actions.listRepoWorkflows({ | ||
owner, | ||
repo, | ||
}) | ||
const workflow = repoWorkflows.workflows.find( | ||
({name}) => name === workflowName, | ||
) | ||
|
||
const res = await octokit.actions.listWorkflowRuns({ | ||
owner, | ||
repo, | ||
workflow_id: workflow.id, | ||
status: 'success', | ||
branch: core.getInput('branch'), | ||
event: 'push', | ||
}) | ||
|
||
const headCommits = res.data.workflow_runs.map(run => { | ||
return run.head_commit | ||
}) | ||
|
||
const sortedHeadCommits = headCommits.sort((a, b) => { | ||
const dateA = new Date(a.timestamp) | ||
const dateB = new Date(b.timestamp) | ||
if (dateA < dateB) return -1 | ||
if (dateA > dateB) return 1 | ||
return 0 | ||
}) | ||
|
||
const lastSuccessCommitHash = | ||
sortedHeadCommits[sortedHeadCommits.length - 1].id | ||
|
||
core.setOutput('commit_hash', lastSuccessCommitHash) | ||
} | ||
|
||
go().then( | ||
() => core.info('Get Last Commit Hash Complete.'), | ||
error => { | ||
core.setFailed(error.message) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters