This commit is contained in:
严浩
2024-09-30 14:13:23 +08:00
committed by mini2024
commit b821c98ddd
18 changed files with 1043 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

View File

@ -0,0 +1,26 @@
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: 准备部署文件
run: |
mkdir dist
html="<!DOCTYPE html><html><body><h1>${{ github.event_name }}: ${{ github.sha }}</h1></body></html>"
echo $html > dist/index.html
- uses: yanhao98/composite-actions/deploy-dist-to-surge@main
id: surge_deploy
- name: Check Surge URL
run: |
echo "steps.surge_deploy.outputs.url: ${{ steps.surge_deploy.outputs.url }}"

View File

@ -0,0 +1,133 @@
# 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 }}
# #####
# 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,133 @@
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:
checkout:
- true
- false
container:
- 'yanhao98/runner-images:pnpm'
- '' # gitea/runner-images:ubuntu-latest
npmrc_content:
- ''
-
use-node-version=22.14.0 # https://pnpm.io/zh/npmrc#use-node-version
lock_file:
- 'true'
- 'false'
cwd:
- ''
- 'test'
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@main
if: matrix.checkout == 'true'
- name: 打印 matrix
run: |
echo "🤖---- 打印 matrix ----🤖"
echo "container: ${{ matrix.container }}"
echo "checkout: ${{ matrix.checkout }}"
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 }}
pwd
- name: Create .npmrc
working-directory: ${{ matrix.cwd }}
if: matrix.npmrc_content != ''
run: |
set -x;
ls -l -R .
cat <<EOF > .npmrc
${{ matrix.npmrc_content }}
EOF
pwd
- 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 .
cat package.json
pwd
- name: Create pnpm-lock.yaml
working-directory: ${{ matrix.cwd }}
if: matrix.lock_file == 'true'
run: |
mkdir -p ${{ github.workspace }}/.git
cat <<EOF > pnpm-lock.yaml
${{ needs.generate_lock.outputs.lock_file_content }}
EOF
set -x;
ls -l -R .
cat pnpm-lock.yaml
- uses: yanhao98/composite-actions/setup-node-environment@main
with:
package_json_cwd: ${{ matrix.cwd }}
# pnpm_standalone: true

View File

@ -0,0 +1,52 @@
name: Upload to Alist Example
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@v4
- 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 }}