mirror of
https://github.com/yanhao98/composite-actions.git
synced 2025-09-18 12:07:03 +08:00
✔
This commit is contained in:
66
.github/workflows/_delete-workflow-runs.yaml
vendored
Normal file
66
.github/workflows/_delete-workflow-runs.yaml
vendored
Normal 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 }}
|
64
.github/workflows/deploy-dist-to-surge-tetst.yaml
vendored
Normal file
64
.github/workflows/deploy-dist-to-surge-tetst.yaml
vendored
Normal 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 }}"
|
134
.github/workflows/docker-build-push-test.yaml
vendored
Normal file
134
.github/workflows/docker-build-push-test.yaml
vendored
Normal 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;
|
26
.github/workflows/npm-build-fix-to-nexus-test.yaml
vendored
Normal file
26
.github/workflows/npm-build-fix-to-nexus-test.yaml
vendored
Normal 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 }}
|
126
.github/workflows/setup-node-environment-test.yaml
vendored
Normal file
126
.github/workflows/setup-node-environment-test.yaml
vendored
Normal 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 }}
|
50
.github/workflows/upload-to-alist-example-test.yaml
vendored
Normal file
50
.github/workflows/upload-to-alist-example-test.yaml
vendored
Normal 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 }}
|
Reference in New Issue
Block a user