Skip to content

Commit a5131d2

Browse files
authored
Merge pull request #99 from SteeltoeOSS/workflows
Workflow updates
2 parents f3e5484 + f526312 commit a5131d2

File tree

6 files changed

+113
-19
lines changed

6 files changed

+113
-19
lines changed
Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
name: Build and stage
2+
23
on:
34
push:
45
branches:
56
- main
67
pull_request:
78
branches:
89
- main
9-
env:
10-
DOTNET_CLI_TELEMETRY_OPTOUT: 1
11-
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
12-
DOTNET_VERSION: '8.0'
1310

1411
concurrency:
1512
group: ${{ github.workflow }}-${{ github.ref }}
@@ -18,11 +15,17 @@ concurrency:
1815
permissions:
1916
checks: write
2017
contents: read
18+
pull-requests: write
2119
statuses: write
2220

2321
jobs:
2422
build:
2523
name: Build and publish app
24+
env:
25+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
26+
DOTNET_NOLOGO: true
27+
DOTNET_VERSION: '8.0'
28+
ASPNETCORE_ENVIRONMENT: Staging
2629
runs-on: ubuntu-latest
2730
steps:
2831
- uses: actions/checkout@v4
@@ -39,8 +42,7 @@ jobs:
3942
with:
4043
path: ~/.nuget/packages
4144
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
42-
restore-keys: |
43-
${{ runner.os }}-nuget-
45+
restore-keys: ${{ runner.os }}-nuget-
4446

4547
- name: dotnet restore
4648
run: dotnet restore
@@ -52,7 +54,7 @@ jobs:
5254
run: dotnet test --logger trx --results-directory "${{ runner.temp }}" --no-build
5355

5456
- name: dotnet test
55-
uses: NasAmin/trx-parser@v0.5.0
57+
uses: NasAmin/trx-parser@v0.6.0
5658
with:
5759
TRX_PATH: "${{ runner.temp }}"
5860
REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
@@ -61,34 +63,61 @@ jobs:
6163
run: dotnet publish src/InitializrService/Steeltoe.InitializrService.csproj -o publish
6264

6365
- name: Upload artifact for deployment job
64-
if: ${{ github.event_name != 'pull_request' }}
6566
uses: actions/upload-artifact@v4
6667
with:
6768
name: published-app
6869
path: publish
6970

7071
deploy:
7172
name: Deploy
72-
environment: Staging
73-
needs:
74-
- build
73+
if: ${{ github.secret_source == 'Actions' }}
74+
environment:
75+
name: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
76+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
77+
env:
78+
SLOT_NAME: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || vars.STAGING_SLOT_NAME }}
79+
needs: build
7580
runs-on: ubuntu-latest
76-
if: ${{ github.event_name != 'pull_request' }}
7781
steps:
7882
- name: Download artifact from build job
7983
uses: actions/download-artifact@v4
8084
with:
8185
name: published-app
8286

83-
- name: Log into Azure CLI with service principal
84-
uses: azure/login@v1
87+
- name: Login to Azure
88+
uses: azure/login@v2
8589
with:
8690
creds: ${{ secrets.AZURE_CREDENTIALS }}
8791

88-
- name: Deploy to Azure Web App
92+
- name: If PR, create a new staging slot
93+
if: ${{ github.event_name == 'pull_request' }}
94+
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 }}
95+
96+
- name: Deploy to staging slot
8997
id: deploy-to-webapp
98+
if: ${{ github.secret_source == 'Actions' }}
9099
uses: azure/webapps-deploy@v3
91100
with:
92101
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
93102
package: '.'
94103
slot-name: ${{ vars.STAGING_SLOT_NAME }}
104+
105+
- name: If PR, comment with the preview link
106+
if: ${{ github.event_name == 'pull_request' }}
107+
uses: mshick/add-pr-comment@v2
108+
with:
109+
message: |
110+
## Preview link: https://${{ vars.AZURE_WEBAPP_NAME }}-${{ env.SLOT_NAME }}.azurewebsites.net
111+
112+
- Your changes have been deployed to the preview site. The preview site will update as you add more commits to this branch.
113+
- The preview link is shareable, but will be deleted when the pull request is merged or closed.
114+
115+
### Need to pair with a custom NetCoreToolService address?
116+
117+
A team member can use this az CLI command, replacing <this-PR-number> and <other-pr-number> for valid numbers:
118+
```bash
119+
az webapp config appsettings set --resource-group steeltoe --name initializr-service --slot pr-<this-PR-number> --settings InitializrService__NetCoreToolService__Uri=https://netcoretoolservice-pr-<other-pr-number>.azurewebsites.net/api
120+
```
121+
122+
> *This is an automated message.*
123+
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr-cleanup.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Delete a preview environment
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
env:
9+
SLOT_NAME: pr-${{ github.event.number }}
10+
11+
jobs:
12+
delete-slot:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Log into Azure CLI with service principal
17+
uses: azure/login@v2
18+
with:
19+
creds: ${{ secrets.AZURE_CREDENTIALS }}
20+
21+
- name: Delete slot on staging site
22+
run: az webapp deployment slot delete --resource-group ${{ vars.AZURE_RESOURCE_GROUP }} --name ${{ vars.AZURE_WEBAPP_NAME}} --slot ${{ env.SLOT_NAME }}
23+
24+
delete-deployment:
25+
runs-on: ubuntu-latest
26+
permissions: write-all
27+
28+
steps:
29+
- name: Delete Deployment Environment
30+
uses: strumwolf/delete-deployment-environment@v3
31+
with:
32+
environment: "pr-${{ github.event.number }}"
33+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/stage-prod-swap.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,26 @@ jobs:
1313

