From 661c7b87c1ae7378bd97b3e16af4939296c87173 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?=
<37316281+yanhao98@users.noreply.github.com>
Date: Sat, 5 Jul 2025 11:56:31 +0800
Subject: [PATCH] Feat/surge customizable dirs (#49)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat: Allow customizing working_dir and dist_dir for Surge deployment
This commit introduces two new optional inputs to the `deploy-dist-to-surge` action:
- `working_dir`: Specifies the directory from which the Surge command should be run. Defaults to the repository root (`.`).
- `dist_dir`: Specifies the directory containing the built assets to deploy, relative to `working_dir`. Defaults to `dist`.
These changes provide more flexibility for projects where the build output is not in the default `dist` folder at the root of the repository.
Updated README.md with details on the new inputs and an example usage.
* feat: Allow customizing working_dir and dist_dir for Surge deployment
This commit introduces two new optional inputs to the `deploy-dist-to-surge` action:
- `working_dir`: Specifies the directory from which the Surge command should be run. Defaults to the repository root (`.`).
- `dist_dir`: Specifies the directory containing the built assets to deploy, relative to `working_dir`. Defaults to `dist`.
These changes provide more flexibility for projects where the build output is not in the default `dist` folder at the root of the repository.
Updated README.md with details on the new inputs and an example usage.
Also updated the test workflow `.github/workflows/deploy-dist-to-surge-tetst.yaml` to utilize and verify these new inputs.
* feat: 支持唯一测试域名并更新中文描述
此提交为 `deploy-dist-to-surge` 操作引入了 `domain_suffix` 输入,以允许在同一工作流程中为多次部署生成唯一的 Surge 域名,这对于测试至关重要。
同时包含先前对 `working_dir` 和 `dist_dir` 输入的支持,并更新了 `action.yml` 和 `README.md` 中的所有相关描述为中文。
测试工作流程已更新以使用 `domain_suffix` 并验证自定义目录和默认目录的部署。
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
---
.../workflows/deploy-dist-to-surge-tetst.yaml | 50 ++++++++++++--
README.md | 66 +++++++++++++++++++
deploy-dist-to-surge/action.yml | 21 +++++-
3 files changed, 128 insertions(+), 9 deletions(-)
diff --git a/.github/workflows/deploy-dist-to-surge-tetst.yaml b/.github/workflows/deploy-dist-to-surge-tetst.yaml
index cfd1e50..fe486f8 100644
--- a/.github/workflows/deploy-dist-to-surge-tetst.yaml
+++ b/.github/workflows/deploy-dist-to-surge-tetst.yaml
@@ -14,13 +14,51 @@ jobs:
job:
runs-on: ubuntu-latest
steps:
- - name: 准备部署文件
+ - name: Checkout code # Required to use the local version of the action
+ uses: actions/checkout@v3
+
+ - name: 准备部署文件 (Testing working_dir and dist_dir)
+ run: |
+ mkdir -p test_project/build_output
+ html="
Test: ${{ github.event_name }}: ${{ github.sha }} - Custom Dirs
"
+ 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="${{ github.event_name }}: ${{ github.sha }}
"
+ html="Test: ${{ github.event_name }}: ${{ github.sha }} - Default Dist
"
echo $html > dist/index.html
- - uses: yanhao98/composite-actions/deploy-dist-to-surge@main
- id: surge_deploy
- - name: Check Surge URL
+
+ - 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 "steps.surge_deploy.outputs.url: ${{ steps.surge_deploy.outputs.url }}"
+ 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 }}"
diff --git a/README.md b/README.md
index 3c2ae6c..00fb9af 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,67 @@
+# GitHub Actions Collection
+
+This repository contains a collection of reusable GitHub Actions.
+
+## Actions
+
+### Deploy dist to Surge (`deploy-dist-to-surge`)
+
+Deploys a distribution folder (typically `dist/`) to Surge.sh.
+
+#### Inputs
+
+| 名称 | 描述 | 是否必须 | 默认值 |
+|---------------|-----------------------------------------------------------------------------------------------------------------|----------|---------|
+| `working_dir` | 执行 Surge 部署的工作目录。默认为仓库根目录。 | `false` | `.` |
+| `dist_dir` | 包含要部署的构建产物的目录。如果指定了 `working_dir`,则相对于 `working_dir`,否则相对于仓库根目录。 | `false` | `dist` |
+| `domain_suffix` | 部署时用于创建唯一域名的后缀(例如,用于在同一工作流程中测试多个实例)。最终域名将是 `.surge.sh`。 | `false` | `''` |
+| `surge_token` | **已弃用.** 用于部署的 Surge 令牌。建议在工作流程中将其设置为环境变量 `SURGE_TOKEN`。 | `false` | (从 `SURGE_TOKEN` 环境变量读取,如果未设置则使用硬编码令牌) |
+
+
+#### Outputs
+
+| Name | Description |
+|-------|------------------|
+| `url` | The Preview URL. |
+
+#### Example Usage
+
+```yaml
+name: Deploy to Surge
+
+on: [push]
+
+jobs:
+ deploy:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Setup Node.js
+ uses: actions/setup-node@v3
+ with:
+ node-version: '18'
+ # Assuming your build process outputs to 'build_output' inside 'frontend' directory
+ - name: Build application
+ run: |
+ cd frontend
+ npm install
+ npm run build
+ - name: Deploy to Surge
+ uses: YOUR_USERNAME/YOUR_REPONAME/deploy-dist-to-surge@main # Replace with your actual repo path
+ with:
+ working_dir: frontend
+ dist_dir: build_output
+ env:
+ SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} # Recommended way to provide the token
+```
+
+### Other Actions
+
+- **`docker-build-push`**: Builds and pushes Docker images.
+- **`npm-build-fix-to-nexus`**: Builds and fixes NPM packages for Nexus.
+- **`setup-node-environment`**: Sets up a Node.js environment.
+- **`upload-to-alist`**: Uploads files to Alist.
+
+---
+*Original reference note (can be removed or integrated elsewhere):*
- https://github.com/renovatebot/renovate/blob/81fc75630b0b43fb4b89a0b65c1086d487e65d2e/.github/actions/setup-node/action.yml
diff --git a/deploy-dist-to-surge/action.yml b/deploy-dist-to-surge/action.yml
index 83cbfe1..f1f95fd 100644
--- a/deploy-dist-to-surge/action.yml
+++ b/deploy-dist-to-surge/action.yml
@@ -1,5 +1,18 @@
name: "Deploy dist to Surge"
description: "部署 dist 到 Surge"
+inputs:
+ working_dir:
+ description: '执行 Surge 部署的工作目录。默认为仓库根目录。'
+ required: false
+ default: '.'
+ dist_dir:
+ description: '包含要部署的构建产物的目录。如果指定了 `working_dir`,则相对于 `working_dir`,否则相对于仓库根目录。'
+ required: false
+ default: 'dist'
+ domain_suffix:
+ description: '部署时用于创建唯一域名的后缀(例如,用于在同一工作流程中测试多个实例)。最终域名将是 `.surge.sh`。'
+ required: false
+ default: ''
outputs:
url:
description: "Preview URL"
@@ -15,8 +28,10 @@ runs:
# 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
+ if [ "${{ inputs.working_dir }}" != "." ]; then cd ${{ inputs.working_dir }}; fi
+ export DEPLOY_DOMAIN_PREFIX=${{ github.sha }}${{ inputs.domain_suffix }}
+ export DEPLOY_DOMAIN=https://${DEPLOY_DOMAIN_PREFIX}.surge.sh
+ cp ${{ inputs.dist_dir }}/index.html ${{ inputs.dist_dir }}/200.html
+ npx surge --project ./${{ inputs.dist_dir }} --domain $DEPLOY_DOMAIN --token d843de16b331c626f10771245c56ed93 # npx surge token
echo the preview URL is $DEPLOY_DOMAIN
echo "url=$DEPLOY_DOMAIN" >> $GITHUB_OUTPUT