diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..158ed88a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,65 @@ +name: CI + +on: + push: + branches: [ "main" ] + +permissions: + id-token: write + contents: read + +jobs: + build: + name: ci + 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-release-folder + + - name: upload artifact + uses: actions/upload-artifact@v4 + with: + name: dometrain-artifact + path: artifacts-release-folder/ + + deploy-dev: + name: Deploy Dev + needs: build # We make sure this job waits for the "build" job + 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 + + + deploy-prod: + name: Deploy Pro + needs: deploy-dev + uses: ./.github/workflows/deploy-to-azure.yml + with: + env: prod + secrets: inherit + + + \ 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 diff --git a/.github/workflows/pr-verify.yml b/.github/workflows/pr-verify.yml new file mode 100644 index 00000000..df2f94e9 --- /dev/null +++ b/.github/workflows/pr-verify.yml @@ -0,0 +1,28 @@ +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 + + - name: dotnet test + run: dotnet test --configuration Release --no-build + + - name: dotnet format + run: dotnet format -v detailed --verify-no-changes \ No newline at end of file diff --git a/.github/workflows/variables.yml b/.github/workflows/variables.yml new file mode 100644 index 00000000..55aa0a31 --- /dev/null +++ b/.github/workflows/variables.yml @@ -0,0 +1,20 @@ +name: Print Variable Values + +on: + workflow_dispatch: + +env: + SOME_VALUE: Francisco + +jobs: + build: + name: Print + runs-on: ubuntu-latest + + steps: + - name: Print using runner's shell specific syntax + run: echo "the value of SOME_VALUE is $SOME_VALUE" + + - name: Print using Context + run: echo "Again, the value of SOME_VALUE is ${{env.SOME_VALUE}}". + \ 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 } 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.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); } } 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(); } + 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