-
Notifications
You must be signed in to change notification settings - Fork 273
143 lines (130 loc) · 6 KB
/
update-api-and-cfg-manual.yaml
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
name: Update API and config manual
concurrency:
group: update-api-cfg-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
on:
repository_dispatch:
types:
- release
workflow_dispatch:
inputs:
version:
type: string
required: true
description: 'EMQX version without v/e prefix'
repository:
type: choice
required: true
options:
- emqx/emqx
- emqx/emqx-platform
run_id:
type: string
required: true
description: 'The run id of the workflow that generates the schema dump'
docker_pull:
type: boolean
default: true
description: 'Pull official docker images'
permissions:
contents: read
jobs:
update-api-cfg-manual:
runs-on: ubuntu-latest
env:
EMQX_VERSION: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.version || github.event.inputs.version }}
REPOSITORY: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.repository || github.event.inputs.repository }}
RUN_ID: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.run-id || github.event.inputs.run_id }}
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: "emqx*-schema-dump"
repository: ${{ env.REPOSITORY }}
run-id: ${{ env.RUN_ID }}
github-token: ${{ secrets.PAT_RO_WORKFLOWS }}
merge-multiple: true
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
if: github.event.inputs.docker_pull == false
with:
name: "emqx-docker"
repository: ${{ env.REPOSITORY }}
run-id: ${{ env.RUN_ID }}
github-token: ${{ secrets.PAT_RO_WORKFLOWS }}
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
if: github.event.inputs.docker_pull == false
with:
name: "emqx-enterprise-docker"
repository: ${{ env.REPOSITORY }}
run-id: ${{ env.RUN_ID }}
github-token: ${{ secrets.PAT_RO_WORKFLOWS }}
- name: Create PR to update api docs and config manual
env:
GH_TOKEN: ${{ github.token }}
DOCKER_PULL: ${{ github.event.inputs.docker_pull }}
run: |
set -euxo pipefail
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
BASE_BRANCH="$(echo release-$(echo $EMQX_VERSION | cut -d '.' -f 1-2))"
NEW_BRANCH="update-api-cfg-${EMQX_VERSION}"
git fetch origin ${BASE_BRANCH}
git checkout -b ${NEW_BRANCH} --track origin/${BASE_BRANCH}
VERSION=$(echo "${EMQX_VERSION}" | cut -d '-' -f 1)
MINOR_VERSION=$(echo "${EMQX_VERSION}" | cut -d '.' -f 1-2)
sed -i "s/CE_VERSION=.*/CE_VERSION=${VERSION}/" ./current-version.env
sed -i "s/CE_MINOR_VERSION=.*/CE_MINOR_VERSION=${MINOR_VERSION}/" ./current-version.env
sed -i "s/EE_VERSION=.*/EE_VERSION=${VERSION}/" ./current-version.env
sed -i "s/EE_MINOR_VERSION=.*/EE_MINOR_VERSION=${MINOR_VERSION}/" ./current-version.env
git add current-version.env
if [ "${DOCKER_PULL}" = true ]; then
EMQX_TAG="emqx/emqx:${EMQX_VERSION}"
EMQX_ENTERPRISE_TAG="emqx/emqx-enterprise:${EMQX_VERSION}"
else
EMQX_TAG=$(docker load < emqx-docker-*.tar.gz | sed 's/Loaded image: //g')
EMQX_ENTERPRISE_TAG=$(docker load < emqx-enterprise-docker-*.tar.gz | sed 's/Loaded image: //g')
fi
EMQX_API_PORT=18083
for edition in ce ee; do
case "${edition}" in
ce)
PROFILE=emqx
DOCKER_IMAGE=${EMQX_TAG}
;;
ee)
PROFILE=emqx-enterprise
DOCKER_IMAGE=${EMQX_ENTERPRISE_TAG}
;;
esac
for lang in en zh; do
CID=$(docker run -d -p $EMQX_API_PORT:18083 -e EMQX_dashboard__i18n_lang=${lang} "${DOCKER_IMAGE}")
SWAGGER_INPUT="/tmp/swagger-${edition}-${lang}.json"
TARGET_FILE="redocly/${edition}-${lang}.json"
# it takes some time for swagger to fully load
sleep 30
curl -o "${SWAGGER_INPUT}" http://127.0.0.1:$EMQX_API_PORT/api-docs/swagger.json
jq --indent 2 'del(.paths[] | .[] | select(.deprecated == true))' > "${TARGET_FILE}" < "${SWAGGER_INPUT}"
# replace docker ip 172.17.0.* with 127.0.0.1
sed -i 's/172\.17\.0\.\([0-9]\{1,3\}\)/127.0.0.1/g' "${TARGET_FILE}"
docker logs $CID
docker rm -f $CID
git add "${TARGET_FILE}"
cp "_build/docgen/${PROFILE}/schema-v2-${lang}.json" "hocon/hocon-${edition}-v${VERSION}-${lang}.json"
git add "hocon/hocon-${edition}-v${VERSION}-${lang}.json"
EMQX_API_PORT=$((EMQX_API_PORT + 1))
done
done
git commit -m "chore($VERSION): update api and cfg manual"
git push origin ${NEW_BRANCH}:${NEW_BRANCH}
for pr in $(gh pr list --state open --base ${BASE_BRANCH} --label update-api-cfg --search "update api and cfg manual ${VERSION} in:title" --repo ${{ github.repository }} --json number --jq '.[] | .number'); do
gh pr close $pr --repo ${{ github.repository }} --delete-branch || true
done
gh pr create --title "update api and cfg manual ${VERSION}" --body '' --base ${BASE_BRANCH} --head ${NEW_BRANCH} --label update-api-cfg --repo ${{ github.repository }}
- uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4.3.5
with:
name: "swagger"
path: |
/tmp/swagger-*.json