Skip to content

Commit

Permalink
feat: Added the GitHub actions for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmiravalir committed Aug 30, 2021
1 parent 0711e97 commit 5c05227
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/release.yml
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 }}
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"devDependencies": {
"@oclif/dev-cli": "^1.22.2",
"@oclif/test": "^1.2.6",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@twilio/cli-test": "^2.1.0",
"aws-sdk": "^2.757.0",
"chai": "^4.2.0",
Expand Down Expand Up @@ -120,5 +122,41 @@
}
},
"helpClass": "./src/services/twilio-help/custom-help"
},
"release": {
"branches": [
"main",
{
"name": "github_action_changes",
"prerelease": "rc"
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGES.md"
}
],
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": [
"CHANGES.md",
"package.json"
],
"message": "chore(release): set `package.json` to ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
}
30 changes: 30 additions & 0 deletions scripts/commit-api-spec-change-log.sh
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
28 changes: 28 additions & 0 deletions scripts/update-change-log.js
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();
})();

0 comments on commit 5c05227

Please sign in to comment.