chore: do not deploy chromatic on draft PR #66
This file contains 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: "Chromatic Deployment" | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
types: [opened, synchronize, ready_for_review] | |
branches: [main] | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
check_conditions: | |
name: "Check Conditions" | |
runs-on: ubuntu-latest | |
outputs: | |
should_run: ${{ steps.set_output.outputs.should_run }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Determine if deployment should proceed | |
id: set_output | |
run: | | |
should_run=false | |
if [[ "${{ github.event_name }}" == "push" || "${{ github.event.pull_request.draft }}" == "false" ]]; then | |
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '\.(mdx|tsx|ts|css|svg|png|jpg|jpeg)$'; then | |
echo "Deploying. Relevant file changes detected." | |
should_run=true | |
else | |
echo "Not deploying. No relevant file changes detected." | |
fi | |
else | |
echo "Not deploying. Not a push or non-draft PR." | |
fi | |
echo "::set-output name=should_run::$should_run" | |
deploy_chromatic: | |
name: "Run Chromatic" | |
runs-on: ubuntu-latest | |
needs: check_conditions | |
if: needs.check_conditions.outputs.should_run == 'true' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 9 | |
run_install: false | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: ".nvmrc" | |
cache: "pnpm" | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile # Install dependencies with lockfile's versions to ensure consistency | |
- name: Cache Build | |
id: cache-build | |
uses: actions/cache@v4 | |
with: | |
path: dist | |
key: ${{ runner.os }}-build-${{ hashFiles('**/*.ts', '**/*.tsx', '**/*.mdx') }} # Cache key based on OS and file hashes | |
restore-keys: | | |
${{ runner.os }}-build- | |
- name: Build | |
if: steps.cache-build.outputs.cache-hit != 'true' | |
run: pnpm build | |
- uses: chromaui/action@v11 | |
with: | |
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
diagnostics: true | |
exitZeroOnChanges: true |