From ff19df6bfda14697bbce4490249549d02dac0412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=B7=E6=B6=AF?= Date: Wed, 10 Jul 2024 17:29:30 +0000 Subject: [PATCH] feat: init workflow --- .github/workflows/update.yml | 45 +++++++++++++ login/callback/dropbox.html => .gitignore | 0 header-editor/install/update.json | 1 - CNAME => public/CNAME | 0 .../login/callback/dropbox.html | 0 public/login/callback/google.html | 0 {xstyle => public/xstyle}/install/open.html | 0 scripts/update.mjs | 64 +++++++++++++++++++ xstyle/install/update.json | 1 - xstyle/install/update.xml | 1 - xstyle/install/updates.xml | 1 - 11 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/update.yml rename login/callback/dropbox.html => .gitignore (100%) delete mode 100644 header-editor/install/update.json rename CNAME => public/CNAME (100%) rename login/callback/google.html => public/login/callback/dropbox.html (100%) create mode 100644 public/login/callback/google.html rename {xstyle => public/xstyle}/install/open.html (100%) create mode 100644 scripts/update.mjs delete mode 100644 xstyle/install/update.json delete mode 100644 xstyle/install/update.xml delete mode 100644 xstyle/install/updates.xml diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..bc8da48 --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,45 @@ +name: update + +on: + workflow_dispatch: + inputs: + name: + type: string + version: + type: string + assets: + type: string + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16.x] + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v4 + with: + version: 7 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Copy public + run: cp -r ./public ./temp + - name: Genetare update files + env: + NAME: ${{ inputs.name }} + VERSION: ${{ inputs.version }} + ASSETS: ${{ inputs.assets }} + run: node ./scripts/update.mjs + - name: Deploy + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: temp + clean: false diff --git a/login/callback/dropbox.html b/.gitignore similarity index 100% rename from login/callback/dropbox.html rename to .gitignore diff --git a/header-editor/install/update.json b/header-editor/install/update.json deleted file mode 100644 index cdc6bcf..0000000 --- a/header-editor/install/update.json +++ /dev/null @@ -1 +0,0 @@ -{"addons":{"headereditor@addon.firefoxcn.net":{"updates":[{"version":"4.1.1","update_link":"https://github.com/FirefoxBar/HeaderEditor/releases/download/4.1.1/HeaderEditor-4.1.1.xpi","update_hash":"sha256:d758784a4f5a5d82f6ba6be5a085fdb4e4ac5b443673f195a9cc94a7293bf3c5"}]}}} \ No newline at end of file diff --git a/CNAME b/public/CNAME similarity index 100% rename from CNAME rename to public/CNAME diff --git a/login/callback/google.html b/public/login/callback/dropbox.html similarity index 100% rename from login/callback/google.html rename to public/login/callback/dropbox.html diff --git a/public/login/callback/google.html b/public/login/callback/google.html new file mode 100644 index 0000000..e69de29 diff --git a/xstyle/install/open.html b/public/xstyle/install/open.html similarity index 100% rename from xstyle/install/open.html rename to public/xstyle/install/open.html diff --git a/scripts/update.mjs b/scripts/update.mjs new file mode 100644 index 0000000..104fe43 --- /dev/null +++ b/scripts/update.mjs @@ -0,0 +1,64 @@ +import { writeFile } from 'fs/promises'; +import { join, dirname } from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +async function main() { + const name = process.env.NAME; + const version = process.env.VERSION; + const assets = JSON.parse(process.env.ASSETS); + + const outputFloder = [ + join(__dirname, '../temp', name), + ]; + + // Header Editor has multi output floders + if (name === 'header-editor') { + outputFloder.push(join(__dirname, '../temp/headereditor')); + } + + for (const item of assets) { + if (!item.name.endsWith('.xpi') || !item.name.endsWith('.crx')) { + continue; + } + + if (item.name.endsWith('.xpi')) { + // firefox + const content = JSON.stringify({ + addons: { + [item.id]: { + updates: [{ + version: version, + update_link: item.url, + update_hash: `sha256:${item.hash}`, + }] + } + } + }); + + for (const floder of outputFloder) { + console.log('write update.json to ' + floder); + await writeFile(join(floder, 'update.json'), content, 'utf-8'); + } + } + + if (item.name.endsWith('.crx')) { + // chrome + const content = ``; + + for (const floder of outputFloder) { + console.log('write update.xml to ' + floder); + await writeFile(join(floder, 'update.xml'), content, 'utf-8'); + if (name === 'xstyle') { + // xStyle has multi xml + await writeFile(join(floder, 'updates.xml'), content, 'utf-8'); + } + } + } + } + +} + +main(); diff --git a/xstyle/install/update.json b/xstyle/install/update.json deleted file mode 100644 index 9ab10ce..0000000 --- a/xstyle/install/update.json +++ /dev/null @@ -1 +0,0 @@ -{"addons":{"xstyle@addon.firefoxcn.net":{"updates":[{"version":"3.1.0","update_link":"https://github.com/FirefoxBar/xStyle/releases/download/3.1.0/xstyle-3.1.0.xpi","update_hash":"sha256:95a9d93df69bc14a292e2ff549a2be7b82189aa9a7aec3a49f0c0d20c9e605c2"},{"version":"3.1.1","update_link":"https://github.com/FirefoxBar/xStyle/releases/download/3.1.1/xstyle-3.1.1.xpi","update_hash":"sha256:45795dd1faeb870e648f7269a1ada93d536380159cd2a66b0e90b640862e461c"},{"version":"3.1.2","update_link":"https://github.com/FirefoxBar/xStyle/releases/download/3.1.2/xstyle-3.1.2.xpi","update_hash":"sha256:136c663998210b200a4d0ab042baf0246929e32f582f5c3ff1eecc97400fe1d3"}]}}} \ No newline at end of file diff --git a/xstyle/install/update.xml b/xstyle/install/update.xml deleted file mode 100644 index 99aee16..0000000 --- a/xstyle/install/update.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/xstyle/install/updates.xml b/xstyle/install/updates.xml deleted file mode 100644 index 99aee16..0000000 --- a/xstyle/install/updates.xml +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file