-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (167 loc) · 6.46 KB
/
deploy_public.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
name: Deploy Public
env:
REPO_NAME: fourinsight-campaigns-python
REPO_NAME_SHORT: campaigns
SRC_ROOT_PATH: "./fourinsight/campaigns"
on:
workflow_dispatch:
inputs:
version_number:
description: Release version number [MAJOR.MINOR.PATCH] to deploy. Use "$latest" to automatically choose the latest release.
required: true
type: string
default: "$latest"
pipeline:
description: Choose deploy pipeline.
required: true
default: production
type: choice
options:
- production
- test
doc_latest:
description: Deploy documentation as latest?
default: true
required: true
type: boolean
jobs:
build:
runs-on: ubuntu-latest
outputs:
version_number: ${{ steps.version_number.outputs.VERSION_NUMBER }}
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build sphinx==5.3.0 pydata_sphinx_theme==0.11.0 myst_parser
- name: Get new version number from input
id: version_number
run: |
if [ "${{ inputs.version_number }}" = "$latest" ]
then
version="$(gh release view --json tagName --jq .tagName)"
version=${version#v}
else
version="${{ inputs.version_number }}"
fi
echo "VERSION_NUMBER=$version" | tee $GITHUB_ENV $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Replace package version number
run: |
filename="$SRC_ROOT_PATH/__init__.py"
search_pattern="__version__ = \"0.0.1\""
replacement_text="__version__ = \"$VERSION_NUMBER\""
sed -i "s/$search_pattern/$replacement_text/" "$filename"
- name : Inject release notes to documentation
run: |
echo $VERSION_NUMBER
n_tag=25
i=0
# Note: may have to use paging if the number of releases gets very high
for tag in $(gh api "/repos/{owner}/{repo}/releases" --paginate -q .[].tag_name)
do
if [[ "$tag" == "v$VERSION_NUMBER" ]];
then
inject=True
fi
if [[ "$inject" == "True" ]] && [[ $i -le $n_tag ]];
then
i=$((i+1))
echo -e "$(gh release view $tag --json name --template '{{.name}}\n------------------------------')" >> docs/release_notes.md
echo -e "$(gh release view $tag --json body --template '{{.body}}\n')" | sed 's/<!-[^~]*->//g' | sed G >> docs/release_notes.md
fi
done
echo -e "*Note: this list includes only the most recent releases. For full release history, see www.github.com/$REPO_NAME/releases" >> docs/release_notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
run: python -m build --sdist --wheel --outdir ./dist
- name: Build documentation
run: |
pip install .
sphinx-build -b html ./docs ./build/html
- name: Stash build artifacts
uses: actions/upload-artifact@v4
with:
name: build_artifacts
path: |
./dist/*.whl
./build/html
retention-days: 1
deploy-test:
if: ${{ inputs.pipeline == 'test' }}
runs-on: ubuntu-latest
needs: build
env:
VERSION_NUMBER: ${{ needs.build.outputs.version_number }}
steps:
- name: Clean up artifacts directory
shell: pwsh
run: Get-ChildItem . | Remove-Item -Recurse -Force
- name: Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: build_artifacts
- name: Publish package to TestPyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TEST_API_KEY }}
repository_url: https://test.pypi.org/legacy/
- name: Upload documentation to TEST blob storage
uses: azure/CLI@v1
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTTEST_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/$VERSION_NUMBER"
- name: Upload documentation to TEST blob storage as latest
if: ${{ inputs.doc_latest }}
uses: azure/CLI@v1
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTTEST_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob delete-batch -s "\$web" --pattern "$REPO_NAME_SHORT/python/docs/latest/*"
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/latest"
deploy-prod:
if: ${{ inputs.pipeline == 'production' }}
runs-on: ubuntu-latest
needs: build
env:
VERSION_NUMBER: ${{ needs.build.outputs.version_number }}
steps:
- name: Clean up artifacts directory
shell: pwsh
run: Get-ChildItem . | Remove-Item -Recurse -Force
- name: Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: build_artifacts
- name: Publish package to PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PROD_API_KEY }}
- name: Upload documentation to PROD blob storage
uses: azure/CLI@v1
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTPROD_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/$VERSION_NUMBER"
- name: Upload documentation to PROD blob storage as latest
if: ${{ inputs.doc_latest }}
uses: azure/CLI@v1
env:
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.FOURINSIGHTPROD_DOC_BLOB_CONNSTR }}
with:
inlineScript: |
az storage blob delete-batch -s "\$web" --pattern "$REPO_NAME_SHORT/python/docs/latest/*"
az storage blob upload-batch -d "\$web" -s ./build/html --destination-path "$REPO_NAME_SHORT/python/docs/latest"