Publish docs via GitHub Pages #2248
This file contains hidden or 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: Publish docs via GitHub Pages | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'docs/**' | |
| - 'charts/**' | |
| - 'mkdocs.yml' | |
| - 'docker-**/README.md' | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'docs/**' | |
| - 'charts/**' | |
| - 'mkdocs.yml' | |
| - 'docker-**/README.md' | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag (e.g."v5.1.6")' | |
| default: "nightly" | |
| required: false | |
| concurrency: | |
| group: run-once | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| permissions: | |
| contents: write # for Git to git push | |
| if: github.repository == 'GluuFederation/flex' | |
| name: Deploy docs | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.MOWORKFLOWTOKEN }} | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0 | |
| with: | |
| python-version: "3.10" | |
| cache: pip | |
| - name: Install dependencies | |
| run: | | |
| curl -sSL https://install.python-poetry.org | python3 - | |
| export PATH="$HOME/.local/bin:$PATH" | |
| cp docs/pyproject.toml docs/poetry.lock ../ | |
| poetry install --no-root | |
| cp mkdocs.yml ../ | |
| - name: Checkout flex ${{ github.event.inputs.version }} | |
| if: >- | |
| github.event_name == 'workflow_dispatch' | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| ref: '${{ github.event.inputs.version }}' | |
| fetch-depth: 0 | |
| token: ${{ secrets.MOWORKFLOWTOKEN }} | |
| - name: Copy files from main to ${{ github.event.inputs.version }} | |
| if: >- | |
| github.event_name == 'workflow_dispatch' | |
| run: | | |
| mv ../mkdocs.yml mkdocs.yml | |
| - name: Copy generated chart from main | |
| run: | | |
| helm package charts/gluu | |
| helm package charts/gluu-all-in-one | |
| cp gluu-*.tgz ../ | |
| - name: Import GPG key | |
| id: import_gpg | |
| uses: crazy-max/ghaction-import-gpg@e89d40939c28e39f97cf32126055eeae86ba74ec # v6.3.0 | |
| with: | |
| gpg_private_key: ${{ secrets.MOAUTO_GPG_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.MOAUTO_GPG_PRIVATE_KEY_PASSPHRASE }} | |
| git_user_signingkey: true | |
| git_commit_gpgsign: true | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "mo-auto" | |
| git config --global user.email "[email protected]" | |
| git config --global user.signingkey "${{ steps.import_gpg.outputs.keyid }}" | |
| echo "${{ secrets.MOWORKFLOWTOKEN }}" | gh auth login --with-token | |
| - name: Generate docs | |
| continue-on-error: true | |
| if: >- | |
| github.event_name == 'release' && | |
| github.event.action == 'published' && | |
| (!github.event.release.draft) && | |
| (startsWith(github.event.release.name, 'v') || github.event.release.name == 'nightly') | |
| env: | |
| VERSION: ${{ github.event.release.tag_name }} | |
| run: | | |
| mkdir temp && cd temp | |
| git clone https://mo-auto:${{ secrets.MOWORKFLOWTOKEN }}@github.com/GluuFederation/flex.git | |
| cd flex | |
| git checkout -b cn-flex-update-auto-generated-docs | |
| git pull origin cn-flex-update-auto-generated-docs || echo "Nothing to pull" | |
| echo "Custom work on generating docs can go here." | |
| # Run cn docs | |
| sudo bash ./automation/docs/generated-cn-docs.sh . || echo "something went wrong with generating the cn docs" | |
| git push --set-upstream origin cn-flex-update-auto-generated-docs | |
| MESSAGE="fix(docs): autogenerate docs" | |
| PR=$(gh pr create --body "Auto generated docs" --title "${MESSAGE}") | |
| cd ../../ | |
| sudo rm -rf temp | |
| - name: mike deploy ${{ github.event.inputs.version }} | |
| if: >- | |
| github.event_name == 'workflow_dispatch' | |
| run: | | |
| poetry run mike deploy --push --force ${{ github.event.inputs.version }} | |
| - name: mike deploy head | |
| if: contains(github.ref, 'refs/heads/main') && github.event_name != 'workflow_dispatch' | |
| run: | | |
| poetry run mike deploy --push head | |
| - name: mike deploy new version | |
| if: >- | |
| github.event_name == 'release' && | |
| github.event.action == 'published' && | |
| (!github.event.release.draft) && | |
| (startsWith(github.event.release.name, 'v') || github.event.release.name == 'nightly') | |
| env: | |
| VERSION: ${{ github.event.release.tag_name }} | |
| run: | | |
| poetry run mike deploy --push "$VERSION" | |
| - name: Update mike version aliases | |
| id: set_versions | |
| run: | | |
| GITHUB_EVENT_RELEASE_TAG_NAME="${{ github.event.release.tag_name }}" | |
| TAGS=$(gh release list -L 1000 -R ${{ github.repository }} | grep -o '^\v.*'| grep -v Draft | cut -f 1 | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//') | |
| LATEST=$(echo "${TAGS}" | tail -1) | |
| STABLE=$(echo "${TAGS}" | grep -v -- "nightly" | tail -1) | |
| if [[ "$GITHUB_EVENT_RELEASE_TAG_NAME" == 'nightly' ]]; then | |
| LATEST='nightly' | |
| fi | |
| echo "Latest is $LATEST and Stable is $STABLE" | |
| poetry run mike alias -u head main | |
| poetry run mike alias -u "${STABLE}" stable | |
| poetry run mike set-default --push stable | |
| echo "LATEST=${LATEST}" >> $GITHUB_OUTPUT | |
| echo "STABLE=${STABLE}" >> $GITHUB_OUTPUT | |
| - name: Create version files | |
| run: | | |
| LATEST=${{ steps.set_versions.outputs.LATEST }} | |
| STABLE=${{ steps.set_versions.outputs.STABLE }} | |
| git checkout -f gh-pages | |
| git pull origin gh-pages | |
| # move generated chart from a previous step | |
| mv ../gluu-*.tgz ./charts/ | |
| cd ./charts | |
| git add gluu-*.tgz && git update-index --refresh | |
| helm repo index . | |
| git add index.yaml && git update-index --refresh | |
| cd .. | |
| for folder in v*/; do | |
| cp -r nightly/search "$folder" | |
| git add $folder/search && git update-index --refresh | |
| done | |
| cd ${LATEST} | |
| if [[ "${LATEST}" == "nightly" ]]; then | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/replace-janssen-version-stable/0.0.0-nightly/g" | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/replace-janssen-version/0.0.0-nightly/g" | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/replace-flex-version-stable/0.0.0-nightly/g" | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/replace-flex-version/0.0.0-nightly/g" | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/v0.0.0-nightly/nightly/g" | |
| else | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/replace-janssen-version/${LATEST:1}/g" | |
| egrep -lRZ --exclude=CONTRIBUTING.md . | xargs -0 -l sed -i -e "s/replace-flex-version/${LATEST:1}/g" | |
| fi | |
| git add . && git update-index --refresh | |
| cd .. | |
| echo "${STABLE}" > stable.txt | |
| git add stable.txt && git update-index --refresh | |
| git diff-index --quiet HEAD -- || git commit -S -m "Set stable to ${STABLE}" | |
| echo "${LATEST}" > latest.txt | |
| git add latest.txt && git update-index --refresh | |
| git diff-index --quiet HEAD -- || git commit -S -m "Set latest to ${LATEST}" | |
| git push origin gh-pages |