Initial commit #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # GitHub Actions Workflow for ShippingApp CI/CD | |
| # | |
| # This workflow automates the build, test, and deployment process for the ShippingApp. | |
| # It is triggered on push and pull request events to ensure code quality and facilitate | |
| # continuous integration and delivery. | |
| # | |
| # Workflow Overview: | |
| # - Triggers: Runs on push to master/main branches and on pull requests | |
| # - Jobs: Build, test, and optionally deploy the application | |
| # - Environment: Configurable for different deployment targets (dev, staging, production) | |
| # | |
| # Prerequisites: | |
| # - Repository secrets should be configured for sensitive data (API keys, credentials) | |
| # - Node.js/Java/Python runtime environment (depending on your app stack) | |
| # - Test frameworks and dependencies properly configured in the project | |
| # | |
| # Customization: | |
| # - Modify trigger branches as needed for your branching strategy | |
| # - Add additional jobs for security scanning, code quality checks, etc. | |
| # - Configure deployment steps based on your infrastructure (AWS, Azure, GCP, etc.) | |
| name: Docker CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ feature/manuals] | |
| env: | |
| DOCKER_REGISTRY: docker.io | |
| IMAGE_NAME: easternshipping/api | |
| DOTNET_VERSION: '9.0.x' | |
| jobs: | |
| # Stage 1: Build & Test | |
| build-and-test: | |
| name: ποΈ Build & Test Application | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: π₯ Checkout code | |
| uses: actions/checkout@v4 | |
| - name: π§ Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: π¦ Restore dependencies | |
| run: dotnet restore ShippingRules.Api.slnf | |
| - name: ποΈ Build solution | |
| run: dotnet build ShippingRules.Api.slnf --configuration Release --no-restore | |
| - name: π§ͺ Run tests | |
| run: | | |
| if [ -d "tests" ]; then | |
| dotnet test tests/**/*.csproj --configuration Release --verbosity normal --logger trx | |
| else | |
| echo "No tests found, skipping test step" | |
| fi | |
| - name: π Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: '**/TestResults/**/*.trx' | |
| - name: β Build Summary | |
| run: | | |
| echo "### ποΈ Build Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "- .NET Version: ${{ env.DOTNET_VERSION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Build Status: β Success" >> $GITHUB_STEP_SUMMARY | |
| # Stage 2: Deploy to Production | |
| deploy-production: | |
| name: π Deploy to Production | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.event.inputs.environment == 'production' || startsWith(github.ref, 'refs/tags/v') | |
| environment: | |
| name: production | |
| url: ${{ steps.deploy.outputs.url }} | |
| steps: | |
| - name: π₯ Checkout code | |
| uses: actions/checkout@v4 | |
| - name: π Azure Login | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| - name: π Deploy to Azure App Service | |
| id: deploy | |
| uses: azure/webapps-deploy@v3 | |
| with: | |
| app-name: ${{ vars.AZURE_WEBAPP_NAME }} | |
| images: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} | |
| - name: π₯ Health Check | |
| run: | | |
| sleep 30 | |
| curl --fail --retry 5 --retry-delay 10 ${{ steps.deploy.outputs.webapp-url }}/health || exit 1 | |
| - name: π’ Notify Teams | |
| if: always() | |
| uses: jdcargile/[email protected] | |
| with: | |
| github-token: ${{ github.token }} | |
| ms-teams-webhook-uri: ${{ secrets.MS_TEAMS_WEBHOOK_URI }} | |
| notification-summary: "Production Deployment ${{ job.status }}" | |
| notification-color: ${{ job.status == 'success' && '28a745' || 'dc3545' }} | |
| - name: β Production Deployment Summary | |
| run: | | |
| echo "### π Production Deployment Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "- Environment: Production" >> $GITHUB_STEP_SUMMARY | |
| echo "- URL: ${{ steps.deploy.outputs.webapp-url }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Status: β Live" >> $GITHUB_STEP_SUMMARY |