forked from twilio/twilio-cli-core
-
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.
Changes: 1. Added workflow file 2. Added scripts to update the changelog in cli-core 3. Added the actions to bump the version and release to GitHub
- Loading branch information
1 parent
33cc65d
commit 01a4fc5
Showing
6 changed files
with
304 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,84 @@ | ||
name: Cli-core Release | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [10.x] | ||
steps: | ||
- 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' | ||
- run: npm ci | ||
- run: npm test | ||
updateAPIDefinitions: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
outputs: | ||
changeLog: ${{ steps.updateFolder.outputs.changeLog }} | ||
steps: | ||
- run: mkdir -p ~/oai_definitions/json | ||
- run: cd ~/oai_definitions | ||
- run: pwd | ||
- run: ls | ||
- uses: actions/checkout@v2 | ||
with: | ||
repository: 'twilio/twilio-oai' | ||
token: ${{ secrets.OAI_TOKEN }} | ||
- run: | | ||
cp -R spec/json/. ~/oai_definitions/json/ | ||
cp -R CHANGES.md ~/oai_definitions/CHANGES.md | ||
- uses: actions/checkout@v2 | ||
- name: Update OAI folder | ||
id: updateFolder | ||
run: | | ||
npm install | ||
cp -R ~/oai_definitions/CHANGES.md OAI_CHANGES.md | ||
source scripts/update-api-spec-with-changelog.sh | ||
echo "::set-output name=changeLog::$changeLog" | ||
release: | ||
runs-on: ubuntu-latest | ||
needs: [updateAPIDefinitions] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: git pull | ||
- run: npm install | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- name: semanticRelease | ||
run: npm install --save-dev @semantic-release/changelog @semantic-release/git | ||
- run: npm ci && npx semantic-release -t \${version} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
updateRelease: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [10.x] | ||
needs: [updateAPIDefinitions, release] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- run: git fetch --tags | ||
- name: Getting tag | ||
id: getTag | ||
run: | | ||
echo "::set-output name=TAG_NAME::$(git describe --tags $(git rev-list --tags --max-count=1))" | ||
- run: echo "${{steps.getTag.outputs.TAG_NAME}}" | ||
- name: update release | ||
id: update_release | ||
uses: tubone24/update_release@v1.2.0 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
TAG_NAME: ${{steps.getTag.outputs.TAG_NAME}} | ||
with: | ||
is_append_body: true | ||
body: ${{needs.updateAPIDefinitions.outputs.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,117 @@ | ||
const fs = require('fs'); | ||
const readline = require('readline'); | ||
|
||
const { logger } = require('../src/services/messaging/logging'); | ||
|
||
const defaultVersionRegex = /(\d+)\.(\d+)\.(\d+)/; | ||
const defaultDateRegex = /\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/; | ||
const cliCoreChangelogFile = 'CHANGES.md'; | ||
const oaiChangelogFile = 'OAI_CHANGES.md'; | ||
|
||
class ChangeLogHelper { | ||
constructor( | ||
cliCoreChangelogFilename = cliCoreChangelogFile, | ||
oaiChangelogFilename = oaiChangelogFile, | ||
versionRegex = defaultVersionRegex, | ||
dateRegex = defaultDateRegex, | ||
) { | ||
this.versionRegex = versionRegex; | ||
this.dateRegex = dateRegex; | ||
this.cliCoreChangelogFilename = cliCoreChangelogFilename; | ||
this.oaiChangelogFilename = oaiChangelogFilename; | ||
this.logger = logger; | ||
} | ||
|
||
async getAllReleaseVersionsFromGivenDate(date) { | ||
this.logger.info(`Started detecting the versions from the date: ${date}`); | ||
const versions = []; | ||
const readLine = await this.getReadLiner(this.oaiChangelogFilename); | ||
for await (const line of readLine) { | ||
const currentDate = this.dateRegex.exec(line); | ||
if (currentDate) { | ||
const version = this.versionRegex.exec(line); | ||
if (version) { | ||
versions.push(version[0]); | ||
} | ||
if (currentDate[0] <= date) { | ||
break; | ||
} | ||
} | ||
} | ||
this.logger.info(`Detected Versions: ${versions}`); | ||
return versions; | ||
} | ||
|
||
async getLatestChangelogGeneratedDate() { | ||
this.logger.info('Started detecting the latest date in cli core changelog'); | ||
let latestDate; | ||
const readLine = await this.getReadLiner(this.cliCoreChangelogFilename); | ||
for await (const line of readLine) { | ||
latestDate = this.dateRegex.exec(line); | ||
if (latestDate) { | ||
latestDate = latestDate[0]; | ||
this.logger.info(`Detected the latest Date: ${latestDate}`); | ||
break; | ||
} | ||
} | ||
return latestDate; | ||
} | ||
|
||
async getChangesAfterGivenDate(date) { | ||
this.logger.info(`Started getting the changelog from given date: ${date}`); | ||
let readLines = false; | ||
let fileData = ''; | ||
const readLine = await this.getReadLiner(this.oaiChangelogFilename); | ||
for await (const line of readLine) { | ||
const currentDate = this.dateRegex.exec(line); | ||
if (currentDate) { | ||
if (currentDate[0] > date) { | ||
this.logger.info('Reading the lines'); | ||
readLines = true; | ||
} else { | ||
this.logger.info(`Changes from OpenAPI specs: ${fileData}`); | ||
break; | ||
} | ||
} else if (readLines) { | ||
fileData += `${line}\n`; | ||
} | ||
} | ||
return fileData; | ||
} | ||
|
||
async appendChangesToChangelog() { | ||
this.logger.info('Started getAndAppendChangesToChangelog'); | ||
const latestDate = await this.getLatestChangelogGeneratedDate(); // changes.md | ||
if (latestDate) { | ||
const changeLog = await this.getChangesAfterGivenDate(latestDate); // oai_changes.md | ||
if (changeLog) { | ||
try { | ||
this.logger.info('Updating the CHANGES.md'); | ||
const data = fs.readFileSync(this.cliCoreChangelogFilename); | ||
const fd = fs.openSync(this.cliCoreChangelogFilename, 'w+'); | ||
const insert = Buffer.from(changeLog); | ||
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; | ||
}); | ||
fs.writeFileSync('changeLog.md', changeLog); | ||
} catch (error) { | ||
this.logger.error(`Error while updating the changelog: ${error}`); | ||
} | ||
return changeLog; | ||
} | ||
} | ||
return ''; | ||
} | ||
|
||
async getReadLiner(filename) { | ||
const fileStream = fs.createReadStream(filename); | ||
return readline.createInterface({ | ||
input: fileStream, | ||
}); | ||
} | ||
} | ||
module.exports = { | ||
ChangeLogHelper, | ||
}; |
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,20 @@ | ||
/* eslint-disable no-console */ | ||
const { ChangeLogHelper } = require('./change-log-helper'); | ||
|
||
const ch = new ChangeLogHelper(); | ||
|
||
const getVersionType = async () => { | ||
const latestDate = await ch.getLatestChangelogGeneratedDate(); | ||
const versions = await ch.getAllReleaseVersionsFromGivenDate(latestDate); | ||
if (versions.length >= 2) { | ||
const version1 = versions[0].split('.'); | ||
const version2 = versions[versions.length - 1].split('.'); | ||
for (let i = 0; i < 3; i++) { | ||
if (version1[i] !== version2[i]) return i; | ||
} | ||
} | ||
return -1; | ||
}; | ||
(async () => { | ||
console.log(await getVersionType()); | ||
})(); |
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,41 @@ | ||
#!/bin/sh | ||
echo "Copying api-definitions" | ||
cp -R ~/oai_definitions/json/. src/services/twilio-api/ | ||
echo "Running update changelog script" | ||
node scripts/update-change-log.js | ||
changeLog=$(cat changeLog.md) | ||
rm -rf changeLog.md | ||
if [ "$changeLog" != '' ]; then | ||
changeLog="${changeLog//'%'/'%25'}" | ||
changeLog="${changeLog//$'\n'/'%0A'}" | ||
changeLog="${changeLog//$'\r'/'%0D'}" | ||
fi | ||
echo "Changelog: $changeLog" | ||
versionType=$(node scripts/get-version-type.js | tail -n -1) | ||
echo "Version type: $versionType" | ||
rm -rf OAI_CHANGES.md | ||
echo "Git configurations" | ||
git config --global user.email "lakshmiravali.rimmalapudi@gmail.com" | ||
git config --global user.name "lakshmiravali" | ||
branch=$(git branch --show-current) | ||
echo "Current branch: $branch" | ||
git add -A | ||
if [ -n "$(git status --porcelain)" ]; then | ||
echo "There are changes to commit."; | ||
commitMessage='' | ||
if [ "$versionType" == 0 ] || [ "$versionType" == 1 ] | ||
then | ||
commitMessage='feat: Updated api definitions' | ||
elif [ "$versionType" == 2 ] | ||
then | ||
commitMessage='fix: Updated api definitions' | ||
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,10 @@ | ||
const { ChangeLogHelper } = require('./change-log-helper'); | ||
|
||
const ch = new ChangeLogHelper(); | ||
|
||
const updateChangeLog = async () => { | ||
return ch.appendChangesToChangelog(); | ||
}; | ||
(async () => { | ||
await updateChangeLog(); | ||
})(); |