-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat: switch to tagless workflow success check #2
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ac7c55b
feat: switch to tagless workflow success check
meeroslav 813443a
docs: add more documentation to readme
meeroslav ee7951c
feat: get workflow_id from API instead of param
meeroslav af2740f
feat: keep workflow-id as an optional param
meeroslav 96c4ba2
Update README.md
meeroslav c0d1652
Update README.md
meeroslav 79cefc8
feat: update readme
meeroslav 38197b9
feat: replace GITHUB_TOKEN with internal token
meeroslav d1f0d5b
chore: fix typo
meeroslav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,53 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
|
||
# Unplanned lock files | ||
yarn.lock | ||
pnpm-lock.yml | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Compiled files | ||
dist | ||
tmp | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# IDE | ||
.idea | ||
.vscode | ||
|
||
.DS_Store |
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,22 @@ | ||
(The MIT License) | ||
|
||
Copyright (c) 2021-present Narwhal Technologies Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
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
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,69 @@ | ||
const { Octokit } = require("@octokit/action"); | ||
const core = require("@actions/core"); | ||
const { execSync } = require('child_process'); | ||
|
||
const token = process.argv[2]; | ||
const branch = process.argv[3]; | ||
const workflowId = process.argv[4]; | ||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/"); | ||
const run_id = process.env.GITHUB_RUN_ID; | ||
process.env.GITHUB_TOKEN = token; | ||
|
||
(async () => { | ||
try { | ||
const octokit = new Octokit(); | ||
let workflow_id = workflowId; | ||
if (!workflow_id) { | ||
// retrieve workflow-id | ||
workflow_id = await octokit.request(`GET /repos/${owner}/${repo}/actions/runs/${run_id}`, { | ||
owner, | ||
repo, | ||
branch, | ||
run_id | ||
}).then(({ data: { workflow_id } }) => workflow_id); | ||
} | ||
// fetch all workflow runs on a given repo/branch/workflow with push and success | ||
const shas = await octokit.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, { | ||
owner, | ||
repo, | ||
branch, | ||
workflow_id, | ||
event: 'push', | ||
status: 'success' | ||
}).then(({ data: { workflow_runs } }) => workflow_runs.map(run => run.head_sha)); | ||
|
||
const sha = await findExistingCommit(shas); | ||
console.log(sha); | ||
} catch (e) { | ||
core.setFailed(e.message); | ||
process.exit(1); | ||
} | ||
})(); | ||
|
||
/** | ||
* Get first existing commit | ||
* @param {string[]} commit_shas | ||
* @returns {string?} | ||
*/ | ||
async function findExistingCommit(shas) { | ||
for (const commitSha of shas) { | ||
if (await commitExists(commitSha)) { | ||
return commitSha; | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Check if given commit is valid | ||
* @param {string} commitSha | ||
* @returns {boolean} | ||
*/ | ||
async function commitExists(commitSha) { | ||
try { | ||
execSync(`git cat-file -e ${commitSha} 2> /dev/null`); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬 typo again "if can find"