Skip to content
This repository was archived by the owner on Sep 7, 2020. It is now read-only.

Commit bf776a7

Browse files
authored
feat: include version (#33)
Fixes #25
1 parent effe29b commit bf776a7

11 files changed

+5756
-406
lines changed

.github/workflows/build-and-release.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ jobs:
2727
${{ runner.OS }}-
2828
- name: Install dependencies
2929
run: npm ci --no-audit
30+
- name: Determine next release version
31+
run: |
32+
node .github/workflows/get-next-version.js > .version
33+
cat .version
3034
- name: Build
3135
run: npm run build
3236
env:

.github/workflows/get-next-version.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const semanticRelease = require('semantic-release')
2+
const { promises: fs } = require('fs')
3+
const path = require('path')
4+
const { WritableStreamBuffer } = require('stream-buffers')
5+
6+
const stdoutBuffer = new WritableStreamBuffer()
7+
const stderrBuffer = new WritableStreamBuffer()
8+
9+
const main = async () => {
10+
const pjson = JSON.parse(
11+
await fs.readFile(path.join(process.cwd(), 'package.json')),
12+
)
13+
const result = await semanticRelease(
14+
{
15+
// Core options
16+
branch: pjson.release.branch,
17+
repositoryUrl: pjson.repository.url,
18+
plugins: ['@semantic-release/commit-analyzer'],
19+
dryRun: true,
20+
},
21+
{
22+
cwd: process.cwd(),
23+
stdout: stdoutBuffer,
24+
stderr: stderrBuffer,
25+
},
26+
)
27+
28+
if (result) {
29+
const { nextRelease } = result
30+
process.stdout.write(nextRelease.version)
31+
} else {
32+
console.error('No new release.')
33+
process.stderr.write(stdoutBuffer.getContentsAsString('utf8'))
34+
if (stderrBuffer.size > 0) {
35+
process.stderr.write(stderrBuffer.getContentsAsString('utf8'))
36+
}
37+
process.stdout.write(pjson.version)
38+
}
39+
}
40+
41+
main()

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
dist/
2+
dist/
3+
.version

package-lock.json

+5,673-404
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@bifravst/code-style": "^7.0.0",
2626
"@commitlint/cli": "^8.3.5",
2727
"@commitlint/config-angular": "^8.3.4",
28+
"@semantic-release/commit-analyzer": "^8.0.1",
2829
"@svgr/webpack": "^5.3.0",
2930
"@types/react": "^16.9.25",
3031
"@types/react-dom": "^16.9.5",
@@ -35,7 +36,9 @@
3536
"eslint-plugin-react": "^7.19.0",
3637
"handlebars": "^4.7.3",
3738
"husky": "^4.2.3",
39+
"semantic-release": "^17.0.4",
3840
"source-map-loader": "^0.2.4",
41+
"stream-buffers": "^3.0.2",
3942
"ts-loader": "^6.2.2",
4043
"twilio-chat": "^3.3.4",
4144
"typescript": "^3.8.3",

src/Chat/components/Error.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export const Error = ({ type, message }: ErrorInfo) => (
1818
<Header>
1919
<Text>
2020
<strong>{type}:</strong> {message}
21+
<br />
22+
<small>
23+
UI version: <code>{GLOBAL_VERSION}</code>
24+
</small>
2125
</Text>
2226
</Header>
2327
)

src/Chat/components/Notice.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ export const DevNotice = ({ onClosed }: { onClosed: () => void }) => (
6060
>
6161
GitHub
6262
</a>
63-
.
63+
.<br />
64+
<small>
65+
Version: <code>{GLOBAL_VERSION}</code>
66+
</small>
6467
<UIButton
6568
type="button"
6669
onClick={() => {

src/chat.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const chat = ({
3535

3636
const deviceId = v4()
3737

38+
log('Version:', GLOBAL_VERSION)
3839
log({ apiEndpoint, apiKey, deviceId, token })
3940

4041
ReactDOM.render(

src/chatbutton.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const imageUrl =
22
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1NiIgaGVpZ2h0PSI1NiIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0iZmVhdGhlciBmZWF0aGVyLW1lc3NhZ2UtY2lyY2xlIj48cGF0aCBkPSJNMjEgMTEuNWE4LjM4IDguMzggMCAwIDEtLjkgMy44IDguNSA4LjUgMCAwIDEtNy42IDQuNyA4LjM4IDguMzggMCAwIDEtMy44LS45TDMgMjFsMS45LTUuN2E4LjM4IDguMzggMCAwIDEtLjktMy44IDguNSA4LjUgMCAwIDEgNC43LTcuNiA4LjM4IDguMzggMCAwIDEgMy44LS45aC41YTguNDggOC40OCAwIDAgMSA4IDh2LjV6Ij48L3BhdGg+PC9zdmc+' // base64 -w0 <feather icon chat bubble white>
33
;(window as any).DAChatButton = (onClick: (remove: () => void) => void) => {
4+
console.log('Chat', GLOBAL_VERSION)
45
const button = document.createElement('button')
56
button.id = 'distribute-aid-chat-button'
67
const img = document.createElement('img')

src/types.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ declare module '*.svg' {
22
const content: React.StatelessComponent<React.SVGAttributes<SVGElement>>
33
export default content
44
}
5+
/**
6+
* This string is replaced through webpack.
7+
*/
8+
declare const GLOBAL_VERSION: string

webpack.config.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
const fs = require('fs')
22
const path = require('path')
33
const Handlebars = require('handlebars')
4+
const webpack = require('webpack')
5+
6+
let v = 'unknown'
7+
try {
8+
v = fs.readFileSync(path.join(process.cwd(), '.version')).trim()
9+
} catch {
10+
v = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json')))
11+
.version
12+
}
413

514
const cfg = {
615
entry: {
@@ -41,6 +50,11 @@ module.exports = [
4150
...cfg,
4251
mode: 'production',
4352
name: 'production',
53+
plugins: [
54+
new webpack.DefinePlugin({
55+
GLOBAL_VERSION: JSON.stringify(v),
56+
}),
57+
],
4458
},
4559
{
4660
...cfg,
@@ -71,5 +85,10 @@ module.exports = [
7185
},
7286
],
7387
},
88+
plugins: [
89+
new webpack.DefinePlugin({
90+
GLOBAL_VERSION: JSON.stringify(v),
91+
}),
92+
],
7493
},
7594
]

0 commit comments

Comments
 (0)