Skip to content

Commit

Permalink
chore: add bump version workflow (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlianaB authored Sep 1, 2022
1 parent 0101566 commit 62879fb
Show file tree
Hide file tree
Showing 5 changed files with 18,866 additions and 2,348 deletions.
5 changes: 5 additions & 0 deletions .github/actions/bump-version/action.yml
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'
53 changes: 53 additions & 0 deletions .github/actions/bump-version/index.js
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));
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
- name: Bump Version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ./.github/actions/bump-version
Loading

0 comments on commit 62879fb

Please sign in to comment.