-
Notifications
You must be signed in to change notification settings - Fork 0
224 lines (195 loc) · 7.23 KB
/
ci_cd.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: GitHub CI
on:
pull_request:
push:
tags:
- "*"
branches:
- main
env:
MAIN_PYTHON_VERSION: '3.12'
DOCUMENTATION_CNAME: 'laughing-guide-5m1lvq6.pages.github.io'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
style:
name: Code style
runs-on: ubuntu-latest
steps:
- name: Install required tools
run : |
sudo apt install golang-golang-x-tools
sudo snap install golangci-lint --classic
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python for pre-commit hook
uses: actions/setup-python@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
- name: Run pre-commit hook
uses: pre-commit/[email protected]
build:
name: Build project
needs: [style]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Verify library builds
run: |
go build ./pkg/externalfunctions
doc-style:
name: "Documentation style"
runs-on: ubuntu-latest
steps:
- uses: ansys/actions/doc-style@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
doc-build:
name: "Build project documentation"
runs-on: ubuntu-latest
steps:
- name: "Build project documentation"
uses: ansys/actions/doc-build@v6
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
use-python-cache: false
skip-install: true
requirements-file: doc/requirements.txt
check-links: false
doc-api-reference:
name: "Build API reference documentation"
needs: [doc-build, doc-style]
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
- name: Build GoPages
run: |
go install github.com/johnstarich/go/gopages@latest
gopages -internal -source-link "https://github.com/ansys-internal/pyconv-externalfunctions/blob/main/{{.Path}}{{if .Line}}#L{{.Line}}{{end}}"
- name: Download HTML documentation artifacts
uses: actions/download-artifact@v4
with:
name: documentation-html
path: documentation-html
- name: Run Bash script
run: |
# Set environment variables for file paths
DOC_BUILD_HTML="documentation-html"
SOURCE_FILE="$DOC_BUILD_HTML/api_reference/test/index.html"
SOURCE_DIRECTORY="dist/pkg/github.com/ansys-internal/pyconv-externalfunctions/pkg/"
REPLACEMENT_DIRECTORY="$DOC_BUILD_HTML/api_reference/pkg"
ACTUAL_DIR="$DOC_BUILD_HTML/api_reference/"
# Check if REPLACEMENT_DIRECTORY exists, if not, create it
if [ ! -d "$REPLACEMENT_DIRECTORY" ]; then
mkdir -p "$REPLACEMENT_DIRECTORY"
fi
# Remove existing content in the replacement directory
rm -rf "$REPLACEMENT_DIRECTORY"/*
# Move the source_directory content to the replacement_directory
mv "$SOURCE_DIRECTORY"* "$REPLACEMENT_DIRECTORY"
# Remove the index.html file in the replacement_directory
rm "$REPLACEMENT_DIRECTORY/index.html"
# Process each HTML file in the replacement directory
find "$REPLACEMENT_DIRECTORY" -type f -name "*.html" | while IFS= read -r replacement_file; do
replacementBodyContent=$(sed -n '/<body>/,/<\/body>/p' "$replacement_file" | \
sed '/<div class="top-heading" id="heading-wide"><a href="\/pkg\/github.com\/ansys-internal\/pyconv-externalfunctions\/">GoPages | Auto-generated docs<\/a><\/div>/,/<a href="#" id="menu-button"><span id="menu-button-arrow">▽<\/span><\/a>/d' | \
sed 's/\//\\\//g')
# Use awk to replace content between specific HTML tags
awk -v repl="$replacementBodyContent" '
/<article class="bd-article" role="main">/,/<\/article>/ {
if ($0 ~ /<article class="bd-article" role="main">/) {
print $0
print repl
while ($0 !~ /<\/article>/) getline
next
}
}
{ print $0 }
' "$SOURCE_FILE" > "$replacement_file"
done
# Move the modified files back to the actual directory
mv "$REPLACEMENT_DIRECTORY"/* "$ACTUAL_DIR"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: documentation-html-with-api
path: documentation-html
release:
name: Generate GitHub release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [doc-api-reference, build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Release to GitHub
uses: softprops/action-gh-release@v2
with:
fail_on_unmatched_files: false
generate_release_notes: true
main-repo-release:
name: Update main pyconv repo and create release
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Checkout pyconv repository
run: |
git clone --branch main https://${{ secrets.PYCONV_RELEASE_TOKEN }}@github.com/ansys-internal/pyconv.git
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'pyconv/scripts/releasehelper/go.mod'
- name: Run tag script
run: |
cd pyconv/scripts/releasehelper
go run main.go "tag" ${{ github.ref_name }} ${{ secrets.PYCONV_RELEASE_TOKEN }}
- name: Commit and push to pyconv
run: |
cd pyconv
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
git config --global user.name '${{ github.actor }}'
git commit -a -m 'New release triggered by ${{ github.event.repository.name }}'
git push origin main
- name: Run release script
run: |
cd pyconv/scripts/releasehelper
go run main.go "release" ${{ github.ref_name }} ${{ secrets.PYCONV_RELEASE_TOKEN }}
upload_dev_docs:
name: Upload dev documentation
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: [doc-api-reference]
steps:
- name: Deploy the latest documentation
uses: ansys/actions/doc-deploy-dev@v6
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
doc-artifact-name: documentation-html-with-api
upload_docs_release:
name: Upload release documentation
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
runs-on: ubuntu-latest
needs: [release]
steps:
- name: Deploy the stable documentation
uses: ansys/actions/doc-deploy-stable@v6
with:
cname: ${{ env.DOCUMENTATION_CNAME }}
token: ${{ secrets.GITHUB_TOKEN }}
doc-artifact-name: documentation-html-with-api