-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (151 loc) · 5.14 KB
/
ci-workflow.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
name: CI Workflow
run-name: ${{ format('{0} triggered {1} on {2}', (github.event_name == 'workflow_dispatch' && format('User {0}', github.actor) || format('{0} event', github.event_name) ), github.workflow, github.ref) }}
on:
schedule:
- cron: '0 4 * * 1'
pull_request:
push:
branches:
- 'main'
workflow_run:
workflows: [Release Workflow]
types:
- completed
workflow_dispatch:
inputs:
forceDocsUpload:
description: 'Force API docs upload'
default: false
type: boolean
jobs:
CI:
name: CI
runs-on: ubuntu-22.04
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Lint Markdown docs
run: make lint-markdown
- name: Lint specification
run: make lint-apispec
configure_build:
name: Configure Build
runs-on: ubuntu-22.04
outputs:
branches_list: ${{ steps.generate-matrix.outputs.branches_list }}
shouldUpload: ${{ steps.shouldUpload.outputs.upload }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # check out the entire repo history for SHA verification in lastSuccessful step
- name: Identify latest successful run
id: lastSuccessful
uses: SamhammerAG/last-successful-build-action@1c368a27a90596574a71ac0ede422a897d0e8e84 # @v4
with:
branch: ${{ github.ref_name }}
workflow: ${{ github.workflow }}
verify: true
- name: Determine if this workflow should upload artefacts
id: shouldUpload
shell: bash
run: |
if [ "${{ steps.lastSuccessful.outputs.sha }}" != "${{ github.sha }}" ] && [ "${{ github.ref_name }}" == "main" ] || [[ ${{ github.ref_name }} == refs/tags/* ]]
then
echo "upload=true" >> $GITHUB_OUTPUT;
else
echo "upload=false" >> $GITHUB_OUTPUT;
fi
- name: Get Tags
id: get_tags
uses: octokit/[email protected]
if: ${{ inputs.forceDocsUpload || ( steps.shouldUpload.outputs.upload == 'true' ) }}
with:
route: GET /repos/${{ github.repository }}/git/matching-refs/tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Matrix
id: generate-matrix
run: |
if [ "${{ steps.shouldUpload.outputs.upload }}" == "true" ] || [ "${{ inputs.forceDocsUpload }}" == "true" ]
then
branches_list=$(echo '${{ steps.get_tags.outputs.data }}' | jq -cr '[.[].ref] | . += ["main"]' )
echo "branches_list=${branches_list}" >> $GITHUB_OUTPUT
else
echo "branches_list=[\"${{ github.ref }}\"]" >> $GITHUB_OUTPUT
fi
build:
name: Build
runs-on: ubuntu-22.04
needs:
- CI
- configure_build
strategy:
matrix:
branch: ${{ fromJSON(needs.configure_build.outputs.branches_list) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: Render API docs
run: make render
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: ${{ inputs.forceDocsUpload || ( needs.configure_build.outputs.shouldUpload == 'true' ) }}
with:
name: ${{ strategy.job-index }}
path: './api/docs'
retention-days: 1
DeployPages:
name: Deploy Pages
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
runs-on: ubuntu-22.04
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs:
- configure_build
- build
if: ${{ inputs.forceDocsUpload || ( needs.configure_build.outputs.shouldUpload == 'true' ) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Download artifacts
run: gh run download ${{ vars.GITHUB_RUN_ID }} --dir branches
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create public folder
run: |
mkdir public
cd public
echo "<html><body><h1>TAMS Documentation</h1><p>" >> ./index.html
branches=$(echo '${{ needs.configure_build.outputs.branches_list }}' | jq -r '.[]')
i=0
for branch in ${branches}
do
short_branch=$(basename ${branch})
mkdir -p -- $short_branch
mv ../branches/$i/* ./$short_branch
echo "<li><a href=\"./${short_branch}/index.html\">${short_branch}</a></li>" >> index.html
i=$((i+1))
done
echo "</p></body></html>" >> index.html
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public/
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- name: Adding summary
run: |
echo "Documentation URL: ${{ steps.deployment.outputs.page_url }}" >> $GITHUB_STEP_SUMMARY