implement staging workflow

This commit is contained in:
Kevin
2026-05-09 16:16:48 +08:00
parent f0e37c5e76
commit 175784292d
9 changed files with 157 additions and 61 deletions

View File

@@ -11,7 +11,10 @@
# push main → stage → node scripts/use-env.js staging → .env.staging
# push v*.*.* → prod → node scripts/use-env.js production → .env.production
#
# 手动触发 workflow_dispatch可选 dev / stage / proddev 用 .env.development便于打内部测试包
# 手动触发 workflow_dispatch
# - dev内部测试包使用 .env.development
# - stage仅用于 main / master 补跑 Staging release使用 .env.staging
# - prod用于 vMAJOR.MINOR.PATCH tag或在 main / master 上填写 version 后发正式 Release
#
# Repository secrets与 android-release.yml 共用同一套即可):
# ANDROID_KEYSTORE_BASE64 / ANDROID_STORE_PASSWORD / ANDROID_KEY_ALIAS / ANDROID_KEY_PASSWORD
@@ -28,7 +31,7 @@ on:
workflow_dispatch:
inputs:
environment:
description: '部署环境'
description: '部署环境stage 请在 main 上补跑prod 请使用 v tag 或在 main 上填写 version'
required: true
type: choice
options:
@@ -67,15 +70,49 @@ jobs:
- name: Determine environment
id: env
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "env=prod"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "env=${{ github.event.inputs.environment }}"
elif [[ "${{ github.ref }}" == refs/tags/v* ]]; then
echo "env=prod"
else
# push 到 main本 workflow 仅监听 main 与 tag
echo "env=stage"
fi >> $GITHUB_OUTPUT
- name: Validate manual release ref
if: github.event_name == 'workflow_dispatch'
run: |
ENVIRONMENT="${{ steps.env.outputs.env }}"
REF="${{ github.ref }}"
REF_NAME="${{ github.ref_name }}"
VERSION="${{ github.event.inputs.version }}"
case "$ENVIRONMENT" in
dev)
echo "dev 构建允许使用当前 ref: $REF_NAME"
;;
stage)
if [ "$REF_NAME" != "main" ] && [ "$REF_NAME" != "master" ]; then
echo "::error::Staging release 只允许在 main / master 上手动补跑,当前 ref 为 '$REF_NAME'。"
exit 1
fi
;;
prod)
if [[ "$REF" == refs/tags/v* && "$REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "使用 tag $REF_NAME 发正式 Release。"
elif { [ "$REF_NAME" = "main" ] || [ "$REF_NAME" = "master" ]; } && [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "使用 main / master 和显式版本 v$VERSION 发正式 Release。"
else
echo "::error::Production release 需要选择 vMAJOR.MINOR.PATCH tag或在 main / master 上填写语义化 version。"
exit 1
fi
;;
*)
echo "::error::未知部署环境 '$ENVIRONMENT'。"
exit 1
;;
esac
- name: Set up Node.js
uses: actions/setup-node@v5
with: