Skip to content

Update API and config manual #52

Update API and config manual

Update API and config manual #52

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