Skip to content

Commit

Permalink
ci: Use node to set npm version (will be reused with electron-packager)
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Feb 1, 2020
1 parent acbe6e8 commit ac4e772
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: |
VERSION=$(echo $GITHUB_REF | sed 's/refs\/tags\/v//')
echo New Version is $VERSION
npm version --no-git-tag-version ${VERSION}
./utils/version-from-tag.js
- name: Publish
run: |
export NPM_TOKEN=${{ secrets.NPM_TOKEN }}
Expand Down
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "electronim",
"version": "0.0.0",
"description": "Electron based multi IM client",
"description": "Free/Libre open source Electron based multi instant messaging (IM) client.",
"main": "src/index.js",
"bin": {
"electronim": "bin.js"
Expand All @@ -23,9 +23,14 @@
},
"keywords": [
"electron",
"electronim",
"IM",
"chat",
"tabs"
"tabs",
"messaging",
"telegram",
"whatsapp",
"slack"
],
"author": {
"name": "Marc Nuri",
Expand All @@ -42,6 +47,17 @@
"url": "https://github.com/manusa/electronim/issues"
},
"homepage": "https://github.com/manusa/electronim#readme",
"build":{
"appId": "com.marcnuri.electronim",
"productName": "ElectronIM",
"copyright": "Copyright 2019 Marc Nuri",
"win": {
"target": [
"zip",
"portable"
]
}
},
"devDependencies": {
"electron-packager": "^14.1.1",
"eslint": "^6.8.0",
Expand Down
7 changes: 7 additions & 0 deletions utils/error-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable no-console */

const errorHandler = error => {
console.error(error);
};

module.exports = errorHandler;
31 changes: 31 additions & 0 deletions utils/version-from-tag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
/* eslint-disable no-console */

const childProcess = require('child_process');
const errorHandler = require('./error-handler');
const refPrefix = 'refs\\/tags\\/v';

const extractVersionFromTag = () => {
const githubRef = process.env.GITHUB_REF;
if (githubRef && githubRef.startsWith('refs\\/tags\\/v')) {
return githubRef.replace(refPrefix, '');
}
return null;
};

const versionFromTag = () => {
const version = extractVersionFromTag();
if (!version) {
console.error('No version specified in $GITHUB_REF environment variable');
process.exit(1);
}
console.log(`Setting project version to ${version}`);
childProcess.execSync(` npm version --no-git-tag-version ${version}`, {
env: {...process.env},
stdio: 'inherit'
});
process.exit(0);
};

process.on('unhandledRejection', errorHandler);
versionFromTag();

0 comments on commit ac4e772

Please sign in to comment.