diff --git a/.github/workflows/build-and-stage.yml b/.github/workflows/build-and-stage.yml index decff1c..2194752 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: @@ -31,19 +34,11 @@ 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 - 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,32 +46,30 @@ 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? - # az webapp config appsettings set -g steeltoe --name www-steeltoe --slot pr-141 --settings DocsSite__BaseAddress=https://docs-steeltoe-pr-310.azurewebsites.net + 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 }} - name: Deploy to Azure Web App id: deploy-to-webapp @@ -91,10 +84,17 @@ 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. + ### 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 }} diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml index 1575264..71e1163 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 }} @@ -17,7 +18,7 @@ jobs: steps: - name: Log into Azure CLI with service principal - uses: azure/login@v1 + uses: azure/login@v2 with: creds: ${{ secrets.AZURE_CREDENTIALS }} @@ -29,8 +30,8 @@ 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 }}