-
Notifications
You must be signed in to change notification settings - Fork 3
185 lines (161 loc) · 5.74 KB
/
deploy.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
on: workflow_call
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Get head tag, if it is new and others vars
run: |
tag=v$(sed -n 's/^__version__ = "\(.*\)"/\1/p' adi_doctools/__init__.py)
echo "tag=$tag" >> "$GITHUB_ENV"
git fetch --tags
if ! [ $(git tag -l "$tag") ] ; then
echo "new_tag=1" >> "$GITHUB_ENV"
fi
asset_name=adi-doctools.tar.gz
echo "asset_name=$asset_name" >> "$GITHUB_ENV"
full_asset_name=$(ls dist/adi_doctools-*.tar.gz)
echo "full_asset_name=$full_asset_name" >> "$GITHUB_ENV"
- name: Get pre-release vars
run: |
source ci/github-api.sh
release_id=$(
gh-get-release-id ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
pre-release \
pre_release_id
)
asset_id=$(
gh-get-asset-id ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$release_id \
pre_release_asset_id
)
- name: Get latest vars
if: ${{ env.new_tag == '1' }}
run: |
source ci/github-api.sh
release_id=$(
gh-get-release-id ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
latest \
latest_id
)
asset_id=$(
gh-get-asset-id ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$release_id \
latest_asset_id
)
- name: Create new tag
if: ${{ env.new_tag == '1' }}
run: |
git tag $tag
git push origin $tag
- name: Create tag release and upload asset
if: ${{ env.new_tag == '1' }}
run: |
source ci/github-api.sh
release_id=$(
gh-create-release ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$tag \
new_tag_release_id
)
gh-upload-asset ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$release_id \
$asset_name \
$full_asset_name
- name: Update pre-release target commitish
run: |
source ci/github-api.sh
gh-update-commitish ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
${{ github.sha }} \
$pre_release_id
- name: Upload pre-release asset
run: |
source ci/github-api.sh
if [[ ! "$pre_release_asset_id" == "" ]]; then
gh-delete-asset ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$pre_release_asset_id
fi
gh-upload-asset ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$pre_release_id \
$asset_name \
$full_asset_name
- name: Update latest target commitish
if: ${{ env.new_tag == '1' }}
run: |
source ci/github-api.sh
gh-update-commitish ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
${{ github.sha }} \
$latest_id
- name: Upload latest asset
if: ${{ env.new_tag == '1' }}
run: |
source ci/github-api.sh
if [[ ! "$latest_asset_id" == "" ]]; then
gh-delete-asset ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$latest_asset_id
fi
gh-upload-asset ${{ secrets.GITHUB_TOKEN }} \
${{ github.repository }} \
$latest_id \
$asset_name \
$full_asset_name
- run: |
git config --global user.name "${{ github.event.head_commit.committer.name }}"
git config --global user.email "${{ github.event.head_commit.committer.email }}"
- name: Prepare gh-pages branch
run: >
git reset --hard ;
git clean -fdx ;
git ls-remote --exit-code --heads origin refs/heads/gh-pages &&
(
git fetch origin gh-pages ;
git checkout -b gh-pages origin/gh-pages ;
DOC_BUILDS=$(find . -mindepth 2 -name objects.inv -exec sh -c 'dirname {}' ';') ;
git rm -r . --quiet || true ;
printf "Detected doc builds: $DOC_BUILDS" ;
if ! [ -z "$DOC_BUILDS" ]; then
git checkout @ -- $DOC_BUILDS ;
fi ;
if [[ "$new_tag" == "1" ]]; then
git rm -r $tag --quiet || true ;
fi ;
) || (
git checkout --orphan gh-pages ;
git reset --hard ;
git commit -m "initial commit" --allow-empty
)
- uses: actions/download-artifact@v4
with:
name: html
- uses: actions/download-artifact@v4
if: ${{ env.new_tag == '1' }}
with:
name: html-tagged
path: ${{ env.tag }}
- name: Generate aux files
run: >
touch .nojekyll ;
find . -name objects.inv -exec sh -c 'dirname {}' ';' |
cut -c 3- |
jq --raw-input . |
jq --slurp . |
sort > tags.json
- name: Commit and push to gh-pages
run: |
git add . >> /dev/null
git commit -m "deploy: ${GITHUB_SHA}" --allow-empty
git push origin gh-pages:gh-pages