Skip to content

Commit 00dda7c

Browse files
authored
ci: implement extension autopublish (#40)
1 parent 2ce0a22 commit 00dda7c

13 files changed

Lines changed: 323 additions & 466 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish Extension
2+
on:
3+
workflow_dispatch:
4+
# release:
5+
# types: [published]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Create .env file
13+
uses: SpicyPizza/create-envfile@v1.3.1
14+
with:
15+
envkey_CREDENTIALS: ${{ secrets.CREDENTIALS }}
16+
- name: Setup pnpm
17+
uses: pnpm/action-setup@v2.2.2
18+
with:
19+
version: latest
20+
- name: Install deps
21+
run: pnpm i --frozen-lockfile
22+
- name: Build extension
23+
run: pnpm run build
24+
- name: Publish extension with Plasmo
25+
uses: PlasmoHQ/bpp@v2
26+
with:
27+
keys: ${{ secrets.BPP_KEYS }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ dist
127127
.pnp.*
128128

129129
# credentials
130-
credentials*
130+
credentials/
131131

132132
# temp files on local machine
133133
tmp/

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "halo-discord-extension",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Receive Discord notifications for updates in Halo",
55
"author": "Elijah Olmos",
66
"license": "AGPL-3.0-only",
@@ -9,15 +9,19 @@
99
"test:chrome": "rollup -c -w --configChrome",
1010
"test:firefox": "rollup -c -w --configFirefox",
1111
"build": "pnpm run build:chrome && pnpm run build:firefox",
12-
"build:chrome": "rollup -c --configChrome && zip-build build/chrome dist -t %NAME%-%VERSION%-chrome.%EXT%",
13-
"build:firefox": "rollup -c --configFirefox && zip-build build/firefox dist -t %NAME%-%VERSION%-firefox.%EXT%"
12+
"build:chrome": "rollup -c --configChrome",
13+
"build:firefox": "rollup -c --configFirefox"
1414
},
1515
"devDependencies": {
1616
"@rollup/plugin-node-resolve": "14.1.0",
1717
"@rollup/plugin-replace": "4.0.0",
1818
"@types/chrome": "0.0.193",
1919
"autoprefixer": "10.4.11",
20+
"colorette": "^2.0.19",
2021
"daisyui": "2.28.0",
22+
"dotenv": "^16.0.2",
23+
"fflate": "^0.7.3",
24+
"filesize": "^9.0.11",
2125
"postcss": "8.4.16",
2226
"rollup": "2.79.0",
2327
"rollup-plugin-chrome-extension": "3.6.10",
@@ -29,8 +33,7 @@
2933
"rollup-plugin-terser": "7.0.2",
3034
"svelte": "3.50.1",
3135
"svelte-preprocess": "4.10.7",
32-
"tailwindcss": "3.1.8",
33-
"zip-build": "1.7.0"
36+
"tailwindcss": "3.1.8"
3437
},
3538
"dependencies": {
3639
"compare-versions": "5.0.1",

plugins/zip.plugin.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2022 Elijah Olmos
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as
6+
* published by the Free Software Foundation, version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU Affero General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU Affero General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
import { bold, green } from 'colorette';
18+
import { strToU8, zip as zipCb } from 'fflate';
19+
import filesize from 'filesize';
20+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
21+
import { relative } from 'node:path';
22+
import { promisify } from 'node:util';
23+
import { OutputOptions } from 'rollup';
24+
25+
/**
26+
* @typedef ZipConfigOptions
27+
* @type {object}
28+
* @property {string} fileName - name of output zip file
29+
* @property {string} [dir] - Output directory, defaults to rollup output directory
30+
*/
31+
32+
/**
33+
* @param {ZipConfigOptions} options
34+
*/
35+
export default function zip(options) {
36+
return {
37+
name: 'zip',
38+
/**
39+
* @param {OutputOptions} options
40+
* @param {Object.<string, {source: string | Uint8Array}>} bundle
41+
*/
42+
writeBundle: async function (_options, bundle) {
43+
const dir = options?.dir ?? _options?.dir ?? process.cwd();
44+
const { fileName } = options;
45+
46+
const data = await promisify(zipCb)(
47+
await Object.entries(bundle).reduce(
48+
async (acc, [name, { type, source }]) => ({
49+
...(await acc),
50+
[name]:
51+
type === 'asset'
52+
? typeof source === 'string'
53+
? strToU8(source)
54+
: source
55+
: await readFile(`${_options?.dir}/${name}`),
56+
}),
57+
{}
58+
)
59+
);
60+
//create dir if it does not exist
61+
await mkdir(`./${relative(process.cwd(), dir)}`, { recursive: true });
62+
await writeFile(`./${relative(process.cwd(), dir)}/${fileName}`, data);
63+
console.log(green(`zipped to ${bold(`${dir}/${fileName}`)} (${filesize(data.byteLength)})`));
64+
},
65+
};
66+
}

0 commit comments

Comments
 (0)