-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added the GitHub actions for cli
- Loading branch information
1 parent
0711e97
commit 5c05227
Showing
4 changed files
with
176 additions
and
0 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,80 @@ | ||
name: Cli Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
change-log: | ||
description: 'Open API Changelog, Please provide as a string.' | ||
required: true | ||
version-type: | ||
description: 'Version to upgrade, Major: 0, Minor:1, Patch: 2' | ||
required: true | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [10.x] | ||
steps: | ||
- name: Checkout to cli | ||
uses: actions/checkout@v2 | ||
run: npm install | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- name: Run tests | ||
run: | | ||
npm ci | ||
npm test | ||
update-api-definitions-changelog: | ||
runs-on: ubuntu-latest | ||
needs: [test] | ||
steps: | ||
- name: Checkout to cli | ||
uses: actions/checkout@v2 | ||
- name: Update Changelog | ||
run: | | ||
bash scripts/updateApiDefinitions.sh "${{ github.event.inputs.changeLog }}" ${{ github.event.inputs.versionType }} | ||
release: | ||
runs-on: ubuntu-latest | ||
needs: [update-api-definitions-changelog] | ||
steps: | ||
- name: Checkout to cli | ||
- uses: actions/checkout@v2 | ||
run: | | ||
git pull | ||
npm install | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- name: Semantic Release runs | ||
run: | | ||
npm install --save-dev @semantic-release/changelog @semantic-release/git | ||
npm ci | ||
npx semantic-release -t \${version} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
update-release: | ||
runs-on: ubuntu-latest | ||
needs: [ release ] | ||
steps: | ||
- name: Checkout to cli | ||
uses: actions/checkout@v2 | ||
- name: Getting tag | ||
id: get-tag | ||
run: | | ||
git fetch --tags | ||
echo "::set-output name=TAG_NAME::$(git describe --tags $(git rev-list --tags --max-count=1))" | ||
- run: echo "${{steps.get-tag.outputs.TAG_NAME}}" | ||
- name: Update release | ||
uses: tubone24/update_release@v1.2.0 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
TAG_NAME: ${{steps.get-tag.outputs.TAG_NAME}} | ||
with: | ||
is_append_body: true | ||
body: ${{ github.event.inputs.changeLog }} |
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,30 @@ | ||
#!/bin/sh | ||
echo "Running update changelog script" | ||
changeLog="$1" | ||
echo "$changeLog" | ||
node scripts/update-change-log.js "$changeLog" | ||
echo "Git configurations" | ||
git config --global user.email "team_interfaces+github@twilio.com" | ||
git config --global user.name "twilio-dx" | ||
git add -A | ||
if [ -n "$(git status --porcelain)" ]; then | ||
branch=$(git branch --show-current) | ||
echo "Current branch: $branch" | ||
echo "There are changes to commit."; | ||
commitMessage='' | ||
if [ "$2" == 0 ] || [ "$2" == 1 ] | ||
then | ||
commitMessage='feat: Updated api definitions changelog in CHANGES.md' | ||
elif [ "$2" == 2 ] | ||
then | ||
commitMessage='fix: Updated api definitions changelog in CHANGES.md' | ||
else | ||
echo "Invalid versionType: $2"; | ||
exit | ||
fi | ||
echo "Commit message:$commitMessage" | ||
git commit -m "$commitMessage" | ||
git push origin "$branch" | ||
else | ||
echo "No changes to commit"; | ||
fi |
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,28 @@ | ||
/* eslint-disable no-console */ | ||
const fs = require('fs'); | ||
|
||
const cliChangelogFilename = 'CHANGES.md'; | ||
|
||
const updateChangeLog = async () => { | ||
try { | ||
console.log('Updating the CHANGES.md'); | ||
const changes = process.argv[2]; | ||
if (changes) { | ||
const data = fs.readFileSync(cliChangelogFilename); | ||
const fd = fs.openSync(cliChangelogFilename, 'w+'); | ||
const insert = Buffer.from(changes); | ||
fs.writeSync(fd, insert, 0, insert.length, 0); | ||
fs.writeSync(fd, data, 0, data.length, insert.length); | ||
fs.close(fd, (err) => { | ||
if (err) throw err; | ||
}); | ||
} else { | ||
console.log('There are no changes provided'); | ||
} | ||
} catch (error) { | ||
console.log(`Error while updating the changelog: ${error}`); | ||
} | ||
}; | ||
(async () => { | ||
await updateChangeLog(); | ||
})(); |