From cd7ff2bb9061e2e4c77858309a08bb10f4c7733d Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Thu, 8 May 2025 18:07:55 +0200 Subject: [PATCH 1/8] Pr verify basic workflow --- .github/workflows/pr-verify.yml | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/pr-verify.yml diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml new file mode 100644 index 00000000..374b619f --- /dev/null +++ b/.github/workflows/pr-verify.yml @@ -0,0 +1,69 @@ +name: PR Verify + +env: + AZURE_WEBAPP_NAME: your-app-name # set this to the name of your Azure Web App + AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root + DOTNET_VERSION: '5' # set this to the .NET Core version to use + +on: + push: + branches: [ "main" ] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Set up dependency caching for faster builds + uses: actions/cache@v3 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: | + ${{ runner.os }}-nuget- + + - name: Build with dotnet + run: dotnet build --configuration Release + + - name: dotnet publish + run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v4 + with: + name: .net-app + path: ${{env.DOTNET_ROOT}}/myapp + + deploy: + permissions: + contents: none + runs-on: ubuntu-latest + needs: build + environment: + name: 'Development' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + name: .net-app + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ env.AZURE_WEBAPP_NAME }} + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} + package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} From 2a414ad79ffe0a5c7ae8628fc8d08e754bfd1e39 Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Thu, 8 May 2025 18:17:32 +0200 Subject: [PATCH 2/8] Update pr-verify.yml --- .github/workflows/pr-verify.yml | 51 +++------------------------------ 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml index 374b619f..cfc983e6 100644 --- a/.github/workflows/pr-verify.yml +++ b/.github/workflows/pr-verify.yml @@ -6,15 +6,12 @@ env: DOTNET_VERSION: '5' # set this to the .NET Core version to use on: - push: + pull_request: branches: [ "main" ] - workflow_dispatch: - -permissions: - contents: read jobs: build: + name: PR Verify runs-on: ubuntu-latest steps: @@ -23,47 +20,7 @@ jobs: - name: Set up .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: ${{ env.DOTNET_VERSION }} - - - name: Set up dependency caching for faster builds - uses: actions/cache@v3 - with: - path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - restore-keys: | - ${{ runner.os }}-nuget- + dotnet-version: 8.0 - name: Build with dotnet - run: dotnet build --configuration Release - - - name: dotnet publish - run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp - - - name: Upload artifact for deployment job - uses: actions/upload-artifact@v4 - with: - name: .net-app - path: ${{env.DOTNET_ROOT}}/myapp - - deploy: - permissions: - contents: none - runs-on: ubuntu-latest - needs: build - environment: - name: 'Development' - url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} - - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - name: .net-app - - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v2 - with: - app-name: ${{ env.AZURE_WEBAPP_NAME }} - publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} - package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} + run: dotnet build --configuration Release \ No newline at end of file From 312ef8c783da37c70ffdf7348cff1c35d317ef35 Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Thu, 8 May 2025 18:35:50 +0200 Subject: [PATCH 3/8] New line for weatherforecast (#1) * New line for weatherforecast * Update WeatherForecast.cs * break the build --- src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs b/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs index 786b4a10..88d9fbb3 100644 --- a/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs +++ b/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs @@ -9,4 +9,4 @@ public record WeatherForecast public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); public string? Summary { get; init; } -} +} \ No newline at end of file From 9f6be6a21dbfd01427e36e1f095cc4b614666a13 Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Thu, 8 May 2025 18:54:26 +0200 Subject: [PATCH 4/8] Add dotnet test to pr verify (#2) * add dotnet test to pr verify * add failing test --- .github/workflows/pr-verify.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml index cfc983e6..826752c7 100644 --- a/.github/workflows/pr-verify.yml +++ b/.github/workflows/pr-verify.yml @@ -23,4 +23,7 @@ jobs: dotnet-version: 8.0 - name: Build with dotnet - run: dotnet build --configuration Release \ No newline at end of file + run: dotnet build --configuration Release + + - name: DotNet Test + run: dotnet test --configuration Release --no-build \ No newline at end of file From f7c863afe758093023b5c7e129d355dd9910b3ae Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Sat, 10 May 2025 14:16:39 +0200 Subject: [PATCH 5/8] Add formatting and migrate to dotnet 9 (#3) * Add formatting and migrate to dotnet 9 * Update pr-verify.yml --- .github/workflows/pr-verify.yml | 7 +++++-- global.json | 2 +- .../GitHubActionsDotNet.Api.Tests.csproj | 2 +- .../Controllers/WeatherForecastController.cs | 5 ++--- src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj | 2 +- src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml index 826752c7..6056dc0b 100644 --- a/.github/workflows/pr-verify.yml +++ b/.github/workflows/pr-verify.yml @@ -20,10 +20,13 @@ jobs: - name: Set up .NET Core uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0 + dotnet-version: 9.0 - name: Build with dotnet run: dotnet build --configuration Release - name: DotNet Test - run: dotnet test --configuration Release --no-build \ No newline at end of file + run: dotnet test --configuration Release --no-build + + - name: DotNet Fromatting + run: dotnet format -v detailed --verify-no-changes \ No newline at end of file diff --git a/global.json b/global.json index 2ddda36c..93681ff8 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.0", + "version": "9.0.0", "rollForward": "latestMinor", "allowPrerelease": false } diff --git a/src/GitHubActionsDotNet.Api.Tests/GitHubActionsDotNet.Api.Tests.csproj b/src/GitHubActionsDotNet.Api.Tests/GitHubActionsDotNet.Api.Tests.csproj index 424bab8f..e8a7bed8 100644 --- a/src/GitHubActionsDotNet.Api.Tests/GitHubActionsDotNet.Api.Tests.csproj +++ b/src/GitHubActionsDotNet.Api.Tests/GitHubActionsDotNet.Api.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs b/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs index d91d7957..f017a55a 100644 --- a/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs +++ b/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs @@ -21,11 +21,10 @@ public class WeatherForecastController : ControllerBase ]; [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() => Enumerable.Range(1, 5).Select(index => new WeatherForecast + public IEnumerable Get() => [.. Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), TemperatureC = Random.Shared.Next(-20, 55), Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); + })]; } diff --git a/src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj b/src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj index f18b2634..7bcce63a 100644 --- a/src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj +++ b/src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable true diff --git a/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs b/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs index 88d9fbb3..786b4a10 100644 --- a/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs +++ b/src/GitHubActionsDotNet.Api/Models/WeatherForecast.cs @@ -9,4 +9,4 @@ public record WeatherForecast public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); public string? Summary { get; init; } -} \ No newline at end of file +} From 66927af4324bc34d6b709d58bb93dad1f5eec4f2 Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Sat, 10 May 2025 15:14:02 +0200 Subject: [PATCH 6/8] Create ci.yml (#6) --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..b22726d3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: + push: + branches: [ "main" ] + +jobs: + build: + name: CI + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up .Net Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0 + + - name: dotnet test + run: dotnet test --configuration Release + + - name: dotnet publish + run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifcats \ No newline at end of file From bea014162602b86eb834c094cbd0ac8bd7229e73 Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Sat, 10 May 2025 15:26:46 +0200 Subject: [PATCH 7/8] upload artifact as part of CI (#7) --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b22726d3..02fb909a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,4 +21,10 @@ jobs: run: dotnet test --configuration Release - name: dotnet publish - run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifcats \ No newline at end of file + run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifcats + + - name: upload artifactes + uses: actions/upload-artifact@v4 + with: + name: lab-artifact + path: artifcats/ \ No newline at end of file From 11c69421c631489e09063e15113989e814a3375f Mon Sep 17 00:00:00 2001 From: Fathi Chabane Date: Sat, 10 May 2025 15:46:40 +0200 Subject: [PATCH 8/8] Create cron.yml --- .github/workflows/cron.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/cron.yml diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml new file mode 100644 index 00000000..5e185f76 --- /dev/null +++ b/.github/workflows/cron.yml @@ -0,0 +1,17 @@ +name: Run every minute + # set this to the .NET Core version to use +on: + schedule: + - cron: "*/5 * * * *" + + +jobs: + cron: + name: Run every 5 minutes + runs-on: ubuntu-latest + + steps: + - name: Greetings + run: echo "Hello World" + + \ No newline at end of file