-
Notifications
You must be signed in to change notification settings - Fork 24
ci: Extract docs versioning into reusable manual_version_docs.yaml workflow
#857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
80efec5
ci: Extract docs versioning into reusable `manual_version_docs.yaml` …
vdusek 35424c7
fix: Quote variable expansions in for loop globs to satisfy shellcheck
vdusek d832d68
refactor: Merge website deps install into snapshot step
vdusek 4cb04e0
refactor: Use `[[` instead of `[` for bash conditionals
vdusek 5b0bca0
refactor: Use defensive version lookup instead of glob-based deletion
vdusek 6232541
refactor: Include version number in docs versioning commit message
vdusek f2ed9e4
refactor: Use .gitignore instead of explicit cleanup for versioned do…
vdusek 2cbc62d
refactor: Remove unnecessary quotes and move env to workflow level
vdusek d94ab95
refactor: Use uv version --short to extract project version
vdusek 4859af2
refactor: Use more precise variable names for version identifiers
vdusek beee4da
refactor: Remove unnecessary .gitignore pattern from versioned docs
vdusek 9037b07
refactor: Quote NODE_VERSION env value for consistency
vdusek d944121
fix: Remove all old versions for same major, not just the first match
vdusek cee2764
fix: Prevent script injection in workflow run blocks
vdusek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| name: Version docs | ||
|
|
||
| on: | ||
| # Runs when manually triggered from the GitHub UI. | ||
| workflow_dispatch: | ||
| inputs: | ||
| ref: | ||
| description: Git ref to checkout (branch, tag, or SHA). Defaults to the default branch. | ||
| required: false | ||
| type: string | ||
| default: "" | ||
|
|
||
| # Runs when invoked by another workflow. | ||
| workflow_call: | ||
| inputs: | ||
| ref: | ||
| description: Git ref to checkout (branch, tag, or SHA) | ||
| required: true | ||
| type: string | ||
| outputs: | ||
| version_docs_commitish: | ||
| description: The commit SHA of the versioned docs commit | ||
| value: ${{ jobs.version_docs.outputs.version_docs_commitish }} | ||
|
|
||
| concurrency: | ||
| group: version-docs | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| NODE_VERSION: 22 | ||
| PYTHON_VERSION: "3.14" | ||
|
|
||
| jobs: | ||
| version_docs: | ||
| name: Version docs | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| version_docs_commitish: ${{ steps.resolve_commitish.outputs.commitish }} | ||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| - name: Determine checkout ref | ||
| id: resolve_ref | ||
| run: | | ||
| REF="${{ inputs.ref }}" | ||
| if [[ -z "$REF" ]]; then | ||
| REF="${{ github.event.repository.default_branch }}" | ||
| fi | ||
| echo "ref=$REF" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} | ||
| ref: ${{ steps.resolve_ref.outputs.ref }} | ||
|
|
||
| - name: Set up Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: ${{ env.NODE_VERSION }} | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
|
|
||
| - name: Set up uv package manager | ||
| uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
|
|
||
| - name: Install Python dependencies | ||
| run: uv run poe install-dev | ||
|
|
||
| - name: Snapshot the current version | ||
| id: snapshot | ||
| run: | | ||
| cd website | ||
| corepack enable | ||
| yarn install | ||
|
|
||
| # Extract version from pyproject.toml. | ||
| FULL_VERSION="$(uv version --short)" | ||
| MAJOR_MINOR_VERSION="$(echo "$FULL_VERSION" | cut -d. -f1-2)" | ||
| MAJOR_VERSION="$(echo "$FULL_VERSION" | cut -d. -f1)" | ||
| echo "version=$FULL_VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "Version: $FULL_VERSION, Major.Minor: $MAJOR_MINOR_VERSION, Major: $MAJOR_VERSION" | ||
|
|
||
| # Find the existing version for this major in versions.json (if any). | ||
| if [[ -f versions.json ]]; then | ||
| OLD_VERSION="$(jq -r --arg major "$MAJOR_VERSION" '.[] | select(startswith($major + "."))' versions.json | head -1)" | ||
| else | ||
| OLD_VERSION="" | ||
| echo "[]" > versions.json | ||
| fi | ||
|
|
||
| # Remove only the specific old version for this major (if found). | ||
| if [[ -n "$OLD_VERSION" ]]; then | ||
| echo "Removing old version $OLD_VERSION for major $MAJOR_VERSION" | ||
| rm -rf "versioned_docs/version-${OLD_VERSION}" | ||
| rm -f "versioned_sidebars/version-${OLD_VERSION}-sidebars.json" | ||
| jq --arg old "$OLD_VERSION" '[.[] | select(. != $old)]' versions.json > tmp.json && mv tmp.json versions.json | ||
|
vdusek marked this conversation as resolved.
Outdated
|
||
| else | ||
| echo "No existing version found for major $MAJOR_VERSION, nothing to remove" | ||
| fi | ||
|
|
||
| # Build API reference and create Docusaurus version snapshots. | ||
| bash build_api_reference.sh | ||
| uv run npx docusaurus docs:version "$MAJOR_MINOR_VERSION" | ||
| uv run npx docusaurus api:version "$MAJOR_MINOR_VERSION" | ||
|
|
||
| - name: Commit and push versioned docs | ||
| id: commit_versioned_docs | ||
| uses: EndBug/add-and-commit@v10 | ||
| with: | ||
| add: website/versioned_docs website/versioned_sidebars website/versions.json | ||
| message: "docs: Version docs for v${{ steps.snapshot.outputs.version }} [skip ci]" | ||
| default_author: github_actions | ||
|
|
||
| - name: Resolve output commitish | ||
| id: resolve_commitish | ||
| run: | | ||
| SHA="${{ steps.commit_versioned_docs.outputs.commit_long_sha }}" | ||
| if [[ -z "$SHA" ]]; then | ||
| SHA="$(git rev-parse HEAD)" | ||
| fi | ||
| echo "commitish=$SHA" >> "$GITHUB_OUTPUT" | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.