From f898e43f650aa48732011b16a66b3c6bae764691 Mon Sep 17 00:00:00 2001 From: Yunchu Lee Date: Wed, 13 Mar 2024 15:29:09 +0900 Subject: [PATCH] add docs workflow for latest & testing --- .github/workflows/docs.yaml | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/docs.yaml diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml new file mode 100644 index 00000000000..80e38e9faea --- /dev/null +++ b/.github/workflows/docs.yaml @@ -0,0 +1,78 @@ +name: Build Docs for the latest + +on: + workflow_dispatch: # run on request (no need for PR) + push: + branches: + - develop + +# Declare default permissions as read only. +permissions: read-all + +jobs: + Build-Docs: + runs-on: ubuntu-20.04 + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Set up Python + uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0 + with: + python-version: "3.10" + - name: Install tox + run: python -m pip install --require-hashes --no-deps -r .ci/tox-deps.txt + - name: Build-Docs + run: tox -e build-doc + - name: Create gh-pages branch + run: | + if [[ ${{github.event_name}} == 'workflow_dispatch' ]]; then + echo RELEASE_VERSION="test_build" >> $GITHUB_ENV + else + echo RELEASE_VERSION=${GITHUB_REF#refs/*/} >> $GITHUB_ENV + fi + echo SOURCE_NAME=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT + echo SOURCE_BRANCH=${GITHUB_REF#refs/heads/} >> $GITHUB_OUTPUT + echo SOURCE_TAG=${GITHUB_REF#refs/tags/} >> $GITHUB_OUTPUT + + existed_in_remote=$(git ls-remote --heads origin gh-pages) + + if [[ -z ${existed_in_remote} ]]; then + echo "Creating gh-pages branch" + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git checkout --orphan gh-pages + git reset --hard + touch .nojekyll + git add .nojekyll + git commit -m "Initializing gh-pages branch" + git push origin gh-pages + git checkout ${{steps.branch_name.outputs.SOURCE_NAME}} + echo "Created gh-pages branch" + else + echo "Branch gh-pages already exists" + fi + - name: Commit docs to gh-pages branch + run: | + git fetch + git checkout gh-pages + mkdir -p /tmp/docs_build + cp -r docs/build/html/* /tmp/docs_build/ + rm -rf ${{ env.RELEASE_VERSION }}/* + echo '' > index.html + mkdir -p ${{ env.RELEASE_VERSION }} + cp -r /tmp/docs_build/* ./${{ env.RELEASE_VERSION }} + rm -rf /tmp/docs_build + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + if [[ ${{ env.RELEASE_VERSION }} != 'test_build' ]]; then + ln -sfn ${{ env.RELEASE_VERSION }} latest + fi + git add ./latest ${{ env.RELEASE_VERSION }} + git commit -m "Update documentation" -a || true + - name: Push changes + uses: ad-m/github-push-action@fcea09907c44d7a7a3331c9c04080d55d87c95fe # master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: gh-pages