Skip to content

Commit

Permalink
fix: bump version update (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlianaB authored Sep 26, 2022
1 parent 62879fb commit f538132
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
32 changes: 6 additions & 26 deletions .github/actions/bump-version/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path');
const fsPromises = require('fs').promises;
const core = require('@actions/core');
const github = require('@actions/github');
const exec = require('@actions/exec');
Expand All @@ -16,36 +15,17 @@ const run = async () => {
});

core.info('Set variables');
const version = latestRelease.data.tag_name;
const filePaths = [{
filePath: 'package.json',
formatSpaces: 2
}, {
filePath: 'app/manifest.json',
formatSpaces: 4
}];
const version = latestRelease.data.tag_name.slice(1);

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);
await exec.exec('node', [path.join(process.env.GITHUB_WORKSPACE, './scripts/update-version.js'), version]);

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.name', 'github-actions']);
await exec.exec('git', ['config', '--global', 'user.email', '[email protected]']);
await exec.exec('git', ['checkout', '-b', `bump-version-${version}`]);
await exec.exec('git', ['commit', '-am', `chore: release ${version}`]);
await exec.exec('git', ['push', '-u', 'origin', `HEAD:master`]);
await exec.exec('git', ['push', '-u', 'origin', `bump-version-${version}`]);
await exec.exec('gh', ['pr', 'create', '--fill']);
};

run()
Expand Down
6 changes: 6 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/exec",
{
"prepareCmd": "node ./scripts/update-version.js ${nextRelease.version} && npm i"
}
],
[
"@semantic-release/github",
{
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const path = require('path');
const args = process.argv.slice(2);
console.log('Updating version - ' + args[0]);

const packagePath = path.join(__dirname, '../package.json')
const manifestPath = path.join(__dirname, '../app/manifest.json')
const packagePath = path.join(path.dirname(__dirname), 'package.json');
const manifestPath = path.join(path.dirname(__dirname), 'app/manifest.json');

const version = args[0];
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
Expand Down

0 comments on commit f538132

Please sign in to comment.