Call Release Doc #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Call Release Doc | |
on: | |
workflow_call: | |
inputs: | |
ref: | |
required: true | |
type: string | |
# --- call by manual | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: 'branch, tag, sha' | |
required: true | |
default: main | |
permissions: write-all | |
env: | |
MERGE_BRANCH: github_pages | |
DEV_DOC_DIRECTORY: dev | |
PR_LABEL: pr/release/robot_update_githubpage | |
PR_REVIWER: ty-dc | |
jobs: | |
release_doc: | |
runs-on: ubuntu-latest | |
outputs: | |
ref: ${{ env.REF }} | |
publish_docs_to_dev: ${{ env.PUBLISH_DOCS_TO_DEV }} | |
doc_tag: ${{ env.DOCS_TAG }} | |
steps: | |
- name: Get Ref | |
id: get_ref | |
run: | | |
pwd | |
ls | |
if ${{ github.event_name == 'workflow_dispatch' }}; then | |
echo "call by workflow_dispatch" | |
echo "REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV | |
elif ${{ inputs.ref != '' }}; then | |
echo "call by workflow_call" | |
echo "REF=${{ inputs.ref }}" >> $GITHUB_ENV | |
else | |
echo "unexpected event: ${{ github.event_name }}" | |
exit 1 | |
fi | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ env.REF }} | |
- name: Set main branch docs to dev (latest) | |
id: main_docs | |
if: ${{ env.REF == 'main' }} | |
run: | | |
echo "DOCS_TAG=${{ env.REF }}" >> $GITHUB_ENV | |
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==8.5.11 | |
git config user.email "[email protected]" | |
git config user.name "robot" | |
cp ./docs/mkdocs.yml ./ | |
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DEV_DOC_DIRECTORY }} -t "${{ env.DEV_DOC_DIRECTORY }} (${{ env.REF }})" | |
rm -rf ./site && rm -rf ./mkdocs.yml | |
git checkout -f ${{ env.MERGE_BRANCH }} | |
rm -rf ./charts && rm -rf ./index.yaml && rm -rf ./changelogs | |
tar -czvf ./site.tar.gz * | |
ls | |
echo "push document version ${{ env.DEV_DOC_DIRECTORY }} from branch ${{ env.REF }}." | |
- name: Extract Version | |
id: extract | |
if: ${{ env.REF != 'main' }} | |
run: | | |
if ! grep -E "^[[:space:]]*v[0-9]+.[0-9]+.[0-9]+[[:space:]]*$" VERSION &>/dev/null ; then | |
echo "It is not a release version. docs for the corresponding version will not be generated. The documents will be published to 'dev' ." | |
cat VERSION | |
echo "PUBLISH_DOCS_TO_DEV=true" >> $GITHUB_ENV | |
exit 0 | |
fi | |
# for example v0.6.1, the build's documentation version is v0.6 | |
docVersion=` cat VERSION | tr -d ' ' | tr -d '\n' | grep -Eo "v[0-9]+\.[0-9]+" ` | |
if [ -n "${docVersion}" ]; then | |
echo "the version intercepted from the branch is: ${docVersion}" | |
else | |
echo "error, failed to get version." && exit 1 | |
fi | |
git checkout -f ${{ env.MERGE_BRANCH }} | |
echo "Switch to the branch:${{ env.MERGE_BRANCH }} where the document is located" | |
ls | |
if [ -e "${docVersion}" ]; then | |
echo "doc version:${docVersion} already exists, just update it." | |
echo "SET_LATEST=false" >> $GITHUB_ENV | |
else | |
echo "The doc version:${docVersion} does not exist yet, while generating the doc and set it to latest" | |
echo "SET_LATEST=true" >> $GITHUB_ENV | |
fi | |
echo "the doc version is: ${docVersion}" | |
echo "DOCS_TAG=${docVersion}" >> $GITHUB_ENV | |
- name: build doc | |
id: build_doc | |
if: ${{ env.REF != 'main' }} | |
run: | | |
git checkout ${{ env.REF }} | |
ls | |
echo "switch to the release version branch ${{ env.REF }}" | |
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==8.5.11 | |
git config user.email "[email protected]" | |
git config user.name "robot" | |
cp ./docs/mkdocs.yml ./ | |
if ${{ env.PUBLISH_DOCS_TO_DEV == 'true' }} ; then | |
echo "publish non-release version of documentation to dev:${{ env.DEV_DOC_DIRECTORY }}" | |
echo "DOCS_TAG=${{ env.DEV_DOC_DIRECTORY }}" >> $GITHUB_ENV | |
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DEV_DOC_DIRECTORY }} -t "${{ env.DEV_DOC_DIRECTORY }} (${{ env.REF }})" | |
elif ${{ env.SET_LATEST == 'true' }} ; then | |
echo "generate doc version:${{ env.DOCS_TAG }} and set to latest." | |
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} --update-aliases ${{env.DOCS_TAG }} latest | |
mike set-default -b ${{ env.MERGE_BRANCH }} latest | |
else | |
echo "the version:${{ env.DOCS_TAG }} of the doc does not need to be set to the latest." | |
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DOCS_TAG }} | |
fi | |
rm -rf ./site | |
rm -rf ./mkdocs.yml | |
git checkout -f ${{ env.MERGE_BRANCH }} | |
rm -rf ./charts && rm -rf ./index.yaml && rm -rf ./changelogs | |
tar -czvf ./site.tar.gz * | |
ls | |
echo "Automatic release, offline package ready" | |
echo "Push a doc version: ${{ env.DOCS_TAG }} from branch: ${{ env.REF }}, update it to latest: ${{ env.SET_LATEST }} " | |
- name: Upload Artifact | |
uses: actions/[email protected] | |
with: | |
name: website_package_artifact | |
path: site.tar.gz | |
retention-days: 0 | |
if-no-files-found: error | |
create_pr: | |
name: Create PR | |
needs: [release_doc] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.MERGE_BRANCH }} | |
fetch-depth: 0 | |
- name: Download Artifact | |
uses: actions/[email protected] | |
with: | |
name: website_package_artifact | |
- name: Untar Doc | |
run: | | |
tar -xzvf site.tar.gz | |
rm -f site.tar.gz | |
# Allow auto-merge on general | |
- name: Create Pull Request | |
id: create_pr | |
uses: peter-evans/[email protected] | |
with: | |
title: "robot update website from ${{ needs.release_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.release_doc.outputs.doc_tag }}" | |
commit-message: "robot update website from ${{ needs.release_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.release_doc.outputs.doc_tag }}" | |
branch-suffix: timestamp | |
branch: robot/update_doc | |
delete-branch: true | |
base: ${{ env.MERGE_BRANCH }} | |
signoff: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
labels: ${{ env.PR_LABEL }} | |
reviewers: ${{ env.PR_REVIWER }} |