-
-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (93 loc) · 2.98 KB
/
format-and-docs.yml
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Format and Docs
on:
push:
# branches: [ 'master', 'main', 'v[0-9]*' ]
pull_request:
# branches: [ 'master', 'main', 'v[0-9]*' ]
jobs:
format:
if: github.event_name != 'push' || !github.event.deleted
runs-on: ubuntu-latest
steps:
# NOTE: Be mindful of what gets checked-out for pr events!
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: package.json
check-latest: true
- run: npm i -g "npm@$(npm pkg get engines.npm | grep -Eom 1 '[^"]+')"
- run: npm ci
- run: npm run format
- name: Log Summary/Diff
id: diff
run: |
git add -A
files="$(git diff --staged --name-status)"
delim="$RANDOM"
printf '%s\n%s\n%s\n' "files<<$delim" "$files" "$delim" >> "$GITHUB_OUTPUT"
cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
# Diff
~~~~~~~~~diff
${files:-No changes.}
$(git diff --staged --exit-code ||
{ echo 'HAS_CHANGES=1' >> "$GITHUB_ENV"; })
~~~~~~~~~
EOF
- uses: peter-evans/create-pull-request@v5
# Don't want 2 similar pr's open and don't want to commit changes from
# pr's merge commit.
if: github.event_name != 'pull_request'
with:
branch: pr/${{ github.ref_name }}/format
title: 'fmt: format files with prettier'
body: |
~~~~~
${{ steps.diff.outputs.files }}
~~~~~
commit-message: 'fmt: format files with prettier'
delete-branch: true
- name: Confirm No Formatting Errors
if: env.HAS_CHANGES
run: echo '::error::Formatting errors detected, please reformat'; exit 1
docs:
needs: format
if: github.event_name != 'push' || !github.event.deleted
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: package.json
check-latest: true
- run: npm i -g "npm@$(npm pkg get engines.npm | grep -Eom 1 '[^"]+')"
- run: npm ci
- run: npm run build-docs
- name: Log Summary/Diff
id: diff
run: |
git add -A
files="$(git diff --staged --name-status)"
delim="$RANDOM"
printf '%s\n%s\n%s\n' "files<<$delim" "$files" "$delim" >> "$GITHUB_OUTPUT"
cat >> "$GITHUB_STEP_SUMMARY" <<-EOF
# Diff
~~~~~~~~~diff
${files:-No changes.}
$(git diff --staged --exit-code ||
{ echo 'HAS_CHANGES=1' >> "$GITHUB_ENV"; })
~~~~~~~~~
EOF
- uses: peter-evans/create-pull-request@v5
if: github.event_name != 'pull_request'
with:
branch: pr/${{ github.ref_name }}/docs
title: 'docs: build docs'
body: |
~~~~~
${{ steps.diff.outputs.files }}
~~~~~
commit-message: 'docs: build docs'
delete-branch: true
- name: Confirm Docs Are Up-To-Date
if: env.HAS_CHANGES
run: echo '::error::Outdated docs, please rebuild'; exit 1