forked from twilio/twilio-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
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 (twilio#284)
* 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 <[email protected]>
- Loading branch information
1 parent
dd03112
commit 49e2376
Showing
5 changed files
with
212 additions
and
17 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,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 "[email protected]" | ||
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 |
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,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(); | ||
})(); |
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 |
---|---|---|
@@ -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/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
TAG_NAME: ${{needs.release.outputs.tag-name}} | ||
with: | ||
is_append_body: true | ||
body: ${{ github.event.inputs.change-log }} |
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,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}'" | ||
} | ||
] | ||
] | ||
} |
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