-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added changes to use scripts instead of community Github actio…
…ns (#155) * Added changes to use scripts instead of community Github actions * Exporing the scripts to use in cli workflows * Update release.yml Co-authored-by: LakshmiRavali Rimmalapudi <lrimmalapudi@LakshmiRavalis-MacBook-Pro.local>
- Loading branch information
1 parent
5367ba5
commit 27bd508
Showing
5 changed files
with
154 additions
and
21 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,53 @@ | ||
const core = require('@actions/core'); | ||
const { Octokit } = require('@octokit/rest'); | ||
|
||
/** | ||
* Functionality from benc-uk/workflow-dispatch. | ||
* Link: https://github.com/benc-uk/workflow-dispatch | ||
*/ | ||
const triggerWorkflow = async () => { | ||
try { | ||
const octokit = new Octokit({ | ||
auth: process.env.REPO_WORKFLOW_TOKEN | ||
}); | ||
const workflowRef = process.env.WORKFLOW_NAME; | ||
const ref = process.env.BRANCH_NAME; | ||
const [owner, repo] = process.env.REPO_NAME | ||
? process.env.REPO_NAME.split('/') | ||
: [null, null]; | ||
|
||
// Decode inputs, this MUST be a valid JSON string | ||
let inputs = {} | ||
const inputsJson = process.env.INPUTS; | ||
if(inputsJson) { | ||
inputs = JSON.parse(inputsJson) | ||
} | ||
|
||
const workflow = await octokit.rest.actions.getWorkflow({ | ||
owner, | ||
repo, | ||
workflow_id: workflowRef | ||
}); | ||
|
||
core.info(`Workflow id is: ${workflow.data.id}`) | ||
|
||
const dispatchResp = await octokit.rest.actions.createWorkflowDispatch({ | ||
owner, | ||
repo, | ||
workflow_id: workflow.data.id, | ||
ref, | ||
inputs | ||
}); | ||
core.info(`API response status: ${dispatchResp.status} 🚀`) | ||
} catch (error) { | ||
core.setFailed(error.message) | ||
} | ||
} | ||
|
||
(async () => { | ||
await triggerWorkflow(); | ||
})(); | ||
|
||
module.exports = { | ||
triggerWorkflow, | ||
}; |
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,77 @@ | ||
const core = require('@actions/core'); | ||
const { GitHub } = require('@actions/github'); | ||
|
||
/** | ||
* Functionality from tubone24/update_release. | ||
* Link: https://github.com/tubone24/update_release | ||
*/ | ||
const updateRelease = async () => { | ||
try { | ||
const github = new GitHub(process.env.GITHUB_TOKEN); | ||
const [owner, repo] = process.env.REPO_NAME | ||
? process.env.REPO_NAME.split('/') | ||
: [null, null]; | ||
const tag = process.env.TAG_NAME; | ||
const getReleaseResponse = await github.repos.getReleaseByTag({ | ||
owner, | ||
repo, | ||
tag | ||
}); | ||
|
||
const { | ||
data: { | ||
id: oldReleaseId, | ||
html_url: oldHtmlUrl, | ||
upload_url: oldUploadUrl, | ||
body: oldBody, | ||
draft: oldDraft, | ||
name: oldName, | ||
prerelease: oldPrerelease | ||
} | ||
} = getReleaseResponse; | ||
|
||
core.info( | ||
`Got release info: '${oldReleaseId}', ${oldName}, '${oldHtmlUrl}', '${oldUploadUrl},'` | ||
) | ||
core.info(`Body: ${oldBody}`) | ||
core.info(`Draft: ${oldDraft}, Prerelease: ${oldPrerelease}`) | ||
|
||
const newBody = process.env.RELEASE_BODY; | ||
const newPrerelease = process.env.PRE_RELEASE; | ||
|
||
let body | ||
if (newBody === '') { | ||
body = oldBody | ||
} else { | ||
body = `${oldBody}\n${newBody}`; | ||
} | ||
|
||
let prerelease | ||
if (newPrerelease !== '' && !!newPrerelease) { | ||
prerelease = newPrerelease === 'true' | ||
} else { | ||
prerelease = oldPrerelease | ||
} | ||
|
||
await github.repos.updateRelease({ | ||
owner, | ||
release_id: oldReleaseId, | ||
repo, | ||
body, | ||
name: oldName, | ||
draft: oldDraft, | ||
prerelease | ||
}) | ||
|
||
core.info(`Updated release with body: ${body}`) | ||
} catch (error) { | ||
core.setFailed(error.message) | ||
} | ||
} | ||
(async () => { | ||
await updateRelease(); | ||
})(); | ||
|
||
module.exports = { | ||
updateRelease, | ||
}; |
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