Skip to content

Commit

Permalink
chore: 🤖 add git-release.js
Browse files Browse the repository at this point in the history
  • Loading branch information
little-buddy committed Sep 9, 2023
1 parent b85497d commit 5f8dab7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
lib/
/scripts/
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"react-native-gesture-handler": "^2.12.1",
"react-native-reanimated": "3.3.0",
"release-it": "^16.1.5",
"simple-git": "^3.19.1",
"source-map-support": "^0.5.21",
"typescript": "^5.0.2"
},
Expand Down
45 changes: 45 additions & 0 deletions scripts/git-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const Git = require('simple-git').default;

const pkg = require('../package.json');

const git = Git();

const remoteName = 'origin';
const mainBranch = 'main';

const run = async () => {
let errorMsg = '';
try {
await git.addRemote(remoteName, pkg.repository.url);
} catch (error) {
errorMsg === error.message;
}

if (errorMsg && errorMsg !== 'error: remote origin already exists.') {
throw new Error(errorMsg);
}

await git.checkout(`${remoteName}/${mainBranch}`);
const remoteLog = await git.log();
const remoteHead = remoteLog.latest.hash;
await git.checkout(mainBranch);
const localLog = await git.log();
const localHead = localLog.latest.hash;

// update done.
if (localHead !== remoteHead) {
await git.push(remoteName, mainBranch);
}

// git tag release && git push origin tag release && git tag -d release

await git.addTag('release');
await git.push(remoteName, mainBranch, ['tag', 'release']);
// await git.tag

// const res = await git.diff();

// console.log(res);
};

run();
21 changes: 21 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,18 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@kwsites/file-exists@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@kwsites/file-exists/-/file-exists-1.1.1.tgz#ad1efcac13e1987d8dbaf235ef3be5b0d96faa99"
integrity sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==
dependencies:
debug "^4.1.1"

"@kwsites/promise-deferred@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@kwsites/promise-deferred/-/promise-deferred-1.1.1.tgz#8ace5259254426ccef57f3175bc64ed7095ed919"
integrity sha512-GaHYm+c0O9MjZRu0ongGBRbinu8gVAMd2UZjji6jVmqKtZluZnptXGWhz1E8j8D2HJ3f/yMxKAUC0b+57wncIw==

"@ljharb/through@^2.3.9":
version "2.3.9"
resolved "https://registry.yarnpkg.com/@ljharb/through/-/through-2.3.9.tgz#85f221eb82f9d555e180e87d6e50fb154af85408"
Expand Down Expand Up @@ -8558,6 +8570,15 @@ signal-exit@^3.0.2, signal-exit@^3.0.3, signal-exit@^3.0.7:
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==

simple-git@^3.19.1:
version "3.19.1"
resolved "https://registry.yarnpkg.com/simple-git/-/simple-git-3.19.1.tgz#ff9c021961a3d876a1b115b1893bed9a28855d30"
integrity sha512-Ck+rcjVaE1HotraRAS8u/+xgTvToTuoMkT9/l9lvuP5jftwnYUp6DwuJzsKErHgfyRk8IB8pqGHWEbM3tLgV1w==
dependencies:
"@kwsites/file-exists" "^1.1.1"
"@kwsites/promise-deferred" "^1.1.1"
debug "^4.3.4"

sisteransi@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
Expand Down

0 comments on commit 5f8dab7

Please sign in to comment.