我正在开发托管在 GitHub 上的 ASP.NET Core 项目,并将其部署到 Azure Web 服务。项目结构包括 REST API 应用程序和 wwwroot 文件夹中的静态文件(JavaScript、JSON)。我想优化我们的 GitHub Actions 工作流程,以便在仅修改 wwwroot 文件夹中的文件时绕过整个构建过程。
我们当前的 GitHub 工作流程在合并到主分支时会触发构建和部署过程。示例工作流程配置如下:
name: Build and Conditional Deploy ASP.Net Core app to Azure Web App - MyOwnApp
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: windows-latest
if: contains(github.event.head_commit.message, '[build]')
steps:
- uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.x'
include-prerelease: true
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: 'MyOwnApp'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
package: ${{env.DOTNET_ROOT}}/myapp
deploy-wwwroot:
runs-on: windows-latest
if: "!contains(github.event.head_commit.message, '[build]')"
steps:
- uses: actions/checkout@v2
- name: List directory structure
run: dir # For Windows runner
- name: Deploy wwwroot to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: 'MyOwnApp'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
package: MyOwnApp/wwwroot
我希望工作流程在 wwwroot 外部进行更改时执行完整的构建和部署,并且仅在更改仅限于该目录时更新 Azure 上的 wwwroot。
当我仅在 wwwroot/js/sample.js 中提交更改并使用“已编辑示例”之类的提交消息时,文件会在 Azure 上更新,我可以通过浏览器访问更新后的 .js,但实际的 dotnet 应用程序会中断。由于某种原因,即使访问 wwwroot (wwwroot/js/sample.json) 中的相邻文件也会导致“您正在查找的资源已被删除、名称已更改或暂时不可用”。错误。但是,如果我通过在提交消息中包含“[build]”来构建(例如,“再次编辑样本[build]”),那么在漫长的构建过程后,一切都会正常运行。
如何修改 GitHub Actions 工作流程以绕过专门在 wwwroot 中进行更改的构建过程,而不破坏应用程序?
branches:
- main
paths:
include:
- YourProjPath/*
# for exampple:
# - scripts/*
# You can also exclude specific files in your case
exclude:
- wwwroot/*