ci: update github actions

This commit is contained in:
Haoyu Xu
2024-08-23 00:35:00 +08:00
parent 9a55ccc5e0
commit 074908facf
6 changed files with 63 additions and 78 deletions

View File

@@ -4,17 +4,44 @@ on:
push: push:
branches: [ main ] branches: [ main ]
env:
CACHE_ZIP_FILENAME: cache.zip
ASSETS_FOLDER: data/operator
RELEASE_FOLDER: release
CACHE_BASE_KEY: akassets
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Use PNPM - name: Use PNPM
uses: pnpm/action-setup@v3 uses: pnpm/action-setup@v4
with: with:
version: latest version: latest
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: latest
cache: 'pnpm'
- name: Install dependencies - name: Install dependencies
run: pnpm i run: pnpm i
- name: Restore cached assets
id: cache-akassets-restore
uses: actions/cache@v4
with:
path: |
${{ env.CACHE_ZIP_FILENAME }}
key: ${{ env.CACHE_BASE_KEY }}-${{ hashFiles('offical_update.json') }}
restore-keys: |
${{ env.CACHE_BASE_KEY }}
- name: Unzip assets
run: |
if test -f ${{ env.CACHE_ZIP_FILENAME }}; then
unzip -qq ${{ env.CACHE_ZIP_FILENAME }} -d .
fi
shell: bash
- name: Download Assets - name: Download Assets
run: pnpm run cf:download run: pnpm run cf:download
- name: Build all - name: Build all
@@ -27,5 +54,14 @@ jobs:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: aklive2d projectName: aklive2d
directory: release directory: ${{ env.RELEASE_FOLDER}}
wranglerVersion: '3' wranglerVersion: '3'
- name: Zip assets
run: zip -qq -9 -r ${{ env.CACHE_ZIP_FILENAME }} ${{ env.ASSETS_FOLDER }}
- name: Save assets
id: cache-akassets-save
uses: actions/cache/save@v4
with:
path: |
${{ env.CACHE_ZIP_FILENAME }}
key: ${{ env.CACHE_BASE_KEY }}-${{ hashFiles('offical_update.json') }}

View File

@@ -1,69 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

View File

@@ -15,9 +15,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Use PNPM - name: Use PNPM
uses: pnpm/action-setup@v3 uses: pnpm/action-setup@v4
with: with:
version: latest version: latest
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: latest
cache: 'pnpm'
- name: Install dependencies - name: Install dependencies
run: pnpm i run: pnpm i
- name: Update charwords - name: Update charwords

View File

@@ -15,9 +15,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Use PNPM - name: Use PNPM
uses: pnpm/action-setup@v3 uses: pnpm/action-setup@v4
with: with:
version: latest version: latest
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: latest
cache: 'pnpm'
- name: Install dependencies - name: Install dependencies
run: pnpm i run: pnpm i
- name: Update music mapping - name: Update music mapping

View File

@@ -15,9 +15,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Use PNPM - name: Use PNPM
uses: pnpm/action-setup@v3 uses: pnpm/action-setup@v4
with: with:
version: latest version: latest
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: latest
cache: 'pnpm'
- name: Install dependencies - name: Install dependencies
run: pnpm i run: pnpm i
- name: Update offical dyn info - name: Update offical dyn info

View File

@@ -5,7 +5,7 @@ import crypto from 'crypto';
import pThrottle from 'p-throttle'; import pThrottle from 'p-throttle';
import { spawnSync } from 'child_process'; import { spawnSync } from 'child_process';
import { readdirSync, fileTypeSync, writeSync, mkdir, exists } from './file.js'; import { readdirSync, fileTypeSync, writeSync, mkdir, exists } from './file.js';
//TODO: Utilizing github actions to upload base.zip and update.zip
export default class CFPages { export default class CFPages {
#uploadPath = path.join(__projectRoot, __config.folder.operator_data); #uploadPath = path.join(__projectRoot, __config.folder.operator_data);
#downloadPath = path.join(__projectRoot, __config.folder.operator_data); #downloadPath = path.join(__projectRoot, __config.folder.operator_data);
@@ -25,13 +25,13 @@ export default class CFPages {
const indexFile = `${__config.akassets_url}/index.json` const indexFile = `${__config.akassets_url}/index.json`
const resp = await fetch(indexFile); const resp = await fetch(indexFile);
const data = await resp.json(); const data = await resp.json();
mkdir(this.#downloadPath); if (!exists(this.#downloadPath)) mkdir(this.#downloadPath);
let list = data.children.flatMap((child) => { let list = data.children.flatMap((child) => {
return this.#generateDownloadList(child, this.#downloadPath); return this.#generateDownloadList(child, this.#downloadPath);
}); });
const throttle = pThrottle({ const throttle = pThrottle({
limit: 10, limit: 10,
interval: 500 interval: 100
}) })
while (list.length > 0) { while (list.length > 0) {
const retry = []; const retry = [];
@@ -42,7 +42,7 @@ export default class CFPages {
const hash = await this.#getHash(file.target); const hash = await this.#getHash(file.target);
if (hash === file.hash) { if (hash === file.hash) {
isExists = true isExists = true
console.log("File already exists and hash matches:", suppressedPath); // console.log("File already exists and hash matches:", suppressedPath);
} }
} }
if (!isExists) { if (!isExists) {