Skip to content

Commit

Permalink
ci: bump node talisman version as patch for new tw talisman version
Browse files Browse the repository at this point in the history
  • Loading branch information
pgmanutd committed Nov 22, 2022
1 parent 6f82ba9 commit 2abfaa7
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 19 deletions.
98 changes: 94 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"lint-staged": "^10.4.0",
"prettier": "^2.1.2",
"replace-in-file": "^6.1.0",
"semver": "^7.3.8",
"ts-jest": "^26.4.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
Expand Down
38 changes: 23 additions & 15 deletions scripts/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ const fs = require('fs');
const request = require('request');
const execShPromise = require('exec-sh').promise;
const replace = require('replace-in-file');
const semver = require('semver');

const packageJson = require('../../package.json');
const { CHECKSUMS, META_INFO } = require('../../src/constants');

const oldVersion = META_INFO.version.replace('v', '');
const oldTWTalismanVersion = META_INFO.version.replace('v', '');
const { version: oldNodeTalismanVersion } = packageJson;

const publishNewTag = async ({ newVersion }) => {
await execShPromise(`npm run publish -- ${newVersion} --no-release-draft`, {
cwd: process.cwd(),
});
const publishNewTag = async () => {
const newNodeTalismanVersion = semver.inc(oldNodeTalismanVersion, 'patch');

await execShPromise(
`npm run publish -- ${newNodeTalismanVersion} --no-release-draft`,
{
cwd: process.cwd(),
},
);
};

const commitChanges = async ({ newVersion }) => {
const commitChanges = async ({ newTWTalismanVersion }) => {
await execShPromise(
[
'git add --all',
`git commit -m "build(tw-talisman): upgrade from ${oldVersion} to ${newVersion}" -n`,
`git commit -m "build(tw-talisman): upgrade from ${oldTWTalismanVersion} to ${newTWTalismanVersion}" -n`,
],
{ cwd: process.cwd() },
);
Expand All @@ -47,14 +55,14 @@ const replaceChecksumsInFiles = async ({ checksums }) => {
}
};

const replaceVersionsInFiles = ({ tagName }) => {
const replaceVersionsInFiles = ({ newTWTalismanVersion }) => {
const cwd = process.cwd();

try {
const changedFiles = replace.sync({
files: [`${cwd}/README.md`, `${cwd}/src/constants.ts`],
from: new RegExp(`v${oldVersion}`, 'g'),
to: tagName,
from: new RegExp(`v${oldTWTalismanVersion}`, 'g'),
to: `v${newTWTalismanVersion}`,
});

console.log('Modified files after replacing versions:', changedFiles);
Expand Down Expand Up @@ -100,7 +108,7 @@ const getChecksumFileContent = ({ tagName }) => {

const getNextValidTagName = (body) => {
const index = body.findIndex(({ tag_name: tagName }) =>
tagName.includes(oldVersion),
tagName.includes(oldTWTalismanVersion),
);

let nextValidTag = null;
Expand Down Expand Up @@ -153,7 +161,7 @@ const getNextTagName = () => {
const tagName = await getNextTagName();

if (tagName) {
const newVersion = tagName.replace('v', '');
const newTWTalismanVersion = tagName.replace('v', '');

const checksumFileContent = await getChecksumFileContent({ tagName });
const checksums = extractChecksumsFromContent({
Expand All @@ -163,11 +171,11 @@ const getNextTagName = () => {

await replaceChecksumsInFiles({ checksums });

replaceVersionsInFiles({ tagName });
replaceVersionsInFiles({ newTWTalismanVersion });

await commitChanges({ newVersion });
await commitChanges({ newTWTalismanVersion });

await publishNewTag({ newVersion });
await publishNewTag();
}
} catch (error) {
setImmediate(() => {
Expand Down

0 comments on commit 2abfaa7

Please sign in to comment.