Skip to content

Commit

Permalink
fix: npm and ext json version bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
lfilho committed Jul 26, 2020
1 parent 1d1ef53 commit 61a509b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@ jobs:
- name: Get version from package.json before the release step
id: pre_release_version
run: echo "::set-output name=version::$(npm run get-version --silent)"
- name: Release to GitHub
- name: Update package.json and release to GitHub
id: release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GIT_AUTHOR_NAME: ops-bot
GITAUTHOR_EMAIL: [email protected]
GIT_COMMITTER_NAME: ops-bot
GIT_COMMITTER_EMAIL: [email protected]
run: |
npm run release
npm run web-ext build
run: npm run release
- name: Get version from package.json after release step
id: post_release_version
run: echo "::set-output name=version::$(npm run get-version --silent)"
Expand Down
25 changes: 25 additions & 0 deletions bin/change-ext-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs';

const MANITFEST_FILE = 'src/manifest.json';
const newVersion = process.argv[2];

function exitWithError(error) {
console.log(error);
process.exit(2);
}

fs.readFile(MANITFEST_FILE, 'utf8', (err, fileContent) => {
if (err) {
exitWithError(err);
}
const newFileContent = fileContent.replace(
/"version": "\d+.\d+.\d+"/g,
`"version": "${newVersion}"`
);

fs.writeFile(MANITFEST_FILE, newFileContent, 'utf8', (err) => {
if (err) {
exitWithError(err);
}
});
});
16 changes: 15 additions & 1 deletion package-lock.json

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

28 changes: 22 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "sample-webextension",
"version": "1.0.1",
"private": true,
"description": "Second test project for - Tracker blocker extension",
"type": "module",
"main": "",
Expand All @@ -15,26 +16,30 @@
},
"homepage": "https://github.com/lfilho/sample-webextension#readme",
"scripts": {
"build": "npm run web-ext -- build",
"develop": "npm run web-ext -- run",
"format": "prettier --write \"**/*.{js,json,css,md}\"",
"//": "eslint is configured with prettier, so it will check and fix js formatting too",
"//eslint is configured with prettier, so it will check and fix js formatting too": "",
"lint": "npm run lint:js && npm run lint:ext",
"lint:ext": "npm run web-ext -- lint",
"lint:js": "eslint \"**/*.js\"",
"lint:js:fix": "npm run lint:js -- --fix",
"pretest": "npm run lint",
"release": "semantic-release",
"start": "npm run develop",
"test": "echo '//TODO' && exit 0",
"web-ext": "web-ext",
"get-version": "echo $npm_package_version"
"//Release related scripts:": "",
"release": "semantic-release",
"build": "npm run web-ext -- build",
"get-version": "echo $npm_package_version",
"change-ext-version": "node bin/change-ext-version.js"
},
"devDependencies": {
"@commitlint/cli": "8.3.5",
"@commitlint/config-conventional": "8.3.4",
"@semantic-release/commit-analyzer": "8.0.1",
"@semantic-release/exec": "5.0.0",
"@semantic-release/github": "7.0.7",
"@semantic-release/npm": "7.0.5",
"@semantic-release/release-notes-generator": "9.0.1",
"conventional-changelog-conventionalcommits": "4.3.0",
"eslint": "7.2.0",
Expand All @@ -56,7 +61,7 @@
"*.{json,css,md}": "npm run format --",
"*.js": [
"eslint --fix",
"web-ext lint"
"web-ext lint --"
]
},
"prettier": {
Expand All @@ -70,7 +75,8 @@
"env": {
"browser": true,
"es2017": true,
"webextensions": true
"webextensions": true,
"node": true
},
"plugins": [
"prettier"
Expand Down Expand Up @@ -100,6 +106,16 @@
"preset": "conventionalcommits"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "npm run change-ext-version -- ${nextRelease.version}",
"publishCmd": "npm run build"
}
],
[
"@semantic-release/npm"
],
[
"@semantic-release/github",
{
Expand Down

0 comments on commit 61a509b

Please sign in to comment.