-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (78 loc) · 2.52 KB
/
validate-story.yml
File metadata and controls
89 lines (78 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: validate-story
on:
workflow_dispatch:
pull_request:
push:
branches: [main]
jobs:
detect:
name: Detect non-markdown changes
runs-on: ubuntu-latest
outputs:
run_validate: ${{ steps.detect.outputs.run_validate }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine base ref
id: base
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "base=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
elif [ -n "${{ github.event.before }}" ] && [ "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]; then
echo "base=${{ github.event.before }}" >> "$GITHUB_OUTPUT"
else
if git rev-parse HEAD^ >/dev/null 2>&1; then
echo "base=$(git rev-parse HEAD^)" >> "$GITHUB_OUTPUT"
else
echo "base=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
fi
fi
- name: Detect non-markdown changes
id: detect
run: |
set -euo pipefail
base_ref="${{ steps.base.outputs.base }}"
changed_files=$(git diff --name-only "$base_ref"...HEAD || true)
if [ -z "$changed_files" ]; then
run_validate=true
else
non_md=$(printf "%s\n" "$changed_files" | grep -vE '\.md$' || true)
if [ -z "$non_md" ]; then
run_validate=false
else
run_validate=true
fi
fi
{
echo "run_validate=${run_validate}"
printf 'changed_files<<EOF\n%s\nEOF\n' "$changed_files"
} >> "$GITHUB_OUTPUT"
validate:
needs: detect
if: needs.detect.outputs.run_validate == 'true'
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Prepare results dir
run: mkdir -p results
- name: Run validate-story
run: node scripts/validate-story.js --glob "web/stories/**/*.ink" --max-steps 500 --output results/validate-story.json
- name: Upload results
if: failure() || always()
uses: actions/upload-artifact@v4
with:
name: validate-story-results
path: results/**
if-no-files-found: ignore