Skip to content

Commit

Permalink
feat: Added the GitHub actions for cli (#284)
Browse files Browse the repository at this point in the history
* feat: Added the GitHub actions for cli

* Fixed the issue of use and run

* Refactoring the code and addresed the review comments

* Added condition to return if changes are already in changelog

* Seperated semantic release related configuration to another file and getting the tag from semantic release

* Added the workflow inputs

* Update release.yml

* Update release.yml

Co-authored-by: lakshmiravali <lakshmiravali.rimmalapudi@gmail.com>
  • Loading branch information
ravali-rimmalapudi and lakshmiravalir committed Sep 10, 2021
1 parent dd03112 commit 49e2376
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 17 deletions.
31 changes: 31 additions & 0 deletions .github/scripts/commit-api-spec-change-log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
echo "Running update changelog script"
changeLog="$1"
versionType="$2"
echo "$changeLog"
node .github/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 [ "$versionType" == 0 ] || [ "$versionType" == 1 ]
then
commitMessage='feat: Updated api definitions changelog in CHANGES.md'
elif [ "$versionType" == 2 ]
then
commitMessage='fix: Updated api definitions changelog in CHANGES.md'
else
echo "Invalid versionType: $versionType";
exit
fi
echo "Commit message:$commitMessage"
git commit -m "$commitMessage"
git push origin "$branch"
else
echo "No changes to commit";
fi
32 changes: 32 additions & 0 deletions .github/scripts/update-change-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* 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);
if (data.toString().includes(changes)) {
console.log(`Provided changes are already in cli changelog : ${changes}`);
return;
}
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();
})();
83 changes: 66 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,69 @@
name: Cli-core Release
name: Cli Release
on:
workflow_dispatch:
inputs:
change-log:
description: 'Open API Changelog.'
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: [14.x]
steps:
- name: Checkout cli-core repo
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 test
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- name: Checkout cli-core repo
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 test
update-api-definitions-changelog:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout cli
uses: actions/checkout@v2
- name: Update Changelog
run: |
bash .github/scripts/commit-api-spec-change-log.sh "${{ github.event.inputs.change-log }}" ${{ github.event.inputs.version-type }}
release:
runs-on: ubuntu-latest
needs: [update-api-definitions-changelog]
outputs:
tag-name: ${{ steps.semantic-release.outputs.TAG_NAME }}
steps:
- name: Checkout cli
uses: actions/checkout@v2
- name: Run git and npm update
run: |
git pull
npm install
- name: Semantic Release runs
id: semantic-release
run: npx semantic-release -t \${version}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-release:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- name: Checkout cli
uses: actions/checkout@v2
- name: Update release
if: ${{needs.release.outputs.tag-name != ''}}
uses: tubone24/update_release@v1.2.0
env:
GITHUB_TOKEN: ${{ github.token }}
TAG_NAME: ${{needs.release.outputs.tag-name}}
with:
is_append_body: true
body: ${{ github.event.inputs.change-log }}
79 changes: 79 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"branches": [
"main",
{
"name": "github_action_changes",
"prerelease": "rc"
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "angular",
"releaseRules": [{
"type": "chore",
"release": "patch"
}]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [{
"type": "feat",
"section": "Library - Features"
},
{
"type": "fix",
"section": "Library - Fixes"
},
{
"type": "chore",
"section": "Library - Chores"
},
{
"type": "test",
"section": "Library - Test"
},
{
"type": "docs",
"section": "Library - Docs"
}
]
}
}
],
[
"@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}"
}
],
[
"@semantic-release/exec",
{
"successCmd": "echo '::set-output name=TAG_NAME::${nextRelease.version}'"
}
]
]
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@
"devDependencies": {
"@oclif/dev-cli": "^1.22.2",
"@oclif/test": "^1.2.6",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"@twilio/cli-test": "^2.1.0",
"aws-sdk": "^2.757.0",
"chai": "^4.2.0",
"conventional-changelog-conventionalcommits": "^4.6.0",
"eslint": "^7.5.0",
"eslint-config-twilio": "~1.31.0",
"eslint-config-twilio-mocha": "~1.31.0",
Expand Down

0 comments on commit 49e2376

Please sign in to comment.