This commit is contained in:
严浩
2025-08-12 13:59:27 +08:00
commit 41ff2ce04a
21 changed files with 1265 additions and 0 deletions

1
.github/_files/.npmrc vendored Normal file
View File

@@ -0,0 +1 @@
use-node-version=22.14.0 # https://pnpm.io/zh/npmrc#use-node-version

6
.github/_files/package.json vendored Normal file
View File

@@ -0,0 +1,6 @@
{
"packageManager": "pnpm@10.6.5",
"dependencies": {
"bun": "^1.2.5"
}
}

125
.github/_files/pnpm-lock.yaml generated vendored Normal file
View File

@@ -0,0 +1,125 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
bun:
specifier: ^1.2.5
version: 1.2.5
packages:
'@oven/bun-darwin-aarch64@1.2.5':
resolution: {integrity: sha512-ggZfdpgUJ/OiWrfcfTgHeSTHcec5HAjkGrZHL9FJ/R60sydRKPYHgAgexdIoJAGfsCVAL+x7y8NSTRIAX8J4Ng==}
cpu: [arm64]
os: [darwin]
'@oven/bun-darwin-x64-baseline@1.2.5':
resolution: {integrity: sha512-3W1RO3/D6Z1S79J47F/DLzmK+dgkYq5hS1ShOCSBAYTTA2b1ZuymaN8avGzSb9ed5W0QfxtyeAksfEY2xUBOqA==}
cpu: [x64]
os: [darwin]
'@oven/bun-darwin-x64@1.2.5':
resolution: {integrity: sha512-4zqyQLJB33s99KcTxH6yQqH5EYBmF1qofQTtLsToIFbIZN1NqSp/aegYiGmxO5Kj/BuWsy8Wf8MS6vX2O0o2Lw==}
cpu: [x64]
os: [darwin]
'@oven/bun-linux-aarch64-musl@1.2.5':
resolution: {integrity: sha512-URlISBOE2HQi8qdru691OYywJRwChxMfXFbk26tCgdZ01LgGAKsIjAYylefuSsPuA697imDN3Pel3D7rveusmw==}
cpu: [aarch64]
os: [linux]
'@oven/bun-linux-aarch64@1.2.5':
resolution: {integrity: sha512-NQFtAVyQyJhLYrhFVxKdh6cqrDNc60pBnBGLQSO8PU+oyFyiJ3e3gGXjLzMbxd6cJxNIK5FZ0JIq96WljKAhlg==}
cpu: [arm64]
os: [linux]
'@oven/bun-linux-x64-baseline@1.2.5':
resolution: {integrity: sha512-fCm/qp7e3VYlaoRs6NIEsKubPqyxjzLv8/qZkxeLLOlPd7CS8L26UY4KPOSjA+wrhPT+Nxsyvl/EEJq2R/iauA==}
cpu: [x64]
os: [linux]
'@oven/bun-linux-x64-musl-baseline@1.2.5':
resolution: {integrity: sha512-H7tuJz7mZvOTPo4yLbIXIxkiDGWSGd2DbwGl4zNol/FURqGsKQVqpomv86yl9KCXsUUOm5FX2i5Ed+ro8N//Cg==}
cpu: [x64]
os: [linux]
'@oven/bun-linux-x64-musl@1.2.5':
resolution: {integrity: sha512-DuU2kQnY48g9tNWjFrZqyG+U2emCBwlhOPxbuY/TMVVNSTMAcQbE/bb3s2pZdhZH5ssjc5SH/ZyWU1TePcYB2A==}
cpu: [x64]
os: [linux]
'@oven/bun-linux-x64@1.2.5':
resolution: {integrity: sha512-pa3kQ4cXNV0jk5aM8+Hdmxr+b4QoPVgeAIA454SN5l3hMGfNsHjczKpsz0ksInZ8506iMMTCPEBXpyQJcSme+Q==}
cpu: [x64]
os: [linux]
'@oven/bun-windows-x64-baseline@1.2.5':
resolution: {integrity: sha512-j5FxI8FeKfWI6rEXA+1O3ASBMTp5CFcZ7MR+/aCpiBKrDse32wLaZMVGnvqQqs4y0YHUvR8b7eXHHTboezjL1w==}
cpu: [x64]
os: [win32]
'@oven/bun-windows-x64@1.2.5':
resolution: {integrity: sha512-oNDdPmzsCyvCATiYgkKWgxOeEx2F7m/i2MGUba+YJAeVXJsJg9iPJrLVBtETvKoSAgkXViwoUEw2U25jRYsp4g==}
cpu: [x64]
os: [win32]
bun@1.2.5:
resolution: {integrity: sha512-fbQLt+DPiGUrPKdmsHRRT7cQAlfjdxPVFvLZrsUPmKiTdv+pU50ypdx9yRJluknSbyaZchFVV7Lx2KXikXKX2Q==}
cpu: [arm64, x64, aarch64]
os: [darwin, linux, win32]
hasBin: true
snapshots:
'@oven/bun-darwin-aarch64@1.2.5':
optional: true
'@oven/bun-darwin-x64-baseline@1.2.5':
optional: true
'@oven/bun-darwin-x64@1.2.5':
optional: true
'@oven/bun-linux-aarch64-musl@1.2.5':
optional: true
'@oven/bun-linux-aarch64@1.2.5':
optional: true
'@oven/bun-linux-x64-baseline@1.2.5':
optional: true
'@oven/bun-linux-x64-musl-baseline@1.2.5':
optional: true
'@oven/bun-linux-x64-musl@1.2.5':
optional: true
'@oven/bun-linux-x64@1.2.5':
optional: true
'@oven/bun-windows-x64-baseline@1.2.5':
optional: true
'@oven/bun-windows-x64@1.2.5':
optional: true
bun@1.2.5:
optionalDependencies:
'@oven/bun-darwin-aarch64': 1.2.5
'@oven/bun-darwin-x64': 1.2.5
'@oven/bun-darwin-x64-baseline': 1.2.5
'@oven/bun-linux-aarch64': 1.2.5
'@oven/bun-linux-aarch64-musl': 1.2.5
'@oven/bun-linux-x64': 1.2.5
'@oven/bun-linux-x64-baseline': 1.2.5
'@oven/bun-linux-x64-musl': 1.2.5
'@oven/bun-linux-x64-musl-baseline': 1.2.5
'@oven/bun-windows-x64': 1.2.5
'@oven/bun-windows-x64-baseline': 1.2.5

35
.github/gh-packages-delete.sh vendored Normal file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
# 设置变量
OWNER="yanhao98"
REPO="gemini-balance"
PACKAGE_NAME="gemini-balance"
# 重新登录 GitHub CLI 获取更多权限
echo "正在更新 GitHub CLI 权限..."
gh auth refresh -h github.com -s read:packages,delete:packages
# 列出所有版本的容器镜像
echo "正在获取 $PACKAGE_NAME 所有版本..."
VERSIONS=$(gh api \
"/user/packages/container/$PACKAGE_NAME/versions" \
--paginate \
--jq '.[].id')
# 检查是否有版本存在
if [ -z "$VERSIONS" ]; then
echo "没有找到 $PACKAGE_NAME 的任何版本"
exit 0
fi
# 删除每个版本
echo "开始删除 $PACKAGE_NAME 的所有版本..."
for version_id in $VERSIONS; do
echo "正在删除版本 ID: $version_id"
gh api \
--method DELETE \
"/user/packages/container/$PACKAGE_NAME/versions/$version_id"
echo "版本 $version_id 已删除"
done
echo "所有 $PACKAGE_NAME 容器镜像版本已成功删除"

4
.github/gh-run-delete.sh vendored Normal file
View File

@@ -0,0 +1,4 @@
while gh run list --json databaseId --jq '.[].databaseId' | grep -q .; do
for id in $(gh run list --json databaseId --jq '.[].databaseId'); do gh run delete $id; done
echo "继续删除下一批..."
done

View File

@@ -0,0 +1,66 @@
name: 删除旧的工作流运行
on:
workflow_dispatch:
inputs:
days:
description: '为每个工作流保留的运行天数'
required: true
default: '30'
minimum_runs:
description: '为每个工作流保留的最小运行次数'
required: true
default: '6'
delete_workflow_pattern:
description: '工作流的名称或文件名(如果未设置,则针对所有工作流)'
required: false
delete_workflow_by_state_pattern:
description: '按状态筛选工作流active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
required: true
default: "ALL"
type: choice
options:
- "ALL"
- active
- deleted
- disabled_inactivity
- disabled_manually
delete_run_by_conclusion_pattern:
description: '根据结论删除运行action_required, cancelled, failure, skipped, success'
required: true
default: "ALL"
type: choice
options:
- "ALL"
- "Unsuccessful: action_required,cancelled,failure,skipped"
- action_required
- cancelled
- failure
- skipped
- success
dry_run:
description: '记录模拟的更改,不执行任何删除操作'
required: false
jobs:
del_runs:
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
steps:
- name: 删除工作流运行
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: >-
${{
startsWith(github.event.inputs.delete_run_by_conclusion_pattern, 'Unsuccessful:')
&& 'action_required,cancelled,failure,skipped'
|| github.event.inputs.delete_run_by_conclusion_pattern
}}
dry_run: ${{ github.event.inputs.dry_run }}

View File

@@ -0,0 +1,64 @@
on:
pull_request:
paths:
- "deploy-dist-to-surge/**"
- ".github/workflows/deploy-dist-to-surge-test.yaml"
push:
paths:
- "deploy-dist-to-surge/**"
- ".github/workflows/deploy-dist-to-surge-test.yaml"
env:
TZ: Asia/Shanghai
jobs:
job:
runs-on: ubuntu-latest
steps:
- name: Checkout code # Required to use the local version of the action
uses: actions/checkout@main
- name: 准备部署文件 (Testing working_dir and dist_dir)
run: |
mkdir -p test_project/build_output
html="<!DOCTYPE html><html><body><h1>Test: ${{ github.event_name }}: ${{ github.sha }} - Custom Dirs</h1></body></html>"
echo $html > test_project/build_output/index.html
- name: Deploy with custom working_dir and dist_dir
uses: ./deploy-dist-to-surge # Use local action
id: surge_deploy_custom
with:
working_dir: ./test_project
dist_dir: build_output
domain_suffix: -custom
- name: Check Surge URL (Custom Dirs)
run: |
echo "Custom dirs deployment URL: ${{ steps.surge_deploy_custom.outputs.url }}"
# Add a basic check if the URL is not empty
if [ -z "${{ steps.surge_deploy_custom.outputs.url }}" ]; then
echo "Error: Surge URL for custom dirs is empty!"
exit 1
fi
- name: 准备部署文件 (Testing default dist_dir)
run: |
mkdir dist
html="<!DOCTYPE html><html><body><h1>Test: ${{ github.event_name }}: ${{ github.sha }} - Default Dist</h1></body></html>"
echo $html > dist/index.html
- name: Deploy with default dist_dir
uses: ./deploy-dist-to-surge # Use local action
id: surge_deploy_default
with:
domain_suffix: -default
- name: Check Surge URL (Default Dist)
run: |
echo "Default dist deployment URL: ${{ steps.surge_deploy_default.outputs.url }}"
# Add a basic check if the URL is not empty
if [ -z "${{ steps.surge_deploy_default.outputs.url }}" ]; then
echo "Error: Surge URL for default dist is empty!"
exit 1
fi
# The following line was from the old version and is redundant as we check specific outputs above.
# echo "steps.surge_deploy.outputs.url: ${{ steps.surge_deploy.outputs.url }}"

View File

@@ -0,0 +1,134 @@
# name: _打包推送镜像
on:
workflow_dispatch:
pull_request:
paths:
- 'docker-build-push/**'
- '.github/workflows/docker-build-push-test.yaml'
push:
paths:
- 'docker-build-push/**'
- '.github/workflows/docker-build-push-test.yaml'
env:
TZ: Asia/Shanghai
jobs:
build-and-push-ghcr:
runs-on: ubuntu-latest
env:
# https://github.com/docker/metadata-action/tree/v5/?tab=readme-ov-file#semver
# Event: push, Ref: refs/head/main, Tags: main
# Event: push tag, Ref: refs/tags/v1.2.3, Tags: 1.2.3, 1.2, 1, latest
# Event: push tag, Ref: refs/tags/v2.0.8-rc1, Tags: 2.0.8-rc1
metadata-action-tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
steps:
- name: 🔑 登录 GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🐳 构建并推送 Docker 镜像
uses: yanhao98/composite-actions/docker-build-push@main
with:
file: ./Dockerfile.test
platforms: linux/amd64,linux/arm64
push: true
load: false
meta_images: ghcr.io/${{ github.repository }}
meta_tags: ${{ env.metadata-action-tags }}
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,scope=${{ github.workflow }}
build-and-push-multi-registry:
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: yanhao98/composite-actions/docker-build-push@main
id: docker-build-push
with:
file: ./Dockerfile.test
platforms: linux/amd64,linux/arm64
push: true
load: false
meta_images: |
docker.io/${{ vars.DOCKERHUB_USERNAME }}/docker-example
ghcr.io/${{ github.repository }}
meta_tags: | # https://github.com/docker/metadata-action
type=raw,value=latest,enable=true
cache-gha:
runs-on: ubuntu-latest
steps:
- uses: yanhao98/composite-actions/docker-build-push@main
id: docker-build-push
with:
file: ./Dockerfile.test
platforms: linux/amd64
push: false
load: true
build-args: |
SHA=${{ github.sha }}
BUILDKIT_INLINE_CACHE=1
# #####
# scope: https://github.com/docker/build-push-action/issues/252#issuecomment-881050512
# cache-to: mode=max
# #####
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,scope=${{ github.workflow }}
- name: Check Docker image
run: |
set -x;
docker images;
docker run --rm ${{ steps.docker-build-push.outputs.imageid }} cat /root/sha.txt;
cache-local:
runs-on: ubuntu-latest
steps:
- name: 🗄️ 缓存Docker层
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-IMAGE_NAME-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-IMAGE_NAME-
- uses: yanhao98/composite-actions/docker-build-push@main
id: docker-build-push
with:
file: ./Dockerfile.test
platforms: linux/amd64
push: false
load: true
build-args: |
SHA=${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix: 如果要在一个 job 中多次使用 buildx 缓存才需要这个步骤。
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🔄 更新缓存
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Check Docker image
run: |
set -x;
docker images;
docker run --rm ${{ steps.docker-build-push.outputs.imageid }} cat /root/sha.txt;

View File

@@ -0,0 +1,26 @@
on:
pull_request:
paths:
- "npm-build-fix-to-nexus/**"
- ".github/workflows/npm-build-fix-to-nexus-test.yaml"
push:
paths:
- "npm-build-fix-to-nexus/**"
- ".github/workflows/npm-build-fix-to-nexus-test.yaml"
env:
TZ: Asia/Shanghai
jobs:
upload_npm_fix_to_nexus:
runs-on: ubuntu-latest
steps:
- name: Prepare
run: |
mkdir npm-build-fix-to-nexus
- uses: yanhao98/composite-actions/npm-build-fix-to-nexus@main
with:
package_json_url: 'https://www.unpkg.com/fuck-your-code/package.json'
pack_workspace: './npm-build-fix-to-nexus'
build_command: 'whoami'
nexus_post_url: 'https://nexus.oo1.dev/service/rest/v1/components?repository=npm-hosted'
nexus_auth: ${{ secrets.NEXUS_AUTH }}

View File

@@ -0,0 +1,126 @@
on:
pull_request:
paths:
- "setup-node-environment/**"
- ".github/workflows/setup-node-environment-test.yaml"
push:
paths:
- "setup-node-environment/**"
- ".github/workflows/setup-node-environment-test.yaml"
env:
TZ: Asia/Shanghai
package_json_content: |
{
"packageManager": "pnpm@10.6.5",
"dependencies": {
"bun": "^1.2.5"
}
}
concurrency:
group: ${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
generate_lock:
runs-on: ubuntu-latest
outputs:
lock_file_content: ${{ steps.generate_lock.outputs.lock_file_content }}
steps:
- uses: pnpm/action-setup@v4
with:
version: latest
standalone: true
- id: generate_lock
env:
CI: 'false'
run: |
set -x;
cat <<EOF > package.json
${{ env.package_json_content }}
EOF
pnpm config list
cat package.json
pnpm install --lockfile-only
echo "lock_file_content<<EOF" >> $GITHUB_OUTPUT
cat pnpm-lock.yaml >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
tests:
needs: generate_lock
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
npmrc_content:
- ''
- |
use-node-version=22.14.0 # https://pnpm.io/zh/npmrc#use-node-version
lock_file:
- 'true'
- 'false'
cwd:
- ''
- 'test'
steps:
# - uses: actions/checkout@main
- name: 打印 matrix
run: |
echo "🤖---- 打印 matrix ----🤖"
echo "npmrc_content: ${{ matrix.npmrc_content }}"
echo "lock_file: ${{ matrix.lock_file }}"
echo "cwd: ${{ matrix.cwd }}"
echo "GITHUB_WORKSPACE: ${{ github.workspace }}"
- name: Create test directory
if: matrix.cwd != ''
run: |
mkdir -p ${{ matrix.cwd }}
set -x;
ls -l -R .
pwd
- name: Create .npmrc
working-directory: ${{ matrix.cwd }}
if: matrix.npmrc_content != ''
run: |
cat <<EOF > .npmrc
${{ matrix.npmrc_content }}
EOF
set -x;
ls -l -R .
pwd
cat .npmrc
- name: Create package.json
working-directory: ${{ matrix.cwd }}
run: |
mkdir -p ${{ github.workspace }}/.git
cat <<EOF > package.json
${{ env.package_json_content }}
EOF
set -x;
ls -l -R .
pwd
cat package.json
- name: Create pnpm-lock.yaml
working-directory: ${{ matrix.cwd }}
if: matrix.lock_file == 'true'
run: |
cat <<EOF > pnpm-lock.yaml
${{ needs.generate_lock.outputs.lock_file_content }}
EOF
set -x;
ls -l -R .
pwd
cat pnpm-lock.yaml
- name: ⚙️ 设置 Node 环境
uses: yanhao98/composite-actions/setup-node-environment@main
with:
working-directory: ${{ matrix.cwd }}

View File

@@ -0,0 +1,50 @@
on:
pull_request:
paths:
- "upload-to-alist/**"
- ".github/workflows/upload-to-alist-example-test.yaml"
push:
paths:
- "upload-to-alist/**"
- ".github/workflows/upload-to-alist-example-test.yaml"
env:
TZ: Asia/Shanghai
jobs:
upload:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@main
- name: 📝 生成构建产物的文件名
id: filename
run: |
PROJECT_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)
DATE=$(date '+%Y%m%d_%H%M')
SHORT_HASH=$(git rev-parse --short HEAD)
FILENAME="${PROJECT_NAME}_${DATE}_${SHORT_HASH}.txt"
echo "📝 生成的文件名: $FILENAME"
echo "FILENAME=${FILENAME}" >> $GITHUB_OUTPUT
- name: Create test file
run: |
cat > ${{ steps.filename.outputs.FILENAME }} << EOF
# 测试文件
- 项目: ${{ github.repository }}
- 分支: ${{ github.ref_name }}
- 提交: $(git rev-parse HEAD)
- 时间: $(date '+%Y-%m-%d %H:%M:%S %Z')
- 触发事件: ${{ github.event_name }}
EOF
- uses: yanhao98/composite-actions/upload-to-alist@main
with:
alist_url: ${{ vars.ALIST_URL }}
alist_username: ${{ secrets.ALIST_USERNAME }}
alist_password: ${{ secrets.ALIST_PASSWORD }}
alist_target: ${{ vars.alist_target_base }}/github-actions/upload-to-alist/${{ steps.filename.outputs.FILENAME }}
file: ${{ steps.filename.outputs.FILENAME }}