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

如何使用Github Actions打包包含Git子模块的zip压缩包

修复方案

你遇到的问题由两处配置错误共同导致:

  1. actions/checkout 默认不会拉取Git子模块内容
  2. 同一个Step下定义了两个run字段,GitHub Actions只会执行最后一个run对应的命令,你写的git submodule update --init --recursive根本没有运行

修复后的完整工作流配置

name: Deploy

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@v4 # 建议升级到最新的v4版本,兼容性更好
        with:
          submodules: 'recursive' # 新增参数,递归拉取所有子模块
          fetch-depth: 0

      - name: Generate deployment package
        run: | # 用多行写法合并两个命令,保证都会执行
          git submodule update --init --recursive
          zip -r deploy.zip . -x '*.git*'

      - name: Get timestamp
        uses: gerred/actions/current-time@master
        id: current-time
        
      - name: Run string replace
        uses: frabert/replace-string-action@master
        id: format-time
        with:
          pattern: '[:\.]+'
          string: "${{ steps.current-time.outputs.time }}"
          replace-with: '-'
          flags: 'g'

      - name: Deploy to EB
        uses: einaregilsson/beanstalk-deploy@v18
        with:
          aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws_secret_key: ${{ secrets.AWS_SECRET_KEY }}
          application_name: test-stage
          environment_name: Testenv-env
          version_label: "${{ steps.format-time.outputs.replaced }}"
          region: eu-central-1 # 注意AWS没有eu-center-1区域,此处修正为常见的eu-central-1(法兰克福区),如果你用的是其他区域请自行调整
          deployment_package: deploy.zip

额外优化建议

  • 如果你的子模块是私有仓库,需要在actions/checkout的with参数中新增token: ${{ secrets.GITHUB_TOKEN }},保证工作流有权限拉取私有子模块代码
  • 可以移除第三方的时间戳和字符串替换步骤,直接使用GitHub Actions内置变量${{ github.run_id }}作为版本号,减少第三方动作依赖,配置更简洁:
    version_label: "deploy-${{ github.run_id }}"
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 23:15:06