Introduction
Every ShopNest push to main should build, test, and deploy automatically — GitHub Actions YAML pipelines replace manual FTP uploads.
After this article you will
- Write build-test-deploy workflow YAML
- Run dotnet test in CI with coverage
- Deploy to Azure App Service on success
- Store secrets in GitHub Secrets
- Require PR checks before merge
Prerequisites
- Article 61 — Azure App Service
- ShopNest solution builds and tests pass locally
Concept deep-dive
# .github/workflows/shopnest-ci.yml
name: ShopNest CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- run: dotnet restore ShopNest.sln
- run: dotnet build ShopNest.sln -c Release --no-restore
- run: dotnet test ShopNest.sln -c Release --no-build --verbosity normal
- run: dotnet publish ShopNest.Web/ShopNest.Web.csproj -c Release -o ./publish
- uses: azure/webapps-deploy@v3
if: github.ref == 'refs/heads/main'
with:
app-name: shopnest-prod
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
Branch strategy: feature/* → PR → develop → main. PR workflow runs tests only; main deploys.
Hands-on — ShopNest Automated Deployment Pipeline
- Add workflow file; push to trigger.
- Store AZURE_PUBLISH_PROFILE in GitHub Secrets.
- Add branch protection: require build pass.
- Optional: Codecov upload from test step.
- Slack/email notify on failure.
Common errors & best practices
- Secrets in YAML — use ${{ secrets.NAME }} only.
- Deploy on PR — gate deploy with if: github.ref == 'refs/heads/main'.
- Missing EF tools for migration step — add dotnet-ef tool install.
Interview questions
Q: CI vs CD?
A: CI builds/tests; CD deploys artifact to environment.
Q: Where store Azure creds?
A: GitHub Secrets or OIDC federated credentials to Azure.
Summary
- YAML pipeline: restore → build → test → publish → deploy
- PR checks catch breaks before merge
- Secrets never in repository
- Publish profile or OIDC for Azure deploy
Previous: Azure App Service
Next: Azure SQL Database
FAQ
Azure DevOps instead?
Similar YAML; GitHub Actions native if code on GitHub.
Run migrations in CI?
Separate job with production connection secret — use carefully.