Skip to content

Commit

Permalink
feat(@ci): AG-36 git tag task in ci
Browse files Browse the repository at this point in the history
implemented release tagging in main workflow
  • Loading branch information
g3k0 committed Apr 7, 2024
1 parent c9596a4 commit 9e0ec30
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ jobs:

- name: Run scripts unit tests
run: node ci --function scriptsUnitTest

- name: Tag the release with the version
run: node ci --function tagRelease
if: |
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
(github.event_name == 'pull_request' && github.base_ref == 'refs/heads/main' && github.event.action == 'closed' && github.event.pull_request.merged)
14 changes: 14 additions & 0 deletions ci/functions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const execSync = require("child_process").execSync;
const fs = require("fs");

const execSyncOptions = { stdio: "inherit" };

Expand All @@ -19,6 +20,19 @@ const functions = {
scriptsUnitTest: function () {
return execSync("npm run test-scripts", execSyncOptions);
},
tagRelease: function () {
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
const version = packageJson.version;

const tags = execSync("git tag", { encoding: "utf8" }).split("\n");

if (tags.includes(`v${version}`)) {
console.error(`Error: The tag for the version ${version} already exists`);
return;
}
execSync(`git tag -a v${version} -m "Version ${version}"`, execSyncOptions);
execSync("git push origin --tags", execSyncOptions);
},
};

module.exports = functions;
5 changes: 4 additions & 1 deletion ci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ if (args[3]) {
try {
functions[functionName](params);
} catch (e) {
console.error("Error: the function invoked does not exists");
console.error(
"Error: the function invoked does not exists or there is an error in the function",
);
console.error(e);
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "agora",
"version": "0.3.0",
"version": "0.4.0",
"description": "A confidentiality-first electronic voting system",
"author": {
"name": "nova collective",
Expand Down

0 comments on commit 9e0ec30

Please sign in to comment.