|
| 1 | +name: Publish docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "[0-9]+.[0-9]+.x" |
| 7 | + release: |
| 8 | + types: |
| 9 | + - published |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Deploy docs |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.x" |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: pip install -r docs/requirements.txt |
| 27 | + |
| 28 | + - name: Set up git author |
| 29 | + uses: oleksiyrudenko/gha-git-credentials@v2 |
| 30 | + with: |
| 31 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Find latest release |
| 34 | + id: latest_release |
| 35 | + uses: pozetroninc/github-action-get-latest-release@v0.8.0 |
| 36 | + with: |
| 37 | + repository: ${{ github.repository }} |
| 38 | + excludes: draft,prerelease |
| 39 | + |
| 40 | + - name: Normalize current versions |
| 41 | + id: current |
| 42 | + uses: actions/github-script@v7 |
| 43 | + with: |
| 44 | + script: return context.ref.match(/([0-9]+\.[0-9]+)\.(x|[0-9]+)/i)[1]; |
| 45 | + result-encoding: string |
| 46 | + |
| 47 | + - name: Normalize latest versions |
| 48 | + id: latest |
| 49 | + uses: actions/github-script@v7 |
| 50 | + with: |
| 51 | + script: return "${{steps.latest_release.outputs.release}}".match(/([0-9]+\.[0-9]+)\.[0-9]+/i)[1]; |
| 52 | + result-encoding: string |
| 53 | + |
| 54 | + - name: Setup deploy key |
| 55 | + env: |
| 56 | + DEPLOY_DOCS_KEY: ${{ secrets.DEPLOY_DOCS_KEY }} |
| 57 | + run: | |
| 58 | + # Setup SSH deploy key |
| 59 | + mkdir -p ~/.ssh |
| 60 | + echo "${DEPLOY_DOCS_KEY}" > ~/.ssh/id_rsa |
| 61 | + chmod 600 ~/.ssh/id_rsa |
| 62 | + ssh-keyscan -H github.com > ~/.ssh/known_hosts |
| 63 | +
|
| 64 | + - run: git remote add doc git@github.com:patchlevel/event-sourcing-bundle-docs.git |
| 65 | + - run: git fetch doc gh-pages --verbose |
| 66 | + |
| 67 | + - run: | |
| 68 | + current_major=$(echo "$version_current" | cut -d '.' -f 1) |
| 69 | + current_minor=$(echo "$version_current" | cut -d '.' -f 2) |
| 70 | + |
| 71 | + latest_major=$(echo "$version_latest" | cut -d '.' -f 1) |
| 72 | + latest_minor=$(echo "$version_latest" | cut -d '.' -f 2) |
| 73 | + |
| 74 | + if [ "${{ steps.current.outputs.result }}" = "${{ steps.latest.outputs.result }}" ] |
| 75 | + then |
| 76 | + # Here we deploy a new latest version |
| 77 | + mike deploy latest --config-file docs/mkdocs.yml --title="${{ steps.current.outputs.result }} (latest)" --push --remote doc |
| 78 | + elif [ "$current_major" -lt "$latest_major" ] || \ |
| 79 | + { [ "$current_major" -eq "$latest_major" ] && [ "$current_minor" -lt "$latest_minor" ]; } |
| 80 | + then |
| 81 | + # Here we deploy a version that's not the latest one and smaller as the latest version |
| 82 | + mike deploy ${{ steps.current.outputs.result }} --config-file docs/mkdocs.yml --push --remote doc |
| 83 | + fi |
| 84 | + - run: | |
| 85 | + # Check if the "latest" alias exists |
| 86 | + HAS_LATEST=$(mike list --config-file docs/mkdocs.yml --rebase --remote doc | grep latest) || true |
| 87 | + |
| 88 | + # If so then it is set as the default version (to enable the index redirect) |
| 89 | + if [ "${HAS_LATEST}" != "" ] |
| 90 | + then |
| 91 | + echo "Set latest as default" |
| 92 | + mike set-default latest --config-file docs/mkdocs.yml --remote doc |
| 93 | + fi |
0 commit comments