From 14efd1526597256da3159625fba4460b9470a130 Mon Sep 17 00:00:00 2001 From: Tim Hess Date: Fri, 28 Feb 2025 17:55:25 -0600 Subject: [PATCH 1/3] separate build and deploy, delete GH environments after PR closes also update actions and align styles, --- .github/workflows/build-and-stage.yml | 43 ++++++++++++++------------- .github/workflows/pr-cleanup.yml | 11 +++---- .github/workflows/stage-prod-swap.yml | 4 +-- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build-and-stage.yml b/.github/workflows/build-and-stage.yml index decff1c..f126e03 100644 --- a/.github/workflows/build-and-stage.yml +++ b/.github/workflows/build-and-stage.yml @@ -1,12 +1,9 @@ name: Build and stage -env: - AZURE_WEBAPP_PACKAGE_PATH: '.' - DOTNET_VERSION: '8.0' - on: push: - branches: [ "main" ] + branches: + - main pull_request: branches: - main @@ -17,7 +14,13 @@ concurrency: permissions: contents: read - pull-requests: 'write' + pull-requests: write + +env: + AZURE_WEBAPP_PACKAGE_PATH: '.' + DOTNET_CLI_TELEMETRY_OPTOUT: 1 + DOTNET_NOLOGO: true + DOTNET_VERSION: '8.0' jobs: build: @@ -36,14 +39,13 @@ jobs: with: path: ~/.nuget/packages key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - restore-keys: | - ${{ runner.os }}-nuget- + restore-keys: ${{ runner.os }}-nuget- - name: dotnet build run: dotnet build src/Client --configuration Release - name: dotnet publish - run: dotnet publish src/Client -c Release -o ${{ env.DOTNET_ROOT }}/mainsite + run: dotnet publish src/Client --configuration Release --no-build --output ${{ env.DOTNET_ROOT }}/mainsite - name: Upload artifact for deployment job uses: actions/upload-artifact@v4 @@ -51,31 +53,32 @@ jobs: name: Steeltoe-MainSite path: ${{ env.DOTNET_ROOT }}/mainsite - deploy-to-staging: - name: Deploy to staging environment - runs-on: ubuntu-latest - needs: build + deploy: + name: Deploy + if: ${{ github.secret_source == 'Actions' }} environment: name: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }} url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} env: SLOT_NAME: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }} - + needs: build + runs-on: ubuntu-latest steps: - name: Download artifact from build job uses: actions/download-artifact@v4 with: name: Steeltoe-MainSite - - name: Log into Azure CLI with service principal - uses: azure/login@v1 + - name: Login to Azure + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: If PR, create a new staging slot if: ${{ github.event_name == 'pull_request' }} - run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} - # Need to pair a PR slot with a custom docs site address? + run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source ${{ vars.STAGING_SLOT_NAME }} + + # Need to pair with a custom docs site address? # az webapp config appsettings set -g steeltoe --name www-steeltoe --slot pr-141 --settings DocsSite__BaseAddress=https://docs-steeltoe-pr-310.azurewebsites.net - name: Deploy to Azure Web App @@ -91,8 +94,8 @@ jobs: uses: mshick/add-pr-comment@v2 with: message: | - ## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net - + ## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net + - Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch. - The preview link is shareable, but will be deleted when the pull request is merged or closed. diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml index 1575264..a086df1 100644 --- a/.github/workflows/pr-cleanup.yml +++ b/.github/workflows/pr-cleanup.yml @@ -2,7 +2,8 @@ name: Delete a preview environment on: pull_request: - types: [closed] + types: + - closed concurrency: group: ci-${{ github.event.number }} @@ -14,10 +15,11 @@ env: jobs: delete-slot: runs-on: ubuntu-latest + permissions: write-all steps: - name: Log into Azure CLI with service principal - uses: azure/login@v1 + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} @@ -29,8 +31,7 @@ jobs: steps: - name: Delete Deployment Environment - uses: strumwolf/delete-deployment-environment@v2 + uses: strumwolf/delete-deployment-environment@v3 with: - environment: "PR #${{ github.event.number }}" + environment: "pr-${{ github.event.number }}" token: ${{ secrets.GITHUB_TOKEN }} - onlyRemoveDeployments: true diff --git a/.github/workflows/stage-prod-swap.yml b/.github/workflows/stage-prod-swap.yml index 2bff404..7674e2b 100644 --- a/.github/workflows/stage-prod-swap.yml +++ b/.github/workflows/stage-prod-swap.yml @@ -8,12 +8,12 @@ jobs: name: Promote to production runs-on: ubuntu-latest environment: - name: 'Production' + name: Production url: 'https://${{ vars.AZURE_WEBAPP_NAME }}.azurewebsites.net/' steps: - name: Log into Azure CLI with service principal - uses: azure/login@v1 + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} From 4d88563f22b37be6b45ea385b4d34c5d602eb811 Mon Sep 17 00:00:00 2001 From: Tim Hess Date: Fri, 28 Feb 2025 18:23:09 -0600 Subject: [PATCH 2/3] add site-link command to preview comment, remove broken nuget cache step --- .github/workflows/build-and-stage.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-and-stage.yml b/.github/workflows/build-and-stage.yml index f126e03..2194752 100644 --- a/.github/workflows/build-and-stage.yml +++ b/.github/workflows/build-and-stage.yml @@ -34,13 +34,6 @@ jobs: with: dotnet-version: ${{ env.DOTNET_VERSION }} - - name: Set up dependency caching for faster builds - uses: actions/cache@v4 - with: - path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - restore-keys: ${{ runner.os }}-nuget- - - name: dotnet build run: dotnet build src/Client --configuration Release @@ -78,9 +71,6 @@ jobs: if: ${{ github.event_name == 'pull_request' }} run: az webapp deployment slot create --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }} --configuration-source ${{ vars.STAGING_SLOT_NAME }} - # Need to pair with a custom docs site address? - # az webapp config appsettings set -g steeltoe --name www-steeltoe --slot pr-141 --settings DocsSite__BaseAddress=https://docs-steeltoe-pr-310.azurewebsites.net - - name: Deploy to Azure Web App id: deploy-to-webapp uses: azure/webapps-deploy@v3 @@ -99,5 +89,12 @@ jobs: - Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch. - The preview link is shareable, but will be deleted when the pull request is merged or closed. + ### Need to pair with a custom docs site address? + + A team member can use this az CLI command, replacing and for valid numbers: + ```bash + az webapp config appsettings set --resource-group steeltoe --name www-steeltoe --slot pr- --settings DocsSite__BaseAddress=https://docs-steeltoe-pr-.azurewebsites.net + ``` + > *This is an automated message.* repo-token: ${{ secrets.GITHUB_TOKEN }} From 20d1b0ef8f4b971a4b364283beff2c66b6f39080 Mon Sep 17 00:00:00 2001 From: Tim Hess Date: Mon, 3 Mar 2025 11:15:10 -0600 Subject: [PATCH 3/3] revert changes to gh env cleanup --- .github/workflows/pr-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml index a086df1..71e1163 100644 --- a/.github/workflows/pr-cleanup.yml +++ b/.github/workflows/pr-cleanup.yml @@ -15,7 +15,6 @@ env: jobs: delete-slot: runs-on: ubuntu-latest - permissions: write-all steps: - name: Log into Azure CLI with service principal @@ -35,3 +34,4 @@ jobs: with: environment: "pr-${{ github.event.number }}" token: ${{ secrets.GITHUB_TOKEN }} + onlyRemoveDeployments: true