Skip to content

Commit 3cddff6

Browse files
authored
Add CI/CD GitHub Action Workflows (#3)
* Add `npm run update-manifest-version` * Add CI/CD GitHub Workflows
1 parent a18c549 commit 3cddff6

File tree

7 files changed

+181
-4
lines changed

7 files changed

+181
-4
lines changed

.github/release-drafter.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name-template: 'v$RESOLVED_VERSION'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
categories:
4+
- title: '🚀 Features'
5+
labels:
6+
- 'feature'
7+
- 'enhancement'
8+
- title: '🐛 Bug Fixes'
9+
labels:
10+
- 'fix'
11+
- 'bugfix'
12+
- 'bug'
13+
- title: '🧰 Maintenance'
14+
label: 'chore'
15+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
16+
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
17+
version-resolver:
18+
major:
19+
labels:
20+
- 'major'
21+
- 'breaking'
22+
minor:
23+
labels:
24+
- 'minor'
25+
- 'enhancement'
26+
patch:
27+
labels:
28+
- 'patch'
29+
- 'bug'
30+
default: patch
31+
template: |
32+
## Changes
33+
34+
$CHANGES
35+
autolabeler:
36+
- label: 'chore'
37+
files:
38+
- '*.md'
39+
branch:
40+
- '/docs{0,1}\/.+/'
41+
- label: 'bug'
42+
branch:
43+
- '/fix\/.+/'
44+
title:
45+
- '/fix/i'
46+
- '/bugfix/i'
47+
- label: 'enhancement'
48+
title:
49+
- '/added/i'
50+
- '/add/i'
51+
- '/feature/i'
52+
- '/feat/i'
53+
- '/support/i'
54+
- '/enable/i'
55+
branch:
56+
- '/feature\/.+/'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, reopened, synchronize]
9+
10+
jobs:
11+
update_release_draft:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: release-drafter/release-drafter@v5
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [ published ]
5+
env:
6+
GIT_TERMINAL_PROMPT: 1
7+
8+
jobs:
9+
upload-extension:
10+
name: Build and upload extension to Chrome Web Store
11+
runs-on: ubuntu-latest
12+
env:
13+
EXTENSION_ID: lamobknkahhlgennggjjphcdfndjkafj
14+
15+
steps:
16+
- name: Build and upload extension to Chrome Web Store
17+
uses: actions/setup-node@v2
18+
with:
19+
cache: 'npm'
20+
node-version: '18.12.1'
21+
- run: |
22+
npm install
23+
initialTag=${{ github.event.release.tag_name }}
24+
tag="${initialTag//[v]/}"
25+
echo $tag
26+
git remote update
27+
git fetch
28+
git checkout --track origin/main
29+
git config --global user.email "github-actions@github.com"
30+
git config --global user.name "Github Actions"
31+
npm --no-git-tag-version --allow-same-version version $tag
32+
npm run update-manifest-version
33+
npm i -g auto-changelog
34+
auto-changelog --hide-credit -l 100
35+
git add .
36+
git commit -m "Release $tag"
37+
npm run build
38+
npm install -g chrome-webstore-upload-cli
39+
chrome-webstore-upload upload \\
40+
--source dist \\
41+
--extension-id ${{ env.EXTENSION_ID }} \\
42+
--client-id ${{ secrets.CI_GOOGLE_CLIENT_ID }} \\
43+
--client-secret ${{ secrets.CI_GOOGLE_CLIENT_SECRET }} \\
44+
--refresh-token ${{ secrets.CI_GOOGLE_REFRESH_TOKEN }}
45+
git push

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
name: Run tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Setup node
18+
uses: actions/setup-node@v2
19+
with:
20+
cache: 'npm'
21+
node-version: '18.12.1'
22+
23+
- name: Build
24+
run: |-
25+
npm install
26+
npm run build
27+
zip -r extension-${{ github.sha }}.zip dist
28+
29+
- name: Archive extension artifact
30+
uses: actions/upload-artifact@v2
31+
with:
32+
name: extension-${{ github.sha }}
33+
path: extension-${{ github.sha }}.zip
34+
35+
- name: Test
36+
run: npm run test

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"build": "webpack --config webpack/webpack.config.cjs",
1212
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
13+
"update-manifest-version": "node scripts/update-manifest-version.js",
1314
"lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --cache-strategy content && echo 'Lint OK!'",
1415
"lint:fix": "eslint . --ext .ts,.tsx --max-warnings 0 --cache --cache-strategy content --fix",
1516
"prettier": "prettier --config .prettierrc.json 'src/**/*.ts' 'test/**/*.ts' --check",

public/manifest.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@
1717
},
1818
"content_scripts": [
1919
{
20-
"js": ["content.js"],
21-
"matches": ["https://etherscan.io/tokenholdings*", "https://etherscan.io/address*", "https://portfolio.metamask.io/"]
20+
"js": [
21+
"content.js"
22+
],
23+
"matches": [
24+
"https://etherscan.io/tokenholdings*",
25+
"https://etherscan.io/address*",
26+
"https://portfolio.metamask.io/"
27+
]
2228
}
2329
],
24-
"permissions": ["storage"],
30+
"permissions": [
31+
"storage"
32+
],
2533
"background": {
2634
"service_worker": "background.js"
2735
}
28-
}
36+
}

scripts/update-manifest-version.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import fs from 'fs';
2+
3+
const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url)));
4+
5+
const pkg = loadJSON('../package.json');
6+
const manifest = loadJSON('../public/manifest.json');
7+
8+
if (pkg.version !== manifest.version) {
9+
console.log(`updating manifest.json version: ${manifest.version} -> ${pkg.version}`)
10+
manifest.version = pkg.version;
11+
fs.writeFileSync(new URL('../public/manifest.json', import.meta.url), JSON.stringify(manifest, null, 2));
12+
13+
} else {
14+
console.log(`manifest.json version (${manifest.version}) is the same as package.json version (${manifest.version}) - no need to update`)
15+
}

0 commit comments

Comments
 (0)