|
| 1 | +name: Version docs |
| 2 | + |
| 3 | +on: |
| 4 | + # Runs when manually triggered from the GitHub UI. |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + ref: |
| 8 | + description: Git ref to checkout (branch, tag, or SHA). Defaults to the default branch. |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + default: "" |
| 12 | + |
| 13 | + # Runs when invoked by another workflow. |
| 14 | + workflow_call: |
| 15 | + inputs: |
| 16 | + ref: |
| 17 | + description: Git ref to checkout (branch, tag, or SHA) |
| 18 | + required: true |
| 19 | + type: string |
| 20 | + outputs: |
| 21 | + version_docs_commitish: |
| 22 | + description: The commit SHA of the versioned docs commit |
| 23 | + value: ${{ jobs.version_docs.outputs.version_docs_commitish }} |
| 24 | + |
| 25 | +concurrency: |
| 26 | + group: version-docs |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +permissions: |
| 30 | + contents: read |
| 31 | + |
| 32 | +env: |
| 33 | + NODE_VERSION: "22" |
| 34 | + PYTHON_VERSION: "3.14" |
| 35 | + |
| 36 | +jobs: |
| 37 | + version_docs: |
| 38 | + name: Version docs |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + version_docs_commitish: ${{ steps.resolve_commitish.outputs.commitish }} |
| 42 | + permissions: |
| 43 | + contents: write |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Determine checkout ref |
| 47 | + id: resolve_ref |
| 48 | + env: |
| 49 | + INPUT_REF: ${{ inputs.ref }} |
| 50 | + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} |
| 51 | + run: | |
| 52 | + REF="${INPUT_REF:-$DEFAULT_BRANCH}" |
| 53 | + echo "ref=$REF" >> "$GITHUB_OUTPUT" |
| 54 | +
|
| 55 | + - name: Checkout repository |
| 56 | + uses: actions/checkout@v6 |
| 57 | + with: |
| 58 | + token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
| 59 | + ref: ${{ steps.resolve_ref.outputs.ref }} |
| 60 | + |
| 61 | + - name: Set up Node |
| 62 | + uses: actions/setup-node@v6 |
| 63 | + with: |
| 64 | + node-version: ${{ env.NODE_VERSION }} |
| 65 | + |
| 66 | + - name: Set up Python |
| 67 | + uses: actions/setup-python@v6 |
| 68 | + with: |
| 69 | + python-version: ${{ env.PYTHON_VERSION }} |
| 70 | + |
| 71 | + - name: Set up uv package manager |
| 72 | + uses: astral-sh/setup-uv@v7 |
| 73 | + with: |
| 74 | + python-version: ${{ env.PYTHON_VERSION }} |
| 75 | + |
| 76 | + - name: Install Python dependencies |
| 77 | + run: uv run poe install-dev |
| 78 | + |
| 79 | + - name: Snapshot the current version |
| 80 | + id: snapshot |
| 81 | + run: | |
| 82 | + cd website |
| 83 | + corepack enable |
| 84 | + yarn install |
| 85 | +
|
| 86 | + # Extract version from pyproject.toml. |
| 87 | + FULL_VERSION="$(uv version --short)" |
| 88 | + MAJOR_MINOR_VERSION="$(echo "$FULL_VERSION" | cut -d. -f1-2)" |
| 89 | + MAJOR_VERSION="$(echo "$FULL_VERSION" | cut -d. -f1)" |
| 90 | + echo "version=$FULL_VERSION" >> "$GITHUB_OUTPUT" |
| 91 | + echo "Version: $FULL_VERSION, Major.Minor: $MAJOR_MINOR_VERSION, Major: $MAJOR_VERSION" |
| 92 | +
|
| 93 | + # Find the existing versions for this major in versions.json (if any). |
| 94 | + if [[ -f versions.json ]]; then |
| 95 | + OLD_VERSIONS="$(jq -r --arg major "$MAJOR_VERSION" '.[] | select(startswith($major + "."))' versions.json)" |
| 96 | + else |
| 97 | + OLD_VERSIONS="" |
| 98 | + echo "[]" > versions.json |
| 99 | + fi |
| 100 | +
|
| 101 | + # Remove all old versions for this major (if found). |
| 102 | + if [[ -n "$OLD_VERSIONS" ]]; then |
| 103 | + while IFS= read -r OLD_VERSION; do |
| 104 | + [[ -z "$OLD_VERSION" ]] && continue |
| 105 | + echo "Removing old version $OLD_VERSION for major $MAJOR_VERSION" |
| 106 | + rm -rf "versioned_docs/version-${OLD_VERSION}" |
| 107 | + rm -f "versioned_sidebars/version-${OLD_VERSION}-sidebars.json" |
| 108 | + done <<< "$OLD_VERSIONS" |
| 109 | + jq --arg major "$MAJOR_VERSION" 'map(select(startswith($major + ".") | not))' versions.json > tmp.json && mv tmp.json versions.json |
| 110 | + else |
| 111 | + echo "No existing versions found for major $MAJOR_VERSION, nothing to remove" |
| 112 | + fi |
| 113 | +
|
| 114 | + # Build API reference and create Docusaurus version snapshots. |
| 115 | + bash build_api_reference.sh |
| 116 | + uv run npx docusaurus docs:version "$MAJOR_MINOR_VERSION" |
| 117 | + uv run npx docusaurus api:version "$MAJOR_MINOR_VERSION" |
| 118 | +
|
| 119 | + - name: Commit and push versioned docs |
| 120 | + id: commit_versioned_docs |
| 121 | + uses: EndBug/add-and-commit@v10 |
| 122 | + with: |
| 123 | + add: website/versioned_docs website/versioned_sidebars website/versions.json |
| 124 | + message: "docs: Version docs for v${{ steps.snapshot.outputs.version }} [skip ci]" |
| 125 | + default_author: github_actions |
| 126 | + |
| 127 | + - name: Resolve output commitish |
| 128 | + id: resolve_commitish |
| 129 | + env: |
| 130 | + COMMIT_SHA: ${{ steps.commit_versioned_docs.outputs.commit_long_sha }} |
| 131 | + run: | |
| 132 | + echo "commitish=${COMMIT_SHA:-$(git rev-parse HEAD)}" >> "$GITHUB_OUTPUT" |
0 commit comments