Skip to content

Commit a73e171

Browse files
authored
Feat: release script (#222)
1 parent 68a9be9 commit a73e171

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
src/main.js
1+
src/main.js
2+
src/scripts/release.js

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Sigma Prime",
66
"homepage": "./",
77
"name": "Siren",
8-
"version": "1.0.1",
8+
"version": "1.0.2",
99
"private": true,
1010
"dependencies": {
1111
"@electron-forge/maker-dmg": "^6.0.5",
@@ -160,6 +160,5 @@
160160
"storybook-dark-mode": "^1.1.0",
161161
"storybook-tailwind-dark-mode": "^1.0.15",
162162
"webpack": "^5.74.0"
163-
},
164-
163+
}
165164
}

src/constants/version.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/scripts/release.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const { exec } = require('child_process')
2+
3+
function isValidSemanticVersion(version) {
4+
const semVerPattern =
5+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/
6+
return semVerPattern.test(version)
7+
}
8+
9+
function executeGitCommand(command) {
10+
return new Promise((resolve, reject) => {
11+
const child = exec(command, (error, stdout, stderr) => {
12+
if (error) {
13+
console.error(`Error executing command: ${command}\n${stderr}`)
14+
reject(error)
15+
} else {
16+
console.log(`Success executing command: ${command}\n${stdout}`)
17+
resolve(stdout)
18+
}
19+
})
20+
21+
setTimeout(() => {
22+
child.kill()
23+
reject(new Error(`Command timed out: ${command}`))
24+
}, 60000)
25+
})
26+
}
27+
28+
async function safeExecuteGitCommand(command) {
29+
try {
30+
await executeGitCommand(command)
31+
} catch (error) {
32+
console.error('An error occurred:', error)
33+
process.exit(1)
34+
}
35+
}
36+
37+
async function main() {
38+
const versionId = process.argv[2]
39+
40+
if (!versionId) {
41+
console.error('Please provide a version ID as an argument.')
42+
return
43+
}
44+
45+
if (!isValidSemanticVersion(versionId)) {
46+
console.error(
47+
'The provided version ID does not follow semantic versioning. Please provide a valid version ID.',
48+
)
49+
return
50+
}
51+
52+
await safeExecuteGitCommand('git checkout unstable')
53+
await safeExecuteGitCommand('git pull')
54+
55+
await safeExecuteGitCommand(`npm version ${versionId} --no-git-tag-version`)
56+
await safeExecuteGitCommand('git add ../../package.json')
57+
await safeExecuteGitCommand(
58+
`git commit --allow-empty -m "siren version updated: ${versionId}" --no-verify`,
59+
)
60+
await safeExecuteGitCommand('git push')
61+
62+
await safeExecuteGitCommand('git checkout stable')
63+
await safeExecuteGitCommand('git merge --ff-only unstable')
64+
await safeExecuteGitCommand('git push origin stable')
65+
66+
await safeExecuteGitCommand(`git tag v${versionId}`)
67+
await safeExecuteGitCommand(`git push origin v${versionId}`)
68+
69+
console.log(`Successfully tagged and initiated release ${versionId}`)
70+
process.exit(1)
71+
}
72+
73+
main()

src/views/DashBoard/Content/MainContent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import useLocalStorage from '../../../hooks/useLocalStorage'
2121
import { UsernameStorage } from '../../../types/storage'
2222
import DashboardOptions from '../../../components/DashboardOptions/DashboardOptions'
2323
import PillIcon from '../../../components/PillIcon/PillIcon'
24-
import { sirenVersion } from '../../../constants/version'
24+
import pckJson from '../../../../package.json'
2525

2626
const MainContent = () => {
2727
const { t } = useTranslation()
28+
const { version } = pckJson
2829
const [username] = useLocalStorage<UsernameStorage>('username', undefined)
2930
const [name, setUsername] = useRecoilState(userName)
3031

@@ -53,7 +54,7 @@ const MainContent = () => {
5354
<Typography type='text-tiny' family='font-roboto' darkMode='dark:text-white' isBold>
5455
{t('lighthouseUiVersion')}
5556
</Typography>
56-
<PillIcon bgColor='bg-tertiary' text={sirenVersion} />
57+
<PillIcon bgColor='bg-tertiary' text={`v${version}`} />
5758
</div>
5859
<div>
5960
<Typography type='text-tiny' family='font-roboto' darkMode='dark:text-white' isBold>

0 commit comments

Comments
 (0)