Skip to content

Deploy Docs

Deploy Docs #246

Workflow file for this run

name: Deploy Docs
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
on:
push:
tags:
- v*
workflow_dispatch:
jobs:
check-docs:
uses: ./.github/workflows/check_docs.yaml
secrets: inherit
deploy:
runs-on: ubuntu-20.04
if: github.repository_owner == 'datalayers-io'
needs: check-docs
strategy:
matrix:
docs_language: [zh, en]
steps:
- name: clone docs
uses: actions/checkout@main
with:
fetch-depth: 0
path: docs-files
- name: clone frontend
uses: actions/checkout@main
with:
repository: "datalayers-io/docs-datalayers-frontend"
token: ${{ secrets.DATALAYERS_GIT_CI_TOKEN }}
path: frontend
- name: use python
uses: actions/setup-python@v4
with:
python-version: 3.8
- name: use node.js
uses: actions/setup-node@v3
with:
node-version-file: "frontend/.nvmrc"
- name: use pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: set env
run: |
BRANCH=$(echo ${{ github.ref }} | sed -r "s ^refs/heads/|^refs/tags/(.*) \1 g")
if [ "$BRANCH" = "main" ];then
VERSION="latest"
else
VERSION=$BRANCH
# make short version as directory name
VERSION=$(echo $BRANCH | awk -F. '{print $1"."$2}')
fi
# save the full version string, do not change this name
REAL_VERSION=$VERSION
# do not remove DOCS_BRANCH
echo "DOCS_BRANCH=$BRANCH" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "DOCS_TYPE=datalayers" >> $GITHUB_ENV
echo "LANGUAGES=${{ matrix.docs_language }}" >> $GITHUB_ENV
echo "REAL_VERSION=$REAL_VERSION" >> $GITHUB_ENV
- name: remove unused files
run: |
cd docs-files
pip3 install pyyaml
python3 ./gen.py | tee directory.json
python3 .github/scripts/remove_unused.py directory.json $(pwd)
- name: move files
run: |
mkdir -p frontend/docs/${DOCS_TYPE}/${VERSION}/
mkdir -p frontend/docs/public/api/
cp frontend/docs/${LANGUAGES}/index.md frontend/docs/
if [ "${LANGUAGES}" = "en" ]; then
cp -r docs-files/en_US/* frontend/docs/${DOCS_TYPE}/${VERSION}/
else
cp -r docs-files/zh_CN/* frontend/docs/${DOCS_TYPE}/${VERSION}/
fi
cp docs-files/directory.json frontend/docs/.vitepress/config/directory.json
rm -r frontend/docs/en || true
rm -r frontend/docs/zh || true
- name: generate version config
run: |
cd docs-files
# make short tag list
tags=$(git tag)
unique_tags=()
for tag in $tags; do
major_minor=$(echo $tag | awk -F. '{print $1"."$2}')
found=0
for utag in "${unique_tags[@]}"; do
if [ "$utag" == "$major_minor" ]; then
found=1
break
fi
done
if [ $found -eq 0 ]; then
unique_tags+=("$major_minor")
fi
done
# Remove duplicates by converting the array to a set and then back to an array
unique_tags=( $(printf "%s\n" "${unique_tags[@]}" | sort -u) )
echo "${unique_tags[@]}"
python3 .github/scripts/generate_version.py "${unique_tags[@]}" > ../frontend/docs/public/api/${DOCS_TYPE}_versions.json
cat ../frontend/docs/public/api/${DOCS_TYPE}_versions.json
- name: Fetch Datalayers tags then write to the .env file
env:
TOKEN: ${{ secrets.DATALAYERS_GIT_CI_TOKEN }}
run: |
cd frontend
touch .env
REPO_OWNER="datalayers-io"
REPO_NAME="datalayers"
RESPONSE=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/tags)
echo "API Response: $RESPONSE"
TAGS=$(echo "$RESPONSE" | jq -r '.[].name')
echo "Fetched tags: $TAGS"
FILTERED_TAGS=$(echo "$TAGS" | grep -Ev 'v2\.1\.(9|8|7|6)')
echo "Filtered tags: $FILTERED_TAGS"
echo "VITE_DATALAYERS_FILTERED_TAGS=$(echo $FILTERED_TAGS | tr '\n' ' ')" >> .env
- name: build docs
run: |
cd frontend
pnpm install
pnpm build
- name: upload dist to oss
run: |
cd frontend/docs/.vitepress/
wget -q https://gosspublic.alicdn.com/ossutil/1.7.8/ossutil64
chmod 755 ./ossutil64
if [ "${LANGUAGES}" = "en" ]; then
./ossutil64 config -e https://oss-us-east-1.aliyuncs.com -i ${{ secrets.ALI_OSS_ACCESSKEY_ID }} -k ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }} -L CH
else
./ossutil64 config -e https://oss-cn-shanghai.aliyuncs.com -i ${{ secrets.ALI_OSS_ACCESSKEY_ID }} -k ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }} -L CH
fi
oss_bucket=datalayers-docs-${LANGUAGES}
./ossutil64 cp -r -f dist/ oss://${oss_bucket}/
- name: refresh zh cdn
if: matrix.docs_language == 'zh'
uses: Swilder-M/refresh-huawei-cdn@master
with:
access_key_id: ${{ secrets.HUAWEI_ACCESS_KEY_ID }}
access_key_secret: ${{ secrets.HUAWEI_ACCESS_KEY_SECRET }}
file_paths: https://docs.datalayers.cn/
- name: refresh en cdn
if: matrix.docs_language == 'en'
uses: Swilder-M/refresh-ali-cdn@master
with:
access_key_id: ${{ secrets.ALI_OSS_ACCESSKEY_ID }}
access_key_secret: ${{ secrets.ALI_OSS_ACCESSKEY_SECRET }}
file_paths: https://docs.datalayers.io/
- name: update search index
if: matrix.docs_language == 'zh'
uses: Swilder-M/docsearch-scraper-simple@next
env:
APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}
API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
with:
docs_type: datalayers-docs-${{ matrix.docs_language }}
docs_version: ${{ env.VERSION }}