ci: Run docs generation on all changes #220
Workflow file for this run
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
| --- | |
| # yamllint disable rule:truthy rule:truthy rule:line-length | |
| # CI Workflow Diagram: | |
| # files-changed | |
| # ↓ | |
| # ┌───┴───┬───────────┐ | |
| # ↓ ↓ ↓ | |
| # yaml python markdown | |
| # -lint -lint -lint | |
| # ↓ ↓ ↓ | |
| # └───┬───┴───────────┘ | |
| # ↓ | |
| # schema-test | |
| # ↓ | |
| # generate-documentation (PR only, commits with [skip ci]) | |
| # ↓ | |
| # validate-documentation (checks latest branch state) | |
| name: "CI" | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} | |
| VALE_VERSION: "3.7.1" | |
| jobs: | |
| files-changed: | |
| name: Detect which file has changed | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| outputs: | |
| documentation: ${{ steps.changes.outputs.documentation_all }} | |
| markdown: ${{ steps.changes.outputs.markdown_all }} | |
| python: ${{ steps.changes.outputs.python_all }} | |
| schema: ${{ steps.changes.outputs.schema_all }} | |
| yaml: ${{ steps.changes.outputs.yaml_all }} | |
| steps: | |
| - name: "Check out repository code" | |
| uses: "actions/checkout@v4" | |
| - name: Check for file changes | |
| uses: opsmill/paths-filter@v3.0.2 | |
| id: changes | |
| with: | |
| token: ${{ github.token }} | |
| filters: .github/file-filters.yml | |
| python-lint: | |
| if: needs.files-changed.outputs.python == 'true' | |
| needs: ["files-changed"] | |
| runs-on: "ubuntu-latest" | |
| timeout-minutes: 5 | |
| steps: | |
| - name: "Check out repository code" | |
| uses: "actions/checkout@v4" | |
| - name: "Set up Python" | |
| uses: "actions/setup-python@v5" | |
| with: | |
| python-version: "3.12" | |
| - name: "Install uv" | |
| uses: "astral-sh/setup-uv@v5" | |
| with: | |
| version: "0.9.18" | |
| - name: "Install dependencies" | |
| run: "uv sync --group dev" | |
| - name: "Linting: ruff check" | |
| run: "uv run ruff check ." | |
| - name: "Linting: ruff format" | |
| run: "uv run ruff format --check --diff ." | |
| - name: "Mypy Tests" | |
| run: "uv run mypy --show-error-codes ." | |
| - name: "Pylint Tests" | |
| run: "uv run pylint --ignore .venv ." | |
| yaml-lint: | |
| name: Run yaml lint | |
| if: needs.files-changed.outputs.yaml == 'true' | |
| needs: ["files-changed"] | |
| runs-on: "ubuntu-latest" | |
| timeout-minutes: 5 | |
| steps: | |
| - name: "Check out repository code" | |
| uses: "actions/checkout@v4" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: "Install uv" | |
| uses: "astral-sh/setup-uv@v5" | |
| with: | |
| version: "0.9.18" | |
| - name: Install dependencies | |
| run: uv sync --group dev | |
| - name: "Linting: yamllint" | |
| run: "uv run yamllint -s ." | |
| markdown-lint: | |
| name: Run markdown lint | |
| if: needs.files-changed.outputs.markdown == 'true' | |
| needs: ["files-changed"] | |
| runs-on: "ubuntu-latest" | |
| timeout-minutes: 5 | |
| steps: | |
| - name: "Check out repository code" | |
| uses: "actions/checkout@v4" | |
| - name: "Setup Node.js" | |
| uses: "actions/setup-node@v4" | |
| with: | |
| node-version: "20" | |
| - name: "Install markdownlint-cli" | |
| run: "npm install -g markdownlint-cli" | |
| - name: "Linting: markdownlint" | |
| run: "markdownlint '**/*.md' '**/*.mdx'" | |
| schema-test: | |
| name: Test all schema files | |
| needs: | |
| - files-changed | |
| - yaml-lint | |
| if: | | |
| always() && !cancelled() && | |
| !contains(needs.*.result, 'failure') && | |
| !contains(needs.*.result, 'cancelled') && | |
| needs.files-changed.outputs.schema == 'true' | |
| runs-on: | |
| group: huge-runners | |
| env: | |
| INFRAHUB_API_TOKEN: 06438eb2-8019-4776-878c-0941b1f1d1ec | |
| INFRAHUB_VERSION: latest | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: "Install uv" | |
| uses: "astral-sh/setup-uv@v5" | |
| with: | |
| version: "0.9.18" | |
| - name: Install dependencies | |
| run: uv sync --group dev | |
| - name: Set job name | |
| run: echo JOB_NAME="$GITHUB_JOB" >> $GITHUB_ENV | |
| - name: "Set environment variable INFRAHUB_BUILD_NAME" | |
| run: echo INFRAHUB_BUILD_NAME=infrahub-${{ runner.name }} >> $GITHUB_ENV | |
| - name: Initialize Infrahub | |
| run: uv run invoke start | |
| - name: Set infrahub address | |
| run: | | |
| PORT=$(docker compose -p $INFRAHUB_BUILD_NAME port infrahub-server 8000 | cut -d: -f2) | |
| echo "INFRAHUB_ADDRESS=http://localhost:${PORT}" >> $GITHUB_ENV | |
| - name: "Store start time" | |
| run: echo TEST_START_TIME=$(date +%s)000 >> $GITHUB_ENV | |
| - name: Load all schemas files | |
| run: uv run invoke schemas.load-all-schemas | |
| - name: "Clear docker environment and force vmagent to stop" | |
| if: always() | |
| run: uv run invoke destroy | |
| generate-documentation: | |
| defaults: | |
| run: | |
| working-directory: ./docs | |
| if: | | |
| always() && !cancelled() && | |
| !contains(needs.*.result, 'failure') && | |
| !contains(needs.*.result, 'cancelled') && | |
| github.event_name == 'pull_request' | |
| needs: | |
| [ | |
| "files-changed", | |
| "yaml-lint", | |
| "python-lint", | |
| "markdown-lint", | |
| "schema-test", | |
| ] | |
| runs-on: "ubuntu-22.04" | |
| timeout-minutes: 5 | |
| steps: | |
| - name: "Check out repository code" | |
| uses: "actions/checkout@v4" | |
| with: | |
| submodules: true | |
| ref: ${{ github.head_ref }} | |
| - name: Install NodeJS | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "npm" | |
| cache-dependency-path: docs/package-lock.json | |
| - name: "Install uv" | |
| uses: "astral-sh/setup-uv@v5" | |
| with: | |
| version: "0.9.18" | |
| - name: "Install Python dependencies" | |
| run: "uv sync" | |
| working-directory: ./ | |
| - name: "Install dependencies" | |
| run: "uv run invoke docs.install" | |
| working-directory: ./ | |
| - name: "Generate reference documentation" | |
| run: "uv run invoke docs.generate" | |
| working-directory: ./ | |
| - name: Push documentation changes | |
| id: push | |
| run: | | |
| git config --global user.name "documentator" | |
| git config --global user.email "documentator@opsmill.com" | |
| git add docs/reference/ | |
| if git commit -m "docs: auto-generate reference [skip ci]"; then | |
| git push | |
| echo "pushed=true" >> $GITHUB_OUTPUT | |
| echo "new_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
| else | |
| echo "No changes to commit!" | |
| echo "pushed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Report CI status on new commit | |
| if: steps.push.outputs.pushed == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh api repos/${{ github.repository }}/statuses/${{ steps.push.outputs.new_sha }} \ | |
| -f state=success \ | |
| -f context="CI" \ | |
| -f description="CI passed on parent commit" \ | |
| -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| working-directory: ./ | |
| validate-documentation: | |
| if: | | |
| always() && !cancelled() && | |
| !contains(needs.*.result, 'failure') && | |
| !contains(needs.*.result, 'cancelled') && | |
| github.event_name == 'pull_request' | |
| needs: ["generate-documentation"] | |
| runs-on: "ubuntu-22.04" | |
| timeout-minutes: 5 | |
| steps: | |
| - name: "Check out repository code" | |
| uses: "actions/checkout@v4" | |
| with: | |
| submodules: true | |
| ref: ${{ github.head_ref }} # checkout the latest changes after the doc generation push | |
| - name: Install NodeJS | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "npm" | |
| cache-dependency-path: docs/package-lock.json | |
| - name: "Install uv" | |
| uses: "astral-sh/setup-uv@v5" | |
| with: | |
| version: "0.9.18" | |
| - name: "Install Python dependencies" | |
| run: "uv sync" | |
| working-directory: ./ | |
| - name: "Install dependencies" | |
| run: "uv run invoke docs.install" | |
| working-directory: ./ | |
| - name: "Build docs website" | |
| run: "uv run invoke docs.build" | |
| working-directory: ./ | |
| # The official GitHub Action for Vale doesn't work, installing manually instead: | |
| # https://github.com/errata-ai/vale-action/issues/103 | |
| - name: Download Vale | |
| run: | | |
| curl -sL "https://github.com/errata-ai/vale/releases/download/v${VALE_VERSION}/vale_${VALE_VERSION}_Linux_64-bit.tar.gz" -o vale.tar.gz | |
| tar -xzf vale.tar.gz | |
| env: | |
| VALE_VERSION: ${{ env.VALE_VERSION }} | |
| - name: "Validate documentation style" | |
| run: ./vale --config=.vale.ini $(find ./docs -type f \( -name "*.mdx" -o -name "*.md" \) -not -path "./docs/node_modules/*" -not -path "./docs/docs/reference/*") |