Repository navigation
216 lines (190 loc) · 7.66 KB
/
Copy pathci.yml
File metadata and controls
216 lines (190 loc) · 7.66 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: CI
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check:
name: ${{ matrix.os }} · node ${{ matrix.node }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Windows and macOS are both first-class targets, and the path,
# line-ending and process-signal behaviour genuinely differs between
# them — so both are tested rather than assumed.
os: [ubuntu-latest, windows-latest, macos-latest]
# Node 22 is the oldest release with a built-in SQLite driver, so the
# session tests only have full coverage from there upwards.
node: [20, 22, 24]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: npm
- name: Configure git identity
run: |
git config --global user.name "CI"
git config --global user.email "ci@example.com"
git config --global init.defaultBranch main
- run: npm ci
- run: npm run lint
- run: npm run typecheck
- run: npm test
- run: npm run build
installer:
# The only place a real scheduled job is ever registered: disposable
# runners. Installs the packed checkout through the real installer, links
# a local bare repository with every root redirected into the runner's
# temp directory, then installs, runs and removes the scheduler entry.
name: installer · ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: check
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
env:
OPENCODE_SYNC_NO_GH: "1"
OPENCODE_SYNC_NO_STAGGER: "1"
OPENCODE_SYNC_LANG: en
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- name: Configure git identity
shell: bash
run: |
git config --global user.name "CI"
git config --global user.email "ci@example.com"
git config --global init.defaultBranch main
- name: Build and pack the checkout
shell: bash
run: |
npm ci
npm run build
npm pack
pkg="$(pwd)/$(ls opencode-github-sync-*.tgz)"
if [ "$RUNNER_OS" = "Windows" ]; then pkg=$(cygpath -w "$pkg"); fi
echo "PKG=$pkg" >> "$GITHUB_ENV"
- name: Isolated roots and a local bare repository
shell: bash
run: |
base="$RUNNER_TEMP/ogs"
mkdir -p "$base/home" "$base/config"
git init -q --bare -b main "$base/remote.git"
printf '{ "model": "ci" }\n' > "$base/config/opencode.jsonc"
{
echo "SYNC_CONFIG_ROOT=$base/config"
echo "SYNC_DATA_ROOT=$base/data"
echo "SYNC_STATE_ROOT=$base/state"
echo "SYNC_AGENTS_ROOT=$base/agents/skills"
echo "SYNC_CACHE_ROOT=$base/cache"
echo "SYNC_HOME=$base/home"
echo "OGS_REMOTE=$base/remote.git"
echo "OGS_LOG=$base/config/logs/opencode-sync-autosync.log"
} >> "$GITHUB_ENV"
- name: Run install.sh non-interactively
if: runner.os != 'Windows'
shell: bash
run: sh install.sh --mode link --repo "$OGS_REMOTE" --interval 5 --lang en --package "$PKG" --yes </dev/null
- name: install.ps1 parses and plans under Windows PowerShell 5.1
if: runner.os == 'Windows'
shell: powershell
run: ./install.ps1 -DryRun -Mode auto -Repo o/r
- name: Run install.ps1 non-interactively
if: runner.os == 'Windows'
shell: pwsh
run: ./install.ps1 -Mode link -Repo $env:OGS_REMOTE -Interval 5 -Lang en -Package $env:PKG -Yes
- name: The first sync landed in the bare repository
shell: bash
run: git --git-dir="$OGS_REMOTE" log --oneline -1 | grep -q sync
- name: autosync enable registers the scheduler entry
shell: bash
run: |
opencode-sync autosync enable
opencode-sync autosync status
case "$RUNNER_OS" in
Windows) schtasks //Query //TN opencode-github-sync ;;
macOS) test -f "$HOME/Library/LaunchAgents/com.opencode-github-sync.autosync.plist"
launchctl list | grep -q com.opencode-github-sync.autosync ;;
Linux) systemctl --user is-enabled opencode-github-sync.timer 2>/dev/null \
|| crontab -l | grep -q "opencode-github-sync autosync" ;;
esac
- name: The scheduler actually starts the job
shell: bash
run: |
if [ "$RUNNER_OS" = "Windows" ]; then schtasks //Run //TN opencode-github-sync; fi
if [ "$RUNNER_OS" = "Linux" ]; then
if systemctl --user is-enabled opencode-github-sync.timer >/dev/null 2>&1; then
systemctl --user start opencode-github-sync.service || true
else
echo "cron fallback: not waiting for the next minute boundary"; exit 0
fi
fi
for _ in $(seq 1 45); do
if grep -q "scheduled:" "$OGS_LOG" 2>/dev/null; then cat "$OGS_LOG"; exit 0; fi
sleep 2
done
echo "the scheduled job did not write to $OGS_LOG"
cat "$OGS_LOG" 2>/dev/null || true
cat "$SYNC_CONFIG_ROOT/logs/autosync-launchd.log" 2>/dev/null || true
if [ "$RUNNER_OS" = "Windows" ]; then
# An InteractiveToken task needs a signed-in desktop session, which
# a hosted runner may not provide. Report what Task Scheduler saw.
powershell -NoProfile -Command "Get-ScheduledTaskInfo -TaskName opencode-github-sync | Format-List"
echo "::warning::Task Scheduler did not start the job in this runner session"
exit 0
fi
exit 1
- name: autosync run
shell: bash
run: |
opencode-sync autosync run --trigger ci
grep "ci:" "$OGS_LOG"
- name: autosync uninstall removes the scheduler entry
shell: bash
run: |
opencode-sync autosync uninstall
case "$RUNNER_OS" in
Windows) ! schtasks //Query //TN opencode-github-sync >/dev/null 2>&1 ;;
macOS) test ! -f "$HOME/Library/LaunchAgents/com.opencode-github-sync.autosync.plist"
! launchctl list | grep -q com.opencode-github-sync.autosync ;;
Linux) ! systemctl --user is-enabled opencode-github-sync.timer >/dev/null 2>&1
! crontab -l 2>/dev/null | grep -q "opencode-github-sync autosync" ;;
esac
shellcheck:
name: shellcheck install.sh
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: shellcheck -s sh install.sh
package:
name: package contents
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm run build
- name: Verify the published tarball
run: |
npm pack --dry-run
# The plugin and CLI entry points must both survive packing.
test -f dist/plugin/index.js
test -f dist/cli/index.js
test -f dist/core/index.js
# Installers and README images are served from GitHub, not npm.
files=$(npm pack --dry-run --json | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>console.log(JSON.parse(s)[0].files.map(f=>f.path).join("\n")))')
! echo "$files" | grep -E '^(install\.(sh|ps1)|docs/)'