-
Notifications
You must be signed in to change notification settings - Fork 995
165 lines (140 loc) · 4.58 KB
/
Copy pathslate-deps-pr.yml
File metadata and controls
165 lines (140 loc) · 4.58 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: SlateDepsSync
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
permissions:
contents: write
concurrency:
group: slate-deps-sync
cancel-in-progress: false
jobs:
update:
name: Update Slate deps
runs-on: ubuntu-latest
if: ${{ github.repository == 'udecode/plate' }}
steps:
- name: 📥 Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.API_TOKEN_GITHUB || secrets.GITHUB_TOKEN }}
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.9
- name: ⚙️ Install pnpm
uses: pnpm/action-setup@v4
- name: ♻️ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: ⬆️ Update Slate manifests
run: >
npx npm-check-updates@latest
'/^(slate|slate-dom|slate-react|slate-hyperscript)$/'
--configFileName .ncurc.yml
--configFilePath tooling/config
--mergeConfig
--packageManager pnpm
--root
--upgrade
--workspaces
- name: 📦 Install updated deps
run: pnpm install --no-frozen-lockfile
env:
HUSKY: '0'
- name: 🔍 Detect Slate update changes
id: slate-changes
run: |
node <<'EOF'
const { execFileSync } = require('node:child_process');
const { appendFileSync, readFileSync } = require('node:fs');
const files = [
'apps/www/package.json',
'packages/core/package.json',
'packages/slate/package.json',
'packages/test-utils/package.json',
];
const sections = [
'dependencies',
'devDependencies',
'peerDependencies',
'optionalDependencies',
];
const targets = [
'slate',
'slate-dom',
'slate-react',
'slate-hyperscript',
];
const changed = new Set();
const readHeadPackageJson = (file) => {
try {
return JSON.parse(
execFileSync('git', ['show', `HEAD:${file}`], {
encoding: 'utf8',
})
);
} catch {
return {};
}
};
for (const file of files) {
const current = JSON.parse(readFileSync(file, 'utf8'));
const previous = readHeadPackageJson(file);
for (const section of sections) {
for (const dependency of targets) {
const currentVersion = current[section]?.[dependency];
const previousVersion = previous[section]?.[dependency];
if (currentVersion !== previousVersion) {
changed.add(dependency);
}
}
}
}
const packages = [...changed];
appendFileSync(
process.env.GITHUB_OUTPUT,
`changed=${packages.length > 0}\n`
);
appendFileSync(
process.env.GITHUB_OUTPUT,
`packages_json<<EOF\n${JSON.stringify(packages)}\nEOF\n`
);
EOF
- name: 📝 Sync Slate changeset
if: ${{ steps.slate-changes.outputs.changed == 'true' }}
env:
CHANGED_PACKAGES_JSON: ${{ steps.slate-changes.outputs.packages_json }}
run: |
if [ -f .changeset/slate.md ]; then
echo "Updating existing .changeset/slate.md"
else
echo "Creating .changeset/slate.md"
fi
node <<'EOF'
const { writeFileSync } = require('node:fs');
const packages = JSON.parse(process.env.CHANGED_PACKAGES_JSON);
const message = `Updated ${packages.map((name) => `\`${name}\``).join(', ')}.`;
writeFileSync(
'.changeset/slate.md',
`---\n"@platejs/slate": patch\n---\n\n${message}\n`
);
EOF
- name: 🔧 Configure git
if: ${{ steps.slate-changes.outputs.changed == 'true' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: ⬆️ Push Slate update
if: ${{ steps.slate-changes.outputs.changed == 'true' }}
run: |
git add .
if git diff --cached --quiet; then
echo "No staged changes."
exit 0
fi
git commit -m "chore: update"
git push origin HEAD:main