Skip to content

Commit

Permalink
feat: init workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sylingd committed Jul 10, 2024
1 parent 12f8f9c commit ff19df6
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
1 change: 0 additions & 1 deletion header-editor/install/update.json

This file was deleted.

File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
64 changes: 64 additions & 0 deletions scripts/update.mjs
Original file line number Diff line number Diff line change
@@ -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 = `<?xml version='1.0' encoding='UTF-8'?><gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'><app appid='${item.id}'><updatecheck codebase='${item.url}' version='${version}' prodversionmin='64.0.3242' /></app></gupdate>`;

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();
1 change: 0 additions & 1 deletion xstyle/install/update.json

This file was deleted.

1 change: 0 additions & 1 deletion xstyle/install/update.xml

This file was deleted.

1 change: 0 additions & 1 deletion xstyle/install/updates.xml

This file was deleted.

0 comments on commit ff19df6

Please sign in to comment.