-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add bump version workflow (#189)
- Loading branch information
Showing
5 changed files
with
18,866 additions
and
2,348 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,5 @@ | ||
name: 'Bump version' | ||
description: 'Bump version in files' | ||
runs: | ||
using: 'node16' | ||
main: 'index.js' |
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,53 @@ | ||
const path = require('path'); | ||
const fsPromises = require('fs').promises; | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const exec = require('@actions/exec'); | ||
|
||
const run = async () => { | ||
core.info('Setup octokit'); | ||
const octokit = github.getOctokit(process.env.GITHUB_TOKEN); | ||
const { owner, repo } = github.context.repo; | ||
|
||
core.info('Fetch latest release info'); | ||
const latestRelease = await octokit.rest.repos.getLatestRelease({ | ||
owner, | ||
repo, | ||
}); | ||
|
||
core.info('Set variables'); | ||
const version = latestRelease.data.tag_name; | ||
const filePaths = [{ | ||
filePath: 'package.json', | ||
formatSpaces: 2 | ||
}, { | ||
filePath: 'app/manifest.json', | ||
formatSpaces: 4 | ||
}]; | ||
|
||
core.info('Update files version field'); | ||
for (let fileObj of filePaths) { | ||
let { filePath, formatSpaces } = fileObj; | ||
filePath = path.join(process.env.GITHUB_WORKSPACE, filePath); | ||
const content = await fsPromises.readFile(filePath); | ||
const parsedContent = JSON.parse(content); | ||
const newVersion = version.slice(1); | ||
|
||
if (parsedContent.version === newVersion) { | ||
core.info('No new version to update!'); | ||
return; | ||
} | ||
|
||
parsedContent.version = newVersion; | ||
await fsPromises.writeFile(filePath, JSON.stringify(parsedContent, null, formatSpaces)); | ||
} | ||
|
||
await exec.exec('git', ['config', '--global', 'user.name', 'UI5 Inspector BOT']); | ||
await exec.exec('git', ['config', '--global', 'user.email', '[email protected]']); | ||
await exec.exec('git', ['commit', '-am', `chore: release ${version}`]); | ||
await exec.exec('git', ['push', '-u', 'origin', `HEAD:master`]); | ||
}; | ||
|
||
run() | ||
.then(() => core.info('Updated files version successfully')) | ||
.catch(error => core.setFailed(error.message)); |
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
Oops, something went wrong.