build(deps): install the shared config from GitHub Packages instead o… #120
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: Deploy VitePress docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| paths: | |
| - 'docs/**' | |
| - 'package.json' | |
| workflow_dispatch: | |
| # @max-health-inc/config is installed from GitHub Packages (see .npmrc), which needs a token | |
| # even though the package is public. Set at workflow level so every `npm ci` below is covered. | |
| # An unset secret expands to an EMPTY string and fails with a 401 identical to a bad token. | |
| # Nothing in this workflow publishes, so a workflow-wide NODE_AUTH_TOKEN is safe here. | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }} | |
| jobs: | |
| deploy-docs: | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: gh-pages-deploy | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build VitePress docs | |
| run: npm run docs:build | |
| - name: Deploy to GitHub Pages | |
| run: | | |
| DOCS_OUT="$(pwd)/.vitepress-dist" | |
| if [ ! -d "$DOCS_OUT" ]; then | |
| echo "ERROR: VitePress build output not found at $DOCS_OUT" | |
| exit 1 | |
| fi | |
| DEPLOY_DIR=$(mktemp -d) | |
| # Checkout existing gh-pages content (preserve parity report at root) | |
| git fetch origin gh-pages:gh-pages 2>/dev/null || true | |
| if git show-ref --verify --quiet refs/heads/gh-pages; then | |
| git worktree add "$DEPLOY_DIR" gh-pages | |
| else | |
| git worktree add --orphan "$DEPLOY_DIR" gh-pages 2>/dev/null || { | |
| git worktree add "$DEPLOY_DIR" --detach | |
| git -C "$DEPLOY_DIR" checkout --orphan gh-pages | |
| git -C "$DEPLOY_DIR" rm -rf . 2>/dev/null || true | |
| } | |
| fi | |
| # Clear old docs/ subdir and copy fresh build | |
| rm -rf "$DEPLOY_DIR/docs" | |
| mkdir -p "$DEPLOY_DIR/docs" | |
| cp -r "$DOCS_OUT"/* "$DEPLOY_DIR/docs/" | |
| # Ensure .nojekyll exists at root | |
| touch "$DEPLOY_DIR/.nojekyll" | |
| # Commit and push | |
| cd "$DEPLOY_DIR" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No docs changes to deploy" | |
| else | |
| git commit -m "Deploy VitePress docs [skip ci]" | |
| git push origin gh-pages | |
| echo "Deployed docs to GitHub Pages at /docs/" | |
| fi | |
| cd - | |
| git worktree remove "$DEPLOY_DIR" --force 2>/dev/null || true |