-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (142 loc) · 5.11 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
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/allie-flowkit/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/allie-flowkit/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\/allie-flowkit\/">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
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