You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action手动触发时读取master而非特性分支问题

问题分析与解决方案

问题根源

你漏掉了代码拉取(checkout)步骤。GitHub Actions 不会自动克隆你的仓库代码到运行器(runner)中,当前你的工作流直接执行脚本时,实际调用的是运行器本地残留的 master 分支代码,而非你选择的特性分支内容。

修复方案

在执行 PowerShell 脚本的步骤前,添加 actions/checkout 动作,确保拉取触发工作流时指定的特性分支的完整代码。

修改后的工作流代码

name: Deploy to persistent environment

on:
  workflow_dispatch:
    inputs:
      deployment_target:
        type: choice
        description: Choose an environment to deploy to
        options:
          - dev
          - staging
          - production

jobs:
  deploy-kms-to-persistent-environment:
    name: Deploy KMS to ${{ github.event.inputs.deployment_target}}
    runs-on: [self-hosted, 3shape-ubuntu-latest]

    steps:
    # 添加代码拉取步骤,确保获取特性分支的最新代码
    - name: Checkout repository code
      uses: actions/checkout@v4
      with:
        ref: ${{ github.ref }} # 拉取触发工作流的分支代码

    - name: Deploy application
      working-directory: ./src/deploy/kms-bicep
      shell: pwsh
      run: |
        ./deploy-release-application2.ps1

补充说明

  • actions/checkout@v4 是官方的代码拉取动作,ref: ${{ github.ref }} 会自动指向你在「Use workflow from」中选择的分支,确保所有文件(包括特性分支新增的脚本)都被拉取到运行器中。
  • 如果你的自托管运行器工作目录有残留代码,建议在 checkout 步骤添加 clean: true 参数,确保每次运行都拉取干净的代码:
    with:
      ref: ${{ github.ref }}
      clean: true
    

内容的提问来源于stack exchange,提问作者Claus Appel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 01:35:27