mirror of
https://github.com/yanhao98/composite-actions.git
synced 2025-07-13 23:00:48 +08:00
Compare commits
47 Commits
Author | SHA1 | Date | |
---|---|---|---|
76e102f6a5 | |||
2dda4ee55a | |||
e01a0b34d8 | |||
5195d74ff1 | |||
6e58674f53 | |||
ced3572c0a | |||
3ef624f5d9 | |||
f7f95de95a | |||
a34f085e86 | |||
54a6963676 | |||
64ad47eb05 | |||
dd74c0faa2 | |||
62d536c82e | |||
a6aa3462f3 | |||
c7455bfb3c | |||
4c23f82657 | |||
4eb4324252 | |||
a9d3e3eb96 | |||
b81659bab6 | |||
f1edd9e2b5 | |||
1fcbdefb2f | |||
55c4c305c0 | |||
79f1925e81 | |||
4f7bdd9fb4 | |||
7c58ef3294 | |||
9f1e52135c | |||
ae2a20ab90 | |||
47b2bb8d26 | |||
f9d3465703 | |||
3d8306ca70 | |||
c1cee30ad3 | |||
fa63868c18 | |||
238392db7a | |||
edf12e5623 | |||
6ca5f9aef2 | |||
746c056e16 | |||
bf2f20471c | |||
5bd89bc7bb | |||
ad1ed515d9 | |||
2e7fd5567e | |||
ebb6f5dc6c | |||
da7c4ac612 | |||
aca6c13ecb | |||
a6b302e68a | |||
dd22eed198 | |||
3624aae550 | |||
f622e0b7fa |
53
.github/workflows/ci.yml
vendored
53
.github/workflows/ci.yml
vendored
@ -1,53 +0,0 @@
|
||||
name: 持续集成
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
env:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
jobs:
|
||||
setup-node-environment-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: yanhao98/composite-actions/setup-node-environment@main
|
||||
- name: Check Node and PNPM versions
|
||||
run: |
|
||||
set -x
|
||||
which pnpm
|
||||
|
||||
docker-build-push-test:
|
||||
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:
|
||||
build_file: ./docker-build-push/Dockerfile
|
||||
build_platforms: linux/amd64
|
||||
build_push: ${{ github.ref_type == 'tag' }}
|
||||
build_load: true
|
||||
metadata_images: |
|
||||
docker.io/${{ vars.DOCKERHUB_USERNAME }}/docker-example
|
||||
ghcr.io/${{ github.repository }}
|
||||
metadata_tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
- name: Check Docker image
|
||||
run: |
|
||||
set -x;
|
||||
docker images;
|
||||
docker run --rm ${{ steps.docker-build-push.outputs.imageid }} whoami;
|
26
.github/workflows/deploy-dist-to-surge.yml
vendored
Normal file
26
.github/workflows/deploy-dist-to-surge.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "deploy-dist-to-surge.yml/**"
|
||||
- ".github/workflows/deploy-dist-to-surge.yml"
|
||||
push:
|
||||
paths:
|
||||
- "deploy-dist-to-surge.yml/**"
|
||||
- ".github/workflows/deploy-dist-to-surge.yml"
|
||||
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 }}"
|
58
.github/workflows/docker-build-push.yml
vendored
Normal file
58
.github/workflows/docker-build-push.yml
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "docker-build-push/**"
|
||||
- ".github/workflows/docker-build-push.yml"
|
||||
push:
|
||||
paths:
|
||||
- "docker-build-push/**"
|
||||
- ".github/workflows/docker-build-push.yml"
|
||||
env:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
jobs:
|
||||
job:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest] # https://docs.github.com/zh/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#用于公共存储库的-github-托管的标准运行器
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@main
|
||||
- uses: yanhao98/semantic-release-action@main
|
||||
id: semantic
|
||||
|
||||
- name: Login to Docker Hub
|
||||
if: steps.semantic.outputs.next_release_published == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Login to GitHub Container Registry
|
||||
if: steps.semantic.outputs.next_release_published == 'true'
|
||||
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
|
||||
# if: steps.semantic.outputs.next_release_published == 'true'
|
||||
id: docker-build-push
|
||||
with:
|
||||
build_file: ./Dockerfile.test
|
||||
build_platforms: linux/amd64,linux/arm64
|
||||
build_push: ${{ matrix.os == 'ubuntu-latest' && steps.semantic.outputs.next_release_published == 'true' }}
|
||||
build_load: false
|
||||
metadata_images: |
|
||||
docker.io/${{ vars.DOCKERHUB_USERNAME }}/docker-example
|
||||
ghcr.io/${{ github.repository }}
|
||||
metadata_tags: |
|
||||
type=semver,pattern={{version}},value=${{ steps.semantic.outputs.next_release_version }}
|
||||
type=semver,pattern={{major}}.{{minor}},value=${{ steps.semantic.outputs.next_release_version }}
|
||||
type=semver,pattern={{major}},value=${{ steps.semantic.outputs.next_release_version }}
|
||||
# - name: Check Docker image
|
||||
# run: |
|
||||
# set -x;
|
||||
# docker images;
|
||||
# docker run --rm ${{ steps.docker-build-push.outputs.imageid }} whoami;
|
57
.github/workflows/setup-node-environment.yml
vendored
Normal file
57
.github/workflows/setup-node-environment.yml
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "setup-node-environment/**"
|
||||
- ".github/workflows/setup-node-environment.yml"
|
||||
push:
|
||||
paths:
|
||||
- "setup-node-environment/**"
|
||||
- ".github/workflows/setup-node-environment.yml"
|
||||
env:
|
||||
TZ: Asia/Shanghai
|
||||
|
||||
jobs:
|
||||
job:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
container-image: ["", "yanhao98/runner-images:pnpm"]
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ${{ matrix.container-image }}
|
||||
steps:
|
||||
- name: before
|
||||
run: |
|
||||
set -x;
|
||||
which pnpm || true;
|
||||
node -v;
|
||||
|
||||
- uses: yanhao98/composite-actions/setup-node-environment@main
|
||||
|
||||
- name: Check Node and PNPM versions
|
||||
run: |
|
||||
set -x;
|
||||
which pnpm;
|
||||
node -v;
|
||||
pnpm node -v;
|
||||
|
||||
job-2: # 测试 .npmrc 文件没有 use-node-version 字段
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@main
|
||||
- name: before
|
||||
run: |
|
||||
set -x;
|
||||
cat .npmrc;
|
||||
sed -i '/use-node-version/d' .npmrc
|
||||
node -v;
|
||||
cat .npmrc;
|
||||
|
||||
- uses: yanhao98/composite-actions/setup-node-environment@main
|
||||
|
||||
- name: Check Node and PNPM versions
|
||||
run: |
|
||||
set -x;
|
||||
which pnpm;
|
||||
node -v;
|
||||
pnpm node -v;
|
1
.npmrc
Normal file
1
.npmrc
Normal file
@ -0,0 +1 @@
|
||||
use-node-version=22.9.0 # https://pnpm.io/zh/npmrc#use-node-version
|
7
.releaserc.json
Normal file
7
.releaserc.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
"@semantic-release/changelog"
|
||||
]
|
||||
}
|
1
README.md
Normal file
1
README.md
Normal file
@ -0,0 +1 @@
|
||||
- https://github.com/renovatebot/renovate/blob/81fc75630b0b43fb4b89a0b65c1086d487e65d2e/.github/actions/setup-node/action.yml
|
22
deploy-dist-to-surge/action.yml
Normal file
22
deploy-dist-to-surge/action.yml
Normal file
@ -0,0 +1,22 @@
|
||||
name: "Deploy dist to Surge"
|
||||
description: "部署 dist 到 Surge"
|
||||
outputs:
|
||||
url:
|
||||
description: "Preview URL"
|
||||
value: ${{ steps.surge_deploy.outputs.url }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: 部署到 Surge
|
||||
shell: bash
|
||||
id: surge_deploy
|
||||
# https://github.com/afc163/surge-preview
|
||||
# https://github.com/Tencent/tdesign-vue-next/pull/1604#issuecomment-1236244550
|
||||
# https://github.com/Tencent/tdesign-vue-next/blob/03036a19adccf4657d7792e3a61a6c6a7d902e3e/.github/workflows/preview-publish.yml
|
||||
# https://github.com/Tencent/tdesign/blob/0c0c9b63897c05d10c58e1a1e36feda2cb99eca7/.github/workflows/preview.yml#L40
|
||||
run: |
|
||||
export DEPLOY_DOMAIN=https://${{ github.sha }}.surge.sh
|
||||
cp dist/index.html dist/200.html
|
||||
npx surge --project ./dist --domain $DEPLOY_DOMAIN --token d843de16b331c626f10771245c56ed93 # npx surge token
|
||||
echo the preview URL is $DEPLOY_DOMAIN
|
||||
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT
|
@ -33,7 +33,19 @@ outputs:
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Check .git folder
|
||||
id: check-git-folder
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -d .git ]; then
|
||||
echo "Found .git folder"
|
||||
echo "git-folder-exists=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "No .git folder found"
|
||||
echo "git-folder-exists=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- uses: actions/checkout@main
|
||||
if: steps.check-git-folder.outputs.git-folder-exists == 'false'
|
||||
with:
|
||||
filter: blob:none
|
||||
show-progress: false
|
||||
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"https://git.1-h.cc/examples/renovate-example/raw/branch/main/default.json5"
|
||||
"https://git.1-h.cc/examples/renovate-example/raw/branch/main/default.json5",
|
||||
":automergeAll"
|
||||
],
|
||||
"dependencyDashboard": false
|
||||
}
|
@ -16,7 +16,19 @@ description: "Setup pnpm + Node.js + install dependencies"
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: Check .git folder
|
||||
id: check-git-folder
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -d .git ]; then
|
||||
echo "Found .git folder"
|
||||
echo "git-folder-exists=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "No .git folder found"
|
||||
echo "git-folder-exists=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- uses: actions/checkout@main
|
||||
if: steps.check-git-folder.outputs.git-folder-exists == 'false'
|
||||
with:
|
||||
# fetch-depth: 0 # zero stands for full checkout, which is required for semantic-release
|
||||
filter: blob:none # we don't need all blobs, only the full tree
|
||||
@ -27,27 +39,53 @@ runs:
|
||||
id: prepare
|
||||
run: |
|
||||
# Check package manager
|
||||
packageManager=$(jq -r '.packageManager' package.json)
|
||||
echo "packageManager: $packageManager"
|
||||
packageManager=$(node -p "require('./package.json').packageManager")
|
||||
echo "##########################################################"
|
||||
echo "packageManager: $packageManager found in package.json"
|
||||
echo ""
|
||||
|
||||
if [[ "$packageManager" == "pnpm"* ]]; then
|
||||
echo "##########################################################"
|
||||
# TODO: 还有一种情况就是镜像中已经安装了pnpm。
|
||||
echo "setup-pnpm=true"
|
||||
echo ""
|
||||
|
||||
echo "setup-pnpm=true" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
# Check if pnpm-lock.yaml exists
|
||||
if [[ -f "pnpm-lock.yaml" ]]; then
|
||||
echo "pnpm-lock.yaml exists"
|
||||
echo "##########################################################"
|
||||
echo "pnpm-lock.yaml exists. So pnpm install --frozen-lockfile will run"
|
||||
echo ""
|
||||
|
||||
echo "pnpm-lock-exists=true" >> $GITHUB_OUTPUT
|
||||
echo "cache=pnpm" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "pnpm-lock.yaml does not exist"
|
||||
fi
|
||||
|
||||
|
||||
# Extract the node version from the .npmrc file
|
||||
nodeVersion=$(sed -n 's/.*use-node-version=\([0-9.]*\).*/\1/p' .npmrc)
|
||||
if [[ -z "$nodeVersion" ]]; then
|
||||
nodeVersion="lts/*"
|
||||
echo "##########################################################"
|
||||
echo "Node version not found in .npmrc. Using default: $nodeVersion"
|
||||
echo ""
|
||||
else
|
||||
echo "##########################################################"
|
||||
echo "Node version found in .npmrc: $nodeVersion"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "node-version=$nodeVersion" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: pnpm/action-setup@v4 # https://github.com/pnpm/action-setup?tab=readme-ov-file#inputs
|
||||
if: steps.prepare.outputs.setup-pnpm == 'true'
|
||||
- uses: actions/setup-node@v4 # https://github.com/actions/setup-node?tab=readme-ov-file#usage
|
||||
with:
|
||||
node-version: lts/*
|
||||
node-version: ${{ steps.prepare.outputs.node-version }}
|
||||
cache: ${{ steps.prepare.outputs.cache }}
|
||||
- name: 📦 Install Project Dependencies
|
||||
if: steps.prepare.outputs.pnpm-lock-exists == 'true'
|
||||
|
Reference in New Issue
Block a user