Fix update swagger json (#150)

I can not understand the old logic:
- download the web page (not the raw data) from GitHub
- replace `AppVer`
- remove the file???

It does nothing.

The correct logic:
- download the raw file from GitHub
- replace `AppVer` and `AppSubUrl`
- move the file to the correct place

As the script is not correct for a long time, added the support for all version since 1.19.

Fix #142

Reviewed-on: https://gitea.com/gitea/docs/pulls/150
Reviewed-by: Lunny Xiao <lunny@noreply.gitea.com>
Co-authored-by: yp05327 <576951401@qq.com>
Co-committed-by: yp05327 <576951401@qq.com>
This commit is contained in:
yp05327
2025-01-14 03:00:44 +00:00
committed by Lunny Xiao
parent 301154989a
commit 192a773da3

View File

@@ -11,13 +11,21 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: |
wget https://github.com/go-gitea/gitea/blob/main/templates/swagger/v1_json.tmpl
sed -i "$@" 's/"version": "{{AppVer | JSEscape}}"/"version": "dev"/' static/swagger-latest.json
rm v1_json.tmpl
wget https://raw.githubusercontent.com/go-gitea/gitea/refs/heads/main/templates/swagger/v1_json.tmpl
sed -i "$@" 's\"version": "{{AppVer | JSEscape}}"\"version": "dev"\' v1_json.tmpl
sed -i "$@" 's\"basePath": "{{AppSubUrl | JSEscape}}/api/v1"\"basePath": "https://gitea.com/api/v1"\' v1_json.tmpl
mv v1_json.tmpl static/swagger-latest.json
wget https://github.com/go-gitea/gitea/blob/v1.23.0/templates/swagger/v1_json.tmpl
sed -i "$@" 's/"version": "{{AppVer | JSEscape}}"/"version": "1.23.1"/' static/swagger-23.json
rm v1_json.tmpl
for ver in '1.23.1' '1.22.6' '1.21.11' '1.20.6' '1.19.4'; do
wget https://raw.githubusercontent.com/go-gitea/gitea/refs/tags/v${ver}/templates/swagger/v1_json.tmpl
sed -i "$@" "s|\"version\": \"{{AppVer \| JSEscape}}\"|\"version\": \"${ver}\"|" v1_json.tmpl
sed -i "$@" 's\"basePath": "{{AppSubUrl | JSEscape}}/api/v1"\"basePath": "https://gitea.com/api/v1"\' v1_json.tmpl
# for version < 1.21.11
sed -i "$@" "s|\"version\": \"{{AppVer \| JSEscape \| Safe}}\"|\"version\": \"${ver}\"|" v1_json.tmpl
sed -i "$@" 's\"basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1"\"basePath": "https://gitea.com/api/v1"\' v1_json.tmpl
minor=$(echo "$ver" | cut -d '.' -f 2)
mv v1_json.tmpl static/swagger-$minor.json
done
if ! [[ $(git diff --shortstat) ]]; then exit 0; fi
git config --global user.name "Gitea Bot"