重构Laravel应用的GitHub Workflow:简化文件归档步骤
优化Laravel应用构建归档的GitHub Workflow(无需创建dist文件夹)
你完全可以跳过创建dist文件夹的步骤,直接用一行zip命令完成归档,只需要排除掉不需要的目录即可。
修改步骤:
- 删除原Workflow中
Create dist和montudor/action-zip这两个步骤 - 新增一个步骤,直接执行打包命令:
- 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
相关产品推荐
相关产品推荐

