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

重构Laravel应用的GitHub Workflow:简化文件归档步骤

优化Laravel应用构建归档的GitHub Workflow(无需创建dist文件夹)

你完全可以跳过创建dist文件夹的步骤,直接用一行zip命令完成归档,只需要排除掉不需要的目录即可。

修改步骤:

  1. 删除原Workflow中Create dist和montudor/action-zip这两个步骤
  2. 新增一个步骤,直接执行打包命令:
- name: Build archive
  run: zip -qq -r build.zip . -x ".git/*" "node_modules/*"

修改后的完整Workflow代码:

name: "Build and Deploy"

on:
  push:
    tags:
      - "v*.*.*"
permissions:
  contents: write

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x]
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
        with:
          version: 7
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "pnpm"

      - uses: php-actions/composer@v6
        with:
          dev: no
          php_version: latest
          args: --profile --ignore-platform-reqs

      - name: Copy env
        run: cp .env.example .env

      - name: Generate key
        run: php artisan key:generate

      - name: Install dependencies
        run: pnpm install

      - name: Build
        run: pnpm run build

      - name: Build archive
        run: zip -qq -r build.zip . -x ".git/*" "node_modules/*"

      - name: Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: |
            build.zip

命令说明:

  • zip -qq -r build.zip .:递归打包当前目录下所有文件到build.zip,-qq是静默模式,减少冗余输出
  • -x ".git/*" "node_modules/*":排除.git和node_modules目录下的所有内容,避免打包不必要的文件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 04:15:11