Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflow updates #159

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions .github/workflows/build-and-stage.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -31,52 +34,42 @@ 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
with:
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
Expand All @@ -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 <this-PR-number> and <other-pr-number> for valid numbers:
```bash
az webapp config appsettings set --resource-group steeltoe --name www-steeltoe --slot pr-<this-PR-number> --settings DocsSite__BaseAddress=https://docs-steeltoe-pr-<other-pr-number>.azurewebsites.net
```

> *This is an automated message.*
repo-token: ${{ secrets.GITHUB_TOKEN }}
9 changes: 5 additions & 4 deletions .github/workflows/pr-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Delete a preview environment

on:
pull_request:
types: [closed]
types:
- closed

concurrency:
group: ci-${{ github.event.number }}
Expand All @@ -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 }}

Expand All @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/stage-prod-swap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down