Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
fix(semantic-release): move to dotenv and release.scripts.js
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Dec 11, 2018
1 parent 82507ff commit a0d82b7
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
6 changes: 0 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,3 @@

# Generate a token in your Github settings -> Developer settings -> Personal access tokens
GH_TOKEN=XXXXX

# Frontibotito name and your email for Git commits (do not change)
GIT_AUTHOR_NAME=Frontibotito
GIT_AUTHOR_EMAIL=frontibotito@frontity.com
GIT_COMMITTER_NAME=Frontibotito
GIT_COMMITTER_EMAIL=frontibotito@frontity.com
32 changes: 7 additions & 25 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"scripts": {
"grunt": "grunt",
"cz": "git-cz",
"semantic-release": "env-cmd .env semantic-release",
"sr:prepare": "env-cmd .env node release/prepare.js",
"sr:success": "env-cmd .env node release/success.js"
"semantic-release": "semantic-release"
},
"repository": {
"type": "git",
Expand All @@ -36,13 +34,14 @@
"@semantic-release/npm": "^3.4.1",
"commitizen": "^2.10.1",
"cz-conventional-changelog": "^2.1.0",
"env-cmd": "^8.0.2",
"dotenv": "^6.2.0",
"grunt": "^1.0.3",
"grunt-cli": "^1.3.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-uglify": "^3.4.0",
"grunt-wp-readme-to-markdown": "^2.0.1",
"husky": "^1.0.0",
"minimist": "^1.2.0",
"replace-in-file": "^3.4.2",
"semantic-release": "^15.9.16",
"semantic-release-cli": "^4.0.8",
Expand Down
6 changes: 4 additions & 2 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('dotenv').config()

process.env.GIT_AUTHOR_NAME = 'Frontibotito';
process.env.GIT_AUTHOR_EMAIL = 'frontibotito@frontity.com';
process.env.GIT_COMMITTER_NAME = 'Frontibotito';
Expand All @@ -14,7 +16,7 @@ module.exports = {
'@semantic-release/npm',
{
path: '@semantic-release/exec',
cmd: 'npm run sr:prepare',
cmd: 'node release.scripts.js --prepare',
},
{
path: '@semantic-release/git',
Expand All @@ -26,7 +28,7 @@ module.exports = {
success: [
{
path: '@semantic-release/exec',
cmd: 'npm run sr:success',
cmd: 'node release.scripts.js --success',
},
'@semantic-release/github',
],
Expand Down
45 changes: 45 additions & 0 deletions release.scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const argv = require("minimist")(process.argv.slice(2));
const connect = require("simple-git/promise");
const replace = require("replace-in-file");
const packageJson = require("./package.json");

const success = async () => {
try {
const repo = await connect(".");
const remotes = await repo.getRemotes(true);
const originPush = remotes[0].refs.push;
const authOrigin = originPush.replace(
"https://",
`https://${process.env.GH_TOKEN}@`
);
await repo.checkout("dev");
await repo.raw(["rebase", "--root", "dev", "--onto", "master"]);
await repo.push("origin", "dev", `--repo=${authOrigin}`);
await repo.push("origin", "master", `--repo=${authOrigin}`);
console.log("Rebase finished.");
} catch (error) {
console.error("Error occurred:", error);
}
};

const prepare = async () => {
const options = {
files: "wp-pwa.php",
from: [/Version: \d+\.\d+\.\d+/, /plugin_version = '\d+\.\d+\.\d+'/],
to: [
`Version: ${packageJson.version}`,
`plugin_version = '${packageJson.version}'`
]
};
try {
const changes = await replace(options);
console.log("Modified files:", changes.join(", "));
} catch (error) {
console.error("Error occurred:", error);
}
};

(async () => {
if (argv.success) await success();
else if (argv.prepare) await prepare();
})();

0 comments on commit a0d82b7

Please sign in to comment.