-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
194 lines (171 loc) · 6.78 KB
/
Copy pathTaskfile.yml
File metadata and controls
194 lines (171 loc) · 6.78 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
# Taskfile.yml - build the minimal submodule release branch.
#
# Why this exists:
# - Consuming repositories should add only the OpenCode shared workspace files as
# a git submodule, without local devcontainer files, generated files, or nested
# checkout metadata.
# - `task release-build` creates a normal commit on the release branch in a
# temporary worktree, updates the local release ref, and pushes it so the
# current branch and dirty worktree stay untouched while release history stays
# reviewable. The first release for a new remote is bootstrapped as an orphan.
# - `task test-release` builds the same file bundle in a temporary directory and
# starts OpenCode from there without creating commits, branches, or pushes.
#
# Inputs:
# - RELEASE_BRANCH: target branch name, defaults to `release`.
# - RELEASE_REMOTE: target remote name or URL, defaults to `origin`.
# - RELEASE_SOURCE: source revision used for validation, defaults to `HEAD`.
# - RELEASE_WORKTREE: temporary worktree path, defaults to `.release-build`.
# - TEST_RELEASE_DIR: optional temp directory for `test-release`.
# - TEST_RELEASE_KEEP: set to `1` to keep the temp directory after `test-release`.
#
# Related files:
# - README_release.md copied as README.md, LICENSE, opencode.json,
# playwright-mcp.json, ai-scripts/, commands/, rules/, skills/, plugin/
# - INDEX.md is intentionally excluded from RELEASE_PATHS because it belongs to
# the consuming repository root, not the generated .opencode submodule.
version: '3'
vars:
RELEASE_BRANCH: '{{default "release" .RELEASE_BRANCH}}'
RELEASE_REMOTE: '{{default "origin" .RELEASE_REMOTE}}'
RELEASE_SOURCE: '{{default "HEAD" .RELEASE_SOURCE}}'
RELEASE_WORKTREE: '{{default ".release-build" .RELEASE_WORKTREE}}'
RELEASE_PATHS: README_release.md LICENSE opencode.json playwright-mcp.json ai-scripts commands rules skills plugin
TEST_RELEASE_DIR: '{{default "" .TEST_RELEASE_DIR}}'
tasks:
test:
desc: Run the repository test suite
vars:
TEST_RELEASE_COPY_TARGET:
sh: mktemp -d /tmp/opencode-release-copy-test.XXXXXX
cmds:
- defer: rm -rf '{{.TEST_RELEASE_COPY_TARGET}}'
- task: release-copy
vars:
RELEASE_TARGET: '{{.TEST_RELEASE_COPY_TARGET}}'
- bash tests/release-copy.sh '{{.TEST_RELEASE_COPY_TARGET}}'
release-copy:
internal: true
desc: Copy release files into RELEASE_TARGET without git writes
cmds:
- |
bash -euo pipefail <<'BASH'
source='{{.RELEASE_SOURCE}}'
target='{{.RELEASE_TARGET}}'
if [ -z "${target}" ]; then
printf 'RELEASE_TARGET is required.\n' >&2
exit 1
fi
if [ ! -d "${target}" ]; then
printf 'Release target does not exist: %s\n' "${target}" >&2
exit 1
fi
git rev-parse --verify --quiet "${source}^{commit}" >/dev/null
tar -c {{.RELEASE_PATHS}} | tar -x -C "${target}"
mv "${target}/README_release.md" "${target}/README.md"
cat >"${target}/.gitignore" <<'GITIGNORE'
node_modules/
bun.lock
package.json
package-lock.json
GITIGNORE
BASH
release-build:
desc: Build a release branch commit containing only submodule files
cmds:
- |
bash -euo pipefail <<'BASH'
branch='{{.RELEASE_BRANCH}}'
source='{{.RELEASE_SOURCE}}'
remote='{{.RELEASE_REMOTE}}'
worktree='{{.RELEASE_WORKTREE}}'
build_branch="release-build-${branch}-$$"
release_ref="refs/tmp/release-build/${branch}"
if [ -e "${worktree}" ]; then
printf 'Release worktree path already exists: %s\n' "${worktree}" >&2
printf 'Remove it or set RELEASE_WORKTREE to another path.\n' >&2
exit 1
fi
git rev-parse --verify --quiet "${source}^{commit}" >/dev/null
if git ls-remote --exit-code "${remote}" "refs/heads/${branch}" >/dev/null 2>&1; then
git fetch "${remote}" "+refs/heads/${branch}:${release_ref}"
git worktree add -B "${build_branch}" "${worktree}" "${release_ref}"
(
cd "${worktree}"
git rm -rf --quiet --ignore-unmatch .
git clean -fdx --quiet
)
else
git worktree add --detach "${worktree}" "${source}"
(
cd "${worktree}"
git checkout --orphan "${build_branch}"
git rm -rf --cached --quiet --ignore-unmatch .
git clean -fdx --quiet
)
fi
BASH
- defer: |
bash -euo pipefail <<'BASH'
worktree='{{.RELEASE_WORKTREE}}'
build_branch='release-build-{{.RELEASE_BRANCH}}-'
release_ref='refs/tmp/release-build/{{.RELEASE_BRANCH}}'
git worktree remove --force "${worktree}" >/dev/null 2>&1 || true
git update-ref -d "${release_ref}" >/dev/null 2>&1 || true
for branch in $(git for-each-ref --format='%(refname:short)' refs/heads/"${build_branch}"'*'); do
git branch --delete --force "${branch}" >/dev/null 2>&1 || true
done
BASH
- task: release-copy
vars:
RELEASE_TARGET: '{{.RELEASE_WORKTREE}}'
- |
bash -euo pipefail <<'BASH'
branch='{{.RELEASE_BRANCH}}'
remote='{{.RELEASE_REMOTE}}'
worktree='{{.RELEASE_WORKTREE}}'
(
cd "${worktree}"
git add .
if git diff --cached --quiet; then
printf 'Release branch already matches the source bundle.\n'
else
git commit -m "chore(release): build submodule release"
fi
)
commit=$(git -C "${worktree}" rev-parse HEAD)
git branch --force "${branch}" "${commit}"
git push -u "${remote}" "${branch}"
printf 'Built release branch: %s\n' "${branch}"
printf 'Pushed release branch to %s/%s\n' "${remote}" "${branch}"
BASH
test-release:
desc: Copy release files into a temp directory and start OpenCode
vars:
TEST_RELEASE_TARGET:
sh: |
if [ -n '{{.TEST_RELEASE_DIR}}' ]; then
mkdir -p '{{.TEST_RELEASE_DIR}}'
printf '%s' '{{.TEST_RELEASE_DIR}}'
else
mktemp -d /tmp/opencode-release-test.XXXXXX
fi
cmds:
- defer: |
bash -euo pipefail <<'BASH'
target='{{.TEST_RELEASE_TARGET}}'
if [ "${TEST_RELEASE_KEEP:-0}" = "1" ]; then
printf 'Kept test release directory: %s\n' "${target}"
else
rm -rf "${target}"
fi
BASH
- task: release-copy
vars:
RELEASE_TARGET: '{{.TEST_RELEASE_TARGET}}'
- |
bash -euo pipefail <<'BASH'
target='{{.TEST_RELEASE_TARGET}}'
printf 'Starting OpenCode with test release bundle: %s\n' "${target}"
opencode "${target}"
BASH