From 5e94794083c217e69f4e4bb141e2f7e2b1fc364c Mon Sep 17 00:00:00 2001 From: Francisco Gavilan Date: Sat, 11 Jan 2025 13:33:55 -0400 Subject: [PATCH 01/17] First Commit after including the workflow --- .github/workflows/pr-verify.yml | 22 ++++++++++++++++++++++ .vscode/launch.json | 15 +++++++++++++++ global.json | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pr-verify.yml create mode 100644 .vscode/launch.json diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml new file mode 100644 index 00000000..2e846fc4 --- /dev/null +++ b/.github/workflows/pr-verify.yml @@ -0,0 +1,22 @@ +name: PR Verify + +on: + pull_request: + branches: [ "main" ] + +jobs: + build: + name: PR Verify + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0 + + - name: Build with dotnet + run: dotnet build --configuration Release \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..2ba986f6 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ 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 } From af9eceb2afb39703f9b4e891465d707dd0390744 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 14:43:41 -0400 Subject: [PATCH 02/17] Fixed spacing for method chaining (#1) * Fixeed spacing for method chaining * Break the build --- .../Controllers/WeatherForecastController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs b/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs index d91d7957..616ea866 100644 --- a/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs +++ b/src/GitHubActionsDotNet.Api/Controllers/WeatherForecastController.cs @@ -26,6 +26,6 @@ public class WeatherForecastController : ControllerBase Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), TemperatureC = Random.Shared.Next(-20, 55), Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); + }).ToArray(); } + From a1b64728abedaa025403f1a9f0ded86568c1bb6b Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 15:55:59 -0400 Subject: [PATCH 03/17] Add dotnet tests to pr verify (#2) --- .github/workflows/pr-verify.yml | 5 ++++- .../GitHubActionsDotNet.Api.Tests.csproj | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml index 2e846fc4..6e56f7a0 100644 --- a/.github/workflows/pr-verify.yml +++ b/.github/workflows/pr-verify.yml @@ -19,4 +19,7 @@ jobs: dotnet-version: 9.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 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 From db8d071a7a0ec750370c95f4e39234b606f35c38 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 21:08:29 -0400 Subject: [PATCH 04/17] break tests (#3) From fdf3bbb3b3d0926d0990d4b1df4e536c623cd35b Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 21:28:06 -0400 Subject: [PATCH 05/17] Add format validation to app (#4) --- .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 6e56f7a0..df2f94e9 100644 --- a/.github/workflows/pr-verify.yml +++ b/.github/workflows/pr-verify.yml @@ -22,4 +22,7 @@ jobs: 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 format + run: dotnet format -v detailed --verify-no-changes \ No newline at end of file From b905028affa05ee271e5252348b8d5349e5a3fe4 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 21:44:07 -0400 Subject: [PATCH 06/17] Added issue for code analysis (#5) --- src/GitHubActionsDotNet.Api.Tests/Models/WeatherForecastTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitHubActionsDotNet.Api.Tests/Models/WeatherForecastTests.cs b/src/GitHubActionsDotNet.Api.Tests/Models/WeatherForecastTests.cs index f03d0f47..78c1a4c1 100644 --- a/src/GitHubActionsDotNet.Api.Tests/Models/WeatherForecastTests.cs +++ b/src/GitHubActionsDotNet.Api.Tests/Models/WeatherForecastTests.cs @@ -13,5 +13,6 @@ public void TemperatureFShouldReturnCorrectValueBasedOnTemperatureC() }; weatherForecast.TemperatureF.Should().Be(32); + weatherForecast.TemperatureF.Should().Be(32); } } From dbec7b535a0b056dfc641b1778cb7ba40677e333 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 22:24:56 -0400 Subject: [PATCH 07/17] Added CI (#6) --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 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..55d704d1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: CI Verify + +on: + push: + branches: [ "main" ] + +jobs: + build: + name: PR Verify + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 9.0 + + # Did not include a dotnet build step because imn the test, we are going to build anyway. We did not use the "--no-build" flag. + # Also, We have the test runiing imn another workflo, but this is so critical that we included this here again even if someone + # bypasses the ruleset, we will have these test here anyway. + + - name: dotnet test + run: dotnet test --configuration Release + + # I did not include a step for dotnet format because we already took care of that indirectly for this repo. We enforced rules to + # have the incomming branch to be updated with the branch "main" changes. Also, as status checks are required and we have other + # workflow thayt takes care of that, there is no need to include formatting here. + + # Of course, the recommendation is to have ALL verifications in the CI workflow + + - name: dotnet publish + run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifacts From dad679627d0e6f06633cd38b5810c4b5e6d98a99 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 22:34:32 -0400 Subject: [PATCH 08/17] Changed name of CI workflow (#7) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55d704d1..9cd0256d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI Verify +name: CI on: push: From e2b3003667bcf434baedb2ee7c8f8fc79dc3744f Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 22:46:57 -0400 Subject: [PATCH 09/17] Added upload artifact step (#8) --- .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 9cd0256d..586bf927 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: jobs: build: - name: PR Verify + name: ci runs-on: ubuntu-latest steps: @@ -33,3 +33,9 @@ jobs: - name: dotnet publish run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifacts + + - name: upload artifact + uses: actions/upload-artifact@v4 + with: + name: app-artifact + path: artifacts/ From acefad050e09cb90681cd0c2a2b6a4fa469e9dbc Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Sat, 11 Jan 2025 23:44:40 -0400 Subject: [PATCH 10/17] Added Printing variables (#9) --- .github/workflows/secrets.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/secrets.yml diff --git a/.github/workflows/secrets.yml b/.github/workflows/secrets.yml new file mode 100644 index 00000000..27b8ce14 --- /dev/null +++ b/.github/workflows/secrets.yml @@ -0,0 +1,20 @@ +name: Print Values + +on: + workflow_dispatch: + +env: + SOME_VALUE: Francisco + +jobs: + build: + name: Print + runs-on: ubuntu-latest + + steps: + - name: Print SOME_VALUE + run: echo "the value of SOME_VALUE is $SOME_VALUE" + + - name: Print SOME_VALUE with full syntax + run: echo "Again, the value of SOME_VALUE is ${{env.SOME_VALUE}}". + \ No newline at end of file From 25a88c815e816e425e6909919581ded95f1a201b Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Tue, 14 Jan 2025 08:59:26 -0400 Subject: [PATCH 11/17] Added cd pipeline (#10) --- .github/workflows/ci.yml | 23 +++++++++++++++++-- .../workflows/{secrets.yml => variables.yml} | 6 ++--- 2 files changed, 24 insertions(+), 5 deletions(-) rename .github/workflows/{secrets.yml => variables.yml} (69%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 586bf927..c6a27805 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,10 +32,29 @@ jobs: # Of course, the recommendation is to have ALL verifications in the CI workflow - name: dotnet publish - run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifacts + run: dotnet publish src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj --configuration Release -o artifacts-release-folder - name: upload artifact uses: actions/upload-artifact@v4 with: - name: app-artifact + name: dometrain-artifact + path: artifacts-release-folder/ + + deploy-dev: + name: Deploy Dev + runs-on: ubuntu-latest + needs: build # We make sure this job waits for the "build" job + + steps: + - name: download artifact + uses: actions/download-artifact@v4 + with: + name: dometrain-artifact path: artifacts/ + + - name: 'Deploy to Azure App Srevice Name' + uses: azure/webapps-deploy@v2 + with: + app-name: app-dometrain-github-actions-fgavilan-dev + package: artifacts/ + \ No newline at end of file diff --git a/.github/workflows/secrets.yml b/.github/workflows/variables.yml similarity index 69% rename from .github/workflows/secrets.yml rename to .github/workflows/variables.yml index 27b8ce14..55aa0a31 100644 --- a/.github/workflows/secrets.yml +++ b/.github/workflows/variables.yml @@ -1,4 +1,4 @@ -name: Print Values +name: Print Variable Values on: workflow_dispatch: @@ -12,9 +12,9 @@ jobs: runs-on: ubuntu-latest steps: - - name: Print SOME_VALUE + - name: Print using runner's shell specific syntax run: echo "the value of SOME_VALUE is $SOME_VALUE" - - name: Print SOME_VALUE with full syntax + - name: Print using Context run: echo "Again, the value of SOME_VALUE is ${{env.SOME_VALUE}}". \ No newline at end of file From b87775f6ec5777859216583b1d2be9ddb3d3cf19 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Tue, 14 Jan 2025 18:59:40 -0400 Subject: [PATCH 12/17] Add Azure Login (#11) --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6a27805..1249d05a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,13 @@ jobs: name: dometrain-artifact path: artifacts/ + - name: Azure login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + - name: 'Deploy to Azure App Srevice Name' uses: azure/webapps-deploy@v2 with: From aa080ee4bdc63747ca403af3df5ca3a65ac0252f Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Tue, 14 Jan 2025 19:11:15 -0400 Subject: [PATCH 13/17] Add token permissions for OAuth (#12) --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1249d05a..515332f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,10 @@ on: push: branches: [ "main" ] +permissions: + id-token: write + contents: read + jobs: build: name: ci From 7fb37c93c7b5de5845d380f529c7a0367b34bae0 Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Wed, 15 Jan 2025 09:28:43 -0400 Subject: [PATCH 14/17] Updated api to ver 9 (#13) --- src/GitHubActionsDotNet.Api/GitHubActionsDotNet.Api.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3fae991cbe922d38369f4fbb3140ee587f8679db Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Wed, 15 Jan 2025 18:42:23 -0400 Subject: [PATCH 15/17] Added enviroemngs (#14) --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 515332f1..e29c5951 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,7 @@ jobs: name: Deploy Dev runs-on: ubuntu-latest needs: build # We make sure this job waits for the "build" job + environment: dev steps: - name: download artifact @@ -68,4 +69,31 @@ jobs: with: app-name: app-dometrain-github-actions-fgavilan-dev package: artifacts/ + + deploy-prod: + name: Deploy Pro + runs-on: ubuntu-latest + needs: deploy-dev + environment: prod + + steps: + - name: download artifact + uses: actions/download-artifact@v4 + with: + name: dometrain-artifact + path: artifacts/ + + - name: Azure login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: 'Deploy to Azure App Srevice Name' + uses: azure/webapps-deploy@v2 + with: + app-name: app-dometrain-github-actions-fgavilan-prod + package: artifacts/ + \ No newline at end of file From 8cda851ffda0de6da81bff3a436d4309fe31c0cd Mon Sep 17 00:00:00 2001 From: fgavilanm Date: Wed, 15 Jan 2025 20:30:15 -0400 Subject: [PATCH 16/17] Reuse deployment steps (#15) --- .github/workflows/ci.yml | 52 +++++---------------------- .github/workflows/deploy-to-azure.yml | 40 +++++++++++++++++++++ 2 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/deploy-to-azure.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e29c5951..f20c20ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,54 +46,20 @@ jobs: deploy-dev: name: Deploy Dev - runs-on: ubuntu-latest needs: build # We make sure this job waits for the "build" job - environment: dev - - steps: - - name: download artifact - uses: actions/download-artifact@v4 - with: - name: dometrain-artifact - path: artifacts/ + uses: ./.github/workflows/deploy-to-azure.yml + with: + env: prod + secrets: inherit - - name: Azure login - uses: azure/login@v2 - with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - - name: 'Deploy to Azure App Srevice Name' - uses: azure/webapps-deploy@v2 - with: - app-name: app-dometrain-github-actions-fgavilan-dev - package: artifacts/ deploy-prod: name: Deploy Pro - runs-on: ubuntu-latest - needs: deploy-dev - environment: prod - - steps: - - name: download artifact - uses: actions/download-artifact@v4 - with: - name: dometrain-artifact - path: artifacts/ + needs: deploy-dev + uses: ./.github/workflows/deploy-to-azure.yml + with: + env: prod + secrets: inherit - - name: Azure login - uses: azure/login@v2 - with: - client-id: ${{ secrets.AZURE_CLIENT_ID }} - tenant-id: ${{ secrets.AZURE_TENANT_ID }} - subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - - - name: 'Deploy to Azure App Srevice Name' - uses: azure/webapps-deploy@v2 - with: - app-name: app-dometrain-github-actions-fgavilan-prod - package: artifacts/ \ No newline at end of file diff --git a/.github/workflows/deploy-to-azure.yml b/.github/workflows/deploy-to-azure.yml new file mode 100644 index 00000000..f54cb0f6 --- /dev/null +++ b/.github/workflows/deploy-to-azure.yml @@ -0,0 +1,40 @@ +name: Deploy to azure + +on: + workflow_call: + inputs: + env: + required: true + type: string + secrets: + AZURE_CLIENT_ID: + required: true + AZURE_TENANT_ID: + required: true + AZURE_SUBSCRIPTION_ID: + required: true +jobs: + deploy: + name: Deploy ${{ inputs.env }} + runs-on: ubuntu-latest + environment: ${{ inputs.env }} + + steps: + - name: download artifact + uses: actions/download-artifact@v4 + with: + name: dometrain-artifact + path: artifacts/ + + - name: Azure login + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: 'Deploy to Azure App Service Name' + uses: azure/webapps-deploy@v2 + with: + app-name: app-dometrain-github-actions-fgavilan-${{ inputs.env }} + package: artifacts/ \ No newline at end of file From 46838dbdc170b76923e3f5b9b8fb78f3a3c0dfb1 Mon Sep 17 00:00:00 2001 From: Francisco Gavilan Date: Wed, 15 Jan 2025 20:58:51 -0400 Subject: [PATCH 17/17] Reusing workflow from another repo --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f20c20ee..158ed88a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: deploy-dev: name: Deploy Dev needs: build # We make sure this job waits for the "build" job - uses: ./.github/workflows/deploy-to-azure.yml + uses: fgavilanm/github-actions-reusable/.github/workflows/step-deploy-web-app-azure.yml@main #Instead of ./.github/workflows/deploy-to-azure.yml with: env: prod secrets: inherit