From 61a509bc80bfaeab7b6109a84d41b6bbe6d85cfb Mon Sep 17 00:00:00 2001 From: Luiz Filho Date: Thu, 11 Jun 2020 16:17:54 -0700 Subject: [PATCH] fix: npm and ext json version bumps --- .github/workflows/release.yml | 7 +++---- bin/change-ext-version.js | 25 +++++++++++++++++++++++++ package-lock.json | 16 +++++++++++++++- package.json | 28 ++++++++++++++++++++++------ 4 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 bin/change-ext-version.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8801402..a9772ce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: ops-bot@luiz.dev GIT_COMMITTER_NAME: ops-bot GIT_COMMITTER_EMAIL: ops-bot@luiz.dev - 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)" diff --git a/bin/change-ext-version.js b/bin/change-ext-version.js new file mode 100644 index 0000000..830fe2e --- /dev/null +++ b/bin/change-ext-version.js @@ -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); + } + }); +}); diff --git a/package-lock.json b/package-lock.json index ba9026d..5d6a294 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "sample-webextension", - "version": "0.0.1", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -773,6 +773,20 @@ "integrity": "sha512-9Tj/qn+y2j+sjCI3Jd+qseGtHjOAeg7dU2/lVcqIQ9TV3QDaDXDYXcoOHU+7o2Hwh8L8ymL4gfuO7KxDs3q2zg==", "dev": true }, + "@semantic-release/exec": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@semantic-release/exec/-/exec-5.0.0.tgz", + "integrity": "sha512-t7LWXIvDJQbuGCy2WmMG51WyaGSLTvZBv9INvcI4S0kn+QjnnVVUMhcioIqhb0r3yqqarMzHVcABFug0q0OXjw==", + "dev": true, + "requires": { + "@semantic-release/error": "^2.1.0", + "aggregate-error": "^3.0.0", + "debug": "^4.0.0", + "execa": "^4.0.0", + "lodash": "^4.17.4", + "parse-json": "^5.0.0" + } + }, "@semantic-release/github": { "version": "7.0.7", "resolved": "https://registry.npmjs.org/@semantic-release/github/-/github-7.0.7.tgz", diff --git a/package.json b/package.json index 4a51640..7e83de2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "sample-webextension", "version": "1.0.1", + "private": true, "description": "Second test project for - Tracker blocker extension", "type": "module", "main": "", @@ -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", @@ -56,7 +61,7 @@ "*.{json,css,md}": "npm run format --", "*.js": [ "eslint --fix", - "web-ext lint" + "web-ext lint --" ] }, "prettier": { @@ -70,7 +75,8 @@ "env": { "browser": true, "es2017": true, - "webextensions": true + "webextensions": true, + "node": true }, "plugins": [ "prettier" @@ -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", {