GitHub Action工作流无效:Laravel FTP部署排除文件报错求助
问题解决与优化方案
一、修复exclude参数的YAML格式错误
你遇到的A sequence was not expected错误,核心原因是SamKirkland/FTP-Deploy-Action@4.3.3的exclude参数不支持YAML列表(序列)格式,它要求传入的是逗号分隔的字符串。
修改后的exclude配置如下:
exclude: public/**,vendor/**,crons/**,storage/**,.github,.github/**,.env,composer.json,composer.lock,.htaccess
完整修正后的main.yml内容:
on: push: branches: - staging name: 🚀 Deploy website on push jobs: web-deploy: name: 🎉 Deploy runs-on: ubuntu-latest timeout-minutes: 5 # time out after 15 minutes (default is 360 minutes) steps: - name: 🚚 Get latest code uses: actions/checkout@v3 - name: 📂 Sync files uses: SamKirkland/FTP-Deploy-Action@4.3.3 with: server: ${{ secrets.ftp_server }} username: ${{ secrets.ftp_username }} password: ${{ secrets.ftp_password }} server-dir: /public_html/admin-test-com/ exclude: public/**,vendor/**,crons/**,storage/**,.github,.github/**,.env,composer.json,composer.lock,.htaccess
二、实现仅上传变更文件
SamKirkland/FTP-Deploy-Action基于git-ftp开发,默认支持增量部署——它会通过Git提交记录对比本地仓库与服务器文件,仅上传发生变更的内容,无需额外配置。
需要注意几个关键点:
- 服务器文件需通过该Action首次部署,或已与Git仓库提交历史同步
- 避免手动修改服务器文件,否则会导致对比逻辑失效
- 若需重新全量同步所有文件,可添加
git-ftp-init: true参数(仅在必要时开启)
示例(强制全量同步):
- name: 📂 Sync files uses: SamKirkland/FTP-Deploy-Action@4.3.3 with: server: ${{ secrets.ftp_server }} username: ${{ secrets.ftp_username }} password: ${{ secrets.ftp_password }} server-dir: /public_html/admin-test-com/ exclude: public/**,vendor/**,crons/**,storage/**,.github,.github/**,.env,composer.json,composer.lock,.htaccess git-ftp-init: true # 仅首次部署或需要全量同步时启用
内容的提问来源于stack exchange,提问作者Rizwan Saleem
相关产品推荐
相关产品推荐

