diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml new file mode 100644 index 00000000..d28ee18e --- /dev/null +++ b/.github/workflows/ci-pr.yml @@ -0,0 +1,34 @@ +on: + pull_request: # Ce workflow se déclenche uniquement sur les MR + +jobs: + ci_merge_request: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Backend + - name: Setup .NET SDK + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Build backend + run: dotnet build --configuration Release + working-directory: ./backend + + # Frontend + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: '21.7.1' + + - name: Build frontend + run: npm install && npm run build + working-directory: ./frontend + + - name: Lint frontend + run: npm run lint + working-directory: ./frontend diff --git a/.github/workflows/deploy-infra-and-apps.yml b/.github/workflows/deploy-infra-and-apps.yml new file mode 100644 index 00000000..aa936c02 --- /dev/null +++ b/.github/workflows/deploy-infra-and-apps.yml @@ -0,0 +1,128 @@ +# Déclenche le workflow sur push ou déclenchement manuel +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + + workflow_dispatch: + + +# Permissions pour OIDC + lecture du repo +permissions: + id-token: write + contents: read + +# Variables globales pour le workflow +env: + AZURE_RG_NAME: rg-${{ vars.PROJECT_NAME }}-${{ vars.AZURE_RESOURCE_IDENTIFIER }} + +jobs: + # -------------------------- + # Job 1 : Déployer l'infrastructure + # -------------------------- + deploy_infrastructure: + runs-on: ubuntu-latest + environment: production # Utilisation de ton Federated Credential + + # Exposer le nom de l'App Service pour le job backend + outputs: + appServiceName: ${{ steps.bicep_deploy.outputs.appServiceName }} + staticWebAppName: ${{ steps.bicep_deploy.outputs.staticWebAppName }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + enable-AzPSSession: true + + - name: Create resource group if not exists + run: | + az group show --name ${{ env.AZURE_RG_NAME }} || + az group create --name ${{ env.AZURE_RG_NAME }} --location ${{ secrets.AZURE_REGION }} + + - name: Deploy bicep + id: bicep_deploy + uses: azure/arm-deploy@v2 + with: + subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }} + region: ${{ secrets.AZURE_REGION }} + template: ./infrastructure/main.bicep + parameters: project=${{ vars.PROJECT_NAME }} location=${{ secrets.AZURE_REGION }} swaLocation=${{ secrets.AZURE_SWA_REGION }} identifier=${{ vars.AZURE_RESOURCE_IDENTIFIER }} + resourceGroupName: ${{ env.AZURE_RG_NAME }} + + # -------------------------- + # Job 2 : Déployer le backend API + # -------------------------- + deploy_backend: + runs-on: ubuntu-latest + needs: deploy_infrastructure + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET SDK 9.0.x + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Publish the app + run: dotnet publish -c Release --property:PublishDir=publish + working-directory: ./backend + + - name: Login to Azure + 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 backend to App Service + uses: azure/webapps-deploy@v2 + with: + app-name: ${{ needs.deploy_infrastructure.outputs.appServiceName }} + package: ./backend/ParkNDeploy.Api/publish + + # -------------------------- + # Job 3 : Déployer le frontend + # -------------------------- + deploy_frontend: + runs-on: ubuntu-latest + needs: deploy_infrastructure + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build the app + run: npm install && npm run build + working-directory: ./frontend + + - name: Login to Azure + uses: azure/login@v2 + with: + client-id: ${{ secrets.AZURE_CLIENT_ID }} + tenant-id: ${{ secrets.AZURE_TENANT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + + - name: Get Static Web App deployment token + run: | + SWA_DEPLOYMENT_TOKEN=$(az staticwebapp secrets list -n ${{ needs.deploy_infrastructure.outputs.staticWebAppName }} -o tsv --query properties.apiKey) + echo SWA_DEPLOYMENT_TOKEN=$SWA_DEPLOYMENT_TOKEN >> $GITHUB_ENV + + - name: Deploy frontend to Static Web App + uses: azure/static-web-apps-deploy@v1 + with: + azure_static_web_apps_api_token: ${{ env.SWA_DEPLOYMENT_TOKEN }} + app_location: frontend/dist + action: upload + skip_app_build: true + skip_api_build: true diff --git a/frontend/index.html b/frontend/index.html index 0a5274f1..19171662 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -4,7 +4,7 @@ -