-
Notifications
You must be signed in to change notification settings - Fork 23
185 lines (159 loc) · 7 KB
/
build-and-stage.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: build-website
on:
pull_request:
branches:
- main
- v4
push:
branches:
- main
- v4
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: 'read'
pull-requests: 'write'
env:
DOCFX_VERSION: 2.59.4
DOCFX_SOURCE_BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
STEELTOE_V2_VERSION: 2.5.5
STEELTOE_V3_VERSION: 3.2.6
STEELTOE_V4_VERSION: main
SITE_IMAGE_VERSION: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.run_id }}
jobs:
change-detection:
name: Detect which layers need to be built, set image versions
runs-on: ubuntu-latest
# Set job outputs to values from filter step
outputs:
docfx-layer-changed: ${{ steps.filter.outputs.docfx-layer-changed }}
docfx-image-version: ${{ steps.version.outputs.docfx-image-version }}
metadata-layer-changed: ${{ steps.filter.outputs.metadata-layer-changed }}
metadata-image-version: ${{ steps.version.outputs.metadata-image-version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
docfx-layer-changed:
- .github/workflows/build-and-stage.yml
- 'docfx/**'
metadata-layer-changed:
- .github/workflows/build-and-stage.yml
- Dockerfile-metadata
- '/api-*.*'
- build-metadata.sh
- docfx.json
- name: Declare image versions
id: version
run: |
if '${{ steps.filter.outputs.docfx-layer-changed }}' == 'true'
then
echo "docfx-image-version=${{ github.event_name == 'pull_request' && github.run_id || env.DOCFX_VERSION }}" >> "$GITHUB_OUTPUT"
else
echo "docfx-image-version=${{ env.DOCFX_VERSION }}" >> "$GITHUB_OUTPUT"
fi
if '${{ steps.filter.outputs.metadata-layer-changed }}' == 'true'
then
echo "metadata-image-version=${{ github.event_name == 'pull_request' && github.run_id || env.STEELTOE_VERSIONS }}" >> "$GITHUB_OUTPUT"
else
echo "metadata-image-version=${{ env.STEELTOE_VERSIONS }}" >> "$GITHUB_OUTPUT"
fi
env:
STEELTOE_VERSIONS: ${{ env.STEELTOE_V2_VERSION }}-${{ env.STEELTOE_V3_VERSION }}-${{ env.STEELTOE_V4_VERSION }}
shell: bash
build-push-docfx:
name: Build and push docfx layer
needs: change-detection
if: ${{ needs.change-detection.outputs.docfx-layer-changed }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set DocFX version to use
run: echo v${{ env.DOCFX_VERSION }} > docfx/version
shell: bash
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Build image
run: docker build docfx --file "docfx/Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/docfx:${{ needs.change-detection.outputs.docfx-image-version }}
- name: Push image
run: docker push ${{ vars.DOCKER_REGISTRY }}/docfx --all-tags
build-push-metadata:
name: Build and push API docs layer
needs: [ change-detection, build-push-docfx ]
if: ${{ needs.change-detection.outputs.metadata-layer-changed }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Steeltoe versions to use
run: |-
echo '2:'${{ env.STEELTOE_V2_VERSION }} > metadata.conf
echo '3:'${{ env.STEELTOE_V3_VERSION }} >> metadata.conf
echo '4:'${{ env.STEELTOE_V4_VERSION }} >> metadata.conf
shell: bash
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Build image
run: docker build --build-arg="DOCFX_IMAGE_VERSION=${{ needs.change-detection.outputs.docfx-image-version }}" . --file "Dockerfile-metadata" -t ${{ vars.DOCKER_REGISTRY }}/documentation-metadata:${{ needs.change-detection.outputs.metadata-image-version }}
- name: Push image
run: docker push ${{ vars.DOCKER_REGISTRY }}/documentation-metadata --all-tags
build-push-deploy:
name: Build and push documentation image
needs: [ change-detection, build-push-docfx, build-push-metadata ]
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 }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Login to container registry
uses: azure/docker-login@v1
with:
login-server: "${{ vars.DOCKER_REGISTRY }}"
username: "${{ secrets.DOCKER_USERNAME }}"
password: "${{ secrets.DOCKER_PASSWORD }}"
- name: Build image
run: docker build --build-arg="METADATA_IMAGE_VERSION=${{ needs.change-detection.outputs.metadata-image-version }}" . --file "Dockerfile" -t ${{ vars.DOCKER_REGISTRY }}/documentation:${{ env.SITE_IMAGE_VERSION }}
- name: Push image
run: docker push ${{ vars.DOCKER_REGISTRY }}/documentation --all-tags
- 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 }} --configuration-source ${{ vars.STAGING_SLOT_NAME }}
# Need to pair a PR slot with a custom MainSite address?
# az webapp config appsettings set -g steeltoe --name docs-steeltoe --slot pr-310 --settings mainsite_host=https://www-steeltoe-pr-141.azurewebsites.net
- name: Deploy to staging slot
uses: azure/webapps-deploy@v3
id: deploy-to-webapp
with:
app-name: ${{ vars.AZURE_WEBAPP_NAME }}
images: ${{ vars.DOCKER_REGISTRY }}/documentation:${{ env.SITE_IMAGE_VERSION }}
slot-name: ${{ env.SLOT_NAME }}
- name: If PR, comment with the preview link
if: ${{ github.event_name == 'pull_request' }}
uses: mshick/add-pr-comment@v2
with:
message: |
## 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.
> *This is an automated message.*
repo-token: ${{ secrets.GITHUB_TOKEN }}