Skip to content

chore:Added changes to use scripts instead of community Github actions #155

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

Merged
merged 3 commits into from
Sep 28, 2021
Merged
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
53 changes: 53 additions & 0 deletions .github/scripts/trigger-workflow.js
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,
};
77 changes: 77 additions & 0 deletions .github/scripts/update-release.js
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,
};
38 changes: 17 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,27 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
update-release:
runs-on: ubuntu-latest
needs: [update-api-specs, release]
steps:
- name: Checkout cli-core repo
uses: actions/checkout@v2
- name: Update release
if: ${{needs.release.outputs.tag-name != ''}}
uses: tubone24/[email protected]
run: node .github/scripts/update-release.js
env:
GITHUB_TOKEN: ${{ github.token }}
TAG_NAME: ${{needs.release.outputs.tag-name}}
with:
is_append_body: true
body: ${{needs.update-api-specs.outputs.change-log}}
TAG_NAME: ${{ steps.semantic-release.outputs.TAG_NAME }}
RELEASE_BODY: ${{needs.update-api-specs.outputs.change-log}}
REPO_NAME: twilio/twilio-cli-core
triggerCliWorkflow:
runs-on: ubuntu-latest
needs: [ update-api-specs, update-release]
needs: [ update-api-specs, release]
steps:
- name: Checkout cli-core repo
uses: actions/checkout@v2
- run: |
git pull
npm install
- name: Invoke CLI workflow with changelog and version-type
if: ${{toJSON(needs.update-api-specs.outputs.change-log) != null && needs.update-api-specs.outputs.version-type != -1}}
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Cli Release
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repo: twilio/twilio-cli
ref: ${{ github.event.inputs.cli-branch }}
inputs: '{ "change-log": ${{ toJSON(needs.update-api-specs.outputs.change-log) }}, "version-type": "${{needs.update-api-specs.outputs.version-type}}", "homebrew-branch": "${{github.event.inputs.homebrew-branch}}", "homebrew-prerelease": "${{github.event.inputs.homebrew-prerelease}}" }'
run: node .github/scripts/trigger-workflow.js
env:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
WORKFLOW_NAME: 'release.yml'
BRANCH_NAME: ${{github.event.inputs.cli-branch}}
REPO_NAME: twilio/twilio-cli
INPUTS: '{ "change-log": ${{ toJSON(needs.update-api-specs.outputs.change-log) }}, "version-type": "${{needs.update-api-specs.outputs.version-type}}", "homebrew-branch": "${{github.event.inputs.homebrew-branch}}", "homebrew-prerelease": "${{github.event.inputs.homebrew-prerelease}}" }'
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
"twilio": "^3.54.2"
},
"devDependencies": {
"@actions/core": "^1.0.0",
"@actions/github": "^2.2.0",
"@oclif/test": "^1.2.6",
"@octokit/rest": "^18.10.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ module.exports = {
secureStorage: require('./services/secure-storage'),
},
configureEnv: require('./services/env'),
releaseScripts: {
UpdateRelease: require('../.github/scripts/update-release'),
TriggerWorkflow: require('../.github/scripts/trigger-workflow'),
},
};