1414
steps:
1515
- name: Log into Azure CLI with service principal
16-
uses: azure/login@v1
16+
uses: azure/login@v2
1717
with:
1818
creds: ${{ secrets.AZURE_CREDENTIALS }}
1919

20+
- name: Change NetCoreToolService link to prod and restart
21+
shell: bash
22+
run: |
23+
az webapp config appsettings set --resource-group steeltoe --name initializr-service --slot Staging --settings InitializrService__NetCoreToolService__Uri=https://netcoretoolservice.azurewebsites.net/api
24+
az webapp restart --resource-group steeltoe --name initializr-service --slot Staging
25+
echo "Waiting 60 seconds until beginning to curl to see if the site is back up"
26+
sleep 60
27+
until $(curl --output /dev/null --silent --head --fail https://initializr-service-staging.azurewebsites.net/actuator/info); do
28+
printf '.'
29+
sleep 5
30+
done
31+
2032
- name: Swap slots
21-
run: az webapp deployment slot swap -s ${{ vars.STAGING_SLOT_NAME }} -n ${{ vars.AZURE_WEBAPP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }}
33+
run: az webapp deployment slot swap -s ${{ vars.STAGING_SLOT_NAME }} -n ${{ vars.AZURE_WEBAPP_NAME }} -g ${{ vars.AZURE_RESOURCE_GROUP }}
34+
35+
- name: Change NetCoreToolService link to staging and restart
36+
run: |
37+
az webapp config appsettings set --resource-group steeltoe --name initializr-service --slot Staging --settings InitializrService__NetCoreToolService__Uri=https://netcoretoolservice-staging.azurewebsites.net/api
38+
az webapp restart --resource-group steeltoe --name initializr-service --slot Staging

Steeltoe.InitializrService.sln

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{51C72D02-A6C
3030
EndProject
3131
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3B483F2E-42EE-4DE5-84B6-92F0D09D94FD}"
3232
EndProject
33+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
34+
EndProject
35+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{689D1DAB-3FD4-49C3-8A46-5914ABCE77E5}"
36+
ProjectSection(SolutionItems) = preProject
37+
.github\workflows\build-and-stage.yml = .github\workflows\build-and-stage.yml
38+
.github\workflows\pr-cleanup.yml = .github\workflows\pr-cleanup.yml
39+
.github\workflows\stage-prod-swap.yml = .github\workflows\stage-prod-swap.yml
40+
EndProjectSection
41+
EndProject
3342
Global
3443
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3544
Debug|Any CPU = Debug|Any CPU
@@ -110,6 +119,7 @@ Global
110119
{EC08DC14-11D5-40D3-8908-BDB0D789F48D} = {3B483F2E-42EE-4DE5-84B6-92F0D09D94FD}
111120
{EA849C8F-7118-45DB-BBF2-D36CE1FD43B4} = {3B483F2E-42EE-4DE5-84B6-92F0D09D94FD}
112121
{24A2AB13-F4C4-4C88-B67D-D280610240B8} = {3B483F2E-42EE-4DE5-84B6-92F0D09D94FD}
122+
{689D1DAB-3FD4-49C3-8A46-5914ABCE77E5} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
113123
EndGlobalSection
114124
GlobalSection(ExtensibilityGlobals) = postSolution
115125
SolutionGuid = {F773FB5B-7619-4DA7-AA07-919DA1A5181C}

src/InitializrService/appsettings.Staging.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
"LogLevel": {
44
"Steeltoe.InitializrService": "Debug"
55
}
6+
},
7+
"InitializrService": {
8+
"NetCoreToolService": {
9+
"Uri": "https://netcoretoolservice-staging.azurewebsites.net/api"
10+
}
611
}
712
}

src/InitializrService/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"InitializrService": {
33
"NetCoreToolService": {
4-
"Uri": "http://net-core-tool-service/api"
4+
"Uri": "https://netcoretoolservice.azurewebsites.net/api"
55
},
66
"Logo": "Resources/logo.txt",
77
"Examples": "Resources/examples.txt"
@@ -12,7 +12,7 @@
1212
},
1313
"Cloud": {
1414
"Config": {
15-
"Uri": "http://initializr-config-server/",
15+
"Uri": "https://initializr-config.azurewebsites.net/",
1616
"Label": "main"
1717
}
1818
}

0 commit comments

Comments
 (0)