Reusable GitHub Actions workflows for common CI/CD tasks.
Builds a Vite application and deploys it to GitHub Pages.
Usage:
name: Deploy to GitHub Pages
on:
push:
branches:
- main
workflow_dispatch:
# IMPORTANT: Define permissions and concurrency at the workflow level
# The reusable workflow inherits these settings
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
uses: agusgonzaleznic/github-reusable-workflows/.github/workflows/vite-build-deploy.yml@main
# Pass permissions to the job
permissions:
contents: read
pages: write
id-token: write
with:
node-version: '20' # Optional, default: '20'
install-command: 'npm ci' # Optional, default: 'npm ci'
lint-command: 'npm run lint' # Optional, default: 'npm run lint'
build-command: 'npm run build' # Optional, default: 'npm run build'
artifact-path: 'dist' # Optional, default: 'dist'
run-lint: true # Optional, default: trueInputs:
| Input | Description | Required | Default |
|---|---|---|---|
node-version |
Node.js version to use | No | '20' |
install-command |
Command to install dependencies | No | 'npm ci' |
lint-command |
Command to lint the project | No | 'npm run lint' |
build-command |
Command to build the project | No | 'npm run build' |
artifact-path |
Path to the build output directory (relative path without ./) |
No | 'dist' |
run-lint |
Whether to run linting | No | true |
Required Repository Settings:
- Go to Repository → Settings → Pages
- Under "Build and deployment" section:
- Source dropdown: Select "GitHub Actions"
- Do NOT use "Deploy from a branch" (this will use Jekyll and ignore your workflow)
- Click Save
Why this matters: If set to "Deploy from a branch", GitHub will try to build your site with Jekyll from the branch, completely ignoring your pre-built artifact. Your workflow will appear to succeed, but the deployed site will be incorrect or broken.
Runs linting and build checks for pull requests on Vite applications.
Usage:
name: CI
on:
pull_request:
branches:
- main
workflow_dispatch:
jobs:
ci:
uses: agusgonzaleznic/github-reusable-workflows/.github/workflows/vite-ci.yml@main
with:
node-version: '20' # Optional, default: '20'
install-command: 'npm ci' # Optional, default: 'npm ci'
lint-command: 'npm run lint' # Optional, default: 'npm run lint'
build-command: 'npm run build' # Optional, default: 'npm run build'
artifact-path: 'dist' # Optional, default: 'dist'
verify-build-output: true # Optional, default: trueInputs:
| Input | Description | Required | Default |
|---|---|---|---|
node-version |
Node.js version to use | No | '20' |
install-command |
Command to install dependencies | No | 'npm ci' |
lint-command |
Command to lint the project | No | 'npm run lint' |
build-command |
Command to build the project | No | 'npm run build' |
artifact-path |
Path to the build output directory | No | 'dist' |
verify-build-output |
Whether to verify build output exists | No | true |
- All workflows use npm by default, but can be customized via inputs
- Workflows support Node.js caching for faster builds
- Both workflows are framework-agnostic and can work with any Vite-based project
- Use
@mainbranch for stable versions, or pin to a specific commit SHA for reproducibility - Important: Use relative paths without
./prefix forartifact-path(e.g.,'dist'not'./dist') to ensure proper artifact upload with GitHub Actions - Reusable Workflow Pattern: The reusable workflow does NOT define its own
permissionsorconcurrencygroups. These must be defined in the calling workflow to avoid deadlock conflicts
If the GitHub Pages artifact isn't uploading correctly:
-
Check the workflow logs - The build verification step shows exactly what will be uploaded
-
Verify artifact structure - The artifact should contain your site files at the root, not in a subdirectory
-
Expected artifact contents:
index.html (at root) assets/ favicon.ico ...other files... -
NOT this structure:
dist/ (don't want this!) index.html assets/ -
Path format: Use
artifact-path: 'dist'without./prefix -
Verify build output: Check that
npm run buildcreates files in the expected directory -
Review workflow logs: Look for the "Build Output Verification" section
-
"Jekyll is building my site" or "Workflow succeeds but site is broken"
- Cause: Repository is set to "Deploy from a branch" instead of "GitHub Actions"
- Solution:
- Go to Repository → Settings → Pages
- Change Source from "Deploy from a branch" to "GitHub Actions"
- Re-run the workflow
- Why: When set to "Deploy from a branch", GitHub ignores your artifact and tries to build with Jekyll from the branch
- Verification: Check your workflow logs - if you see Jekyll-related output, your settings are wrong
-
"Deadlock was detected for concurrency group 'pages'"
- This happens when both the calling workflow and reusable workflow define the same concurrency group
- Solution: Only define
concurrencyin the calling workflow, not in the reusable workflow - The reusable workflow now correctly inherits concurrency settings from the caller
-
404 on deployment: Check that
index.htmlis at the root of the artifact, not in a subdirectory -
Assets not loading: Verify your
vite.config.tshas the correctbasepath- User/org pages (
username.github.io):base: '/' - Project pages (
username.github.io/repo):base: '/repo/'
- User/org pages (
When adding new reusable workflows, ensure:
- Use
workflow_callas the trigger - Provide sensible default values for all inputs
- Document all inputs and outputs
- Include usage examples in this README