Skip to content

Commit

Permalink
ci: implement extension autopublish (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
elijaholmos authored Sep 27, 2022
1 parent 2ce0a22 commit 00dda7c
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 466 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/publish-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish Extension
on:
workflow_dispatch:
# release:
# types: [published]

jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create .env file
uses: SpicyPizza/[email protected]
with:
envkey_CREDENTIALS: ${{ secrets.CREDENTIALS }}
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: latest
- name: Install deps
run: pnpm i --frozen-lockfile
- name: Build extension
run: pnpm run build
- name: Publish extension with Plasmo
uses: PlasmoHQ/bpp@v2
with:
keys: ${{ secrets.BPP_KEYS }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ dist
.pnp.*

# credentials
credentials*
credentials/

# temp files on local machine
tmp/
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "halo-discord-extension",
"version": "2.0.1",
"version": "2.0.2",
"description": "Receive Discord notifications for updates in Halo",
"author": "Elijah Olmos",
"license": "AGPL-3.0-only",
Expand All @@ -9,15 +9,19 @@
"test:chrome": "rollup -c -w --configChrome",
"test:firefox": "rollup -c -w --configFirefox",
"build": "pnpm run build:chrome && pnpm run build:firefox",
"build:chrome": "rollup -c --configChrome && zip-build build/chrome dist -t %NAME%-%VERSION%-chrome.%EXT%",
"build:firefox": "rollup -c --configFirefox && zip-build build/firefox dist -t %NAME%-%VERSION%-firefox.%EXT%"
"build:chrome": "rollup -c --configChrome",
"build:firefox": "rollup -c --configFirefox"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "14.1.0",
"@rollup/plugin-replace": "4.0.0",
"@types/chrome": "0.0.193",
"autoprefixer": "10.4.11",
"colorette": "^2.0.19",
"daisyui": "2.28.0",
"dotenv": "^16.0.2",
"fflate": "^0.7.3",
"filesize": "^9.0.11",
"postcss": "8.4.16",
"rollup": "2.79.0",
"rollup-plugin-chrome-extension": "3.6.10",
Expand All @@ -29,8 +33,7 @@
"rollup-plugin-terser": "7.0.2",
"svelte": "3.50.1",
"svelte-preprocess": "4.10.7",
"tailwindcss": "3.1.8",
"zip-build": "1.7.0"
"tailwindcss": "3.1.8"
},
"dependencies": {
"compare-versions": "5.0.1",
Expand Down
66 changes: 66 additions & 0 deletions plugins/zip.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2022 Elijah Olmos
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { bold, green } from 'colorette';
import { strToU8, zip as zipCb } from 'fflate';
import filesize from 'filesize';
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { relative } from 'node:path';
import { promisify } from 'node:util';
import { OutputOptions } from 'rollup';

/**
* @typedef ZipConfigOptions
* @type {object}
* @property {string} fileName - name of output zip file
* @property {string} [dir] - Output directory, defaults to rollup output directory
*/

/**
* @param {ZipConfigOptions} options
*/
export default function zip(options) {
return {
name: 'zip',
/**
* @param {OutputOptions} options
* @param {Object.<string, {source: string | Uint8Array}>} bundle
*/
writeBundle: async function (_options, bundle) {
const dir = options?.dir ?? _options?.dir ?? process.cwd();
const { fileName } = options;

const data = await promisify(zipCb)(
await Object.entries(bundle).reduce(
async (acc, [name, { type, source }]) => ({
...(await acc),
[name]:
type === 'asset'
? typeof source === 'string'
? strToU8(source)
: source
: await readFile(`${_options?.dir}/${name}`),
}),
{}
)
);
//create dir if it does not exist
await mkdir(`./${relative(process.cwd(), dir)}`, { recursive: true });
await writeFile(`./${relative(process.cwd(), dir)}/${fileName}`, data);
console.log(green(`zipped to ${bold(`${dir}/${fileName}`)} (${filesize(data.byteLength)})`));
},
};
}
Loading

0 comments on commit 00dda7c

Please sign in to comment.