Repository navigation
276 lines (260 loc) · 11.3 KB
/
Copy pathrelease.yml
File metadata and controls
276 lines (260 loc) · 11.3 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Release
# Builds the Dify plugin package (diffbot-<version>.difypkg) and publishes it on a
# GitHub Release, which is what Dify's "Install plugin from GitHub" reads.
#
# Contract:
# - Pushing a tag vX.Y.Z (or vX.Y.Z-rc.N) runs verify -> gates -> package ->
# github-release. The tag must equal `version` in diffbot/manifest.yaml, which must
# equal `[project] version` in diffbot/pyproject.toml, and CHANGELOG.md must have a
# "## [X.Y.Z]" section. The release notes are that section. A version containing "-"
# is a prerelease: it may reuse the base "## [X.Y.Z]" section and its GitHub Release
# is marked Pre-release.
# - workflow_dispatch is a dry run: verify, gates and package run and the .difypkg is
# uploaded as a workflow artifact. A dispatch never creates or edits a GitHub
# Release, even on a tag ref.
# - Official .difypkg files come only from this workflow. Nobody commits one (dist/ is
# gitignored) or attaches a hand-built one to a release.
# - This workflow does NOT submit to the Dify Marketplace (that is the manual
# SUBMISSION.md runbook) and does NOT sign the package (Dify signs marketplace
# builds after review). No secrets are used; tests are offline (httpx.MockTransport).
#
# Shared ideas (CHANGELOG-driven notes, --prerelease for "-" versions, dispatch dry
# run) follow the diffbot npm release standard; see diffbot-dev-docs
# docs/conventions/dify-plugin-release.md for this repo's standard.
on:
push:
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
# A release run is never cancelled halfway; re-runs for the same ref queue.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify version
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
# manifest.yaml is the source of truth; pyproject.toml and the tag must agree.
# Only the top-level (unindented) `version:` is read: meta.version is the manifest
# schema version and meta.runner.version is Python, neither is the plugin version.
- name: Check tag matches plugin version
id: version
run: |
set -euo pipefail
manifest=$(sed -n 's/^version:[[:space:]]*//p' diffbot/manifest.yaml | tr -d "\"' \r")
if [ -z "$manifest" ] || [ "$(printf '%s\n' "$manifest" | wc -l)" -ne 1 ]; then
echo "::error::Could not read a single top-level version from diffbot/manifest.yaml."
exit 1
fi
if ! printf '%s' "$manifest" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error::diffbot/manifest.yaml version '${manifest}' is not like 1.2.3 or 1.2.3-rc.0."
exit 1
fi
pyproject=$(python3 -c 'import tomllib; print(tomllib.load(open("diffbot/pyproject.toml", "rb"))["project"]["version"])')
if [ "$manifest" != "$pyproject" ]; then
echo "::error::diffbot/manifest.yaml version ${manifest} does not match diffbot/pyproject.toml version ${pyproject}."
exit 1
fi
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
tag=${GITHUB_REF_NAME#v}
if [ "$manifest" != "$tag" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} does not match plugin version ${manifest}. Bump diffbot/manifest.yaml and diffbot/pyproject.toml, then re-tag."
exit 1
fi
fi
echo "version=${manifest}" >> "$GITHUB_OUTPUT"
echo "Versions agree: ${manifest}"
# Checked before the gates so a tag without release notes fails within seconds.
# Headings are Keep a Changelog style, matched at the start of the line, so a
# non-version heading such as "## Earlier, ..." never counts.
- name: Check CHANGELOG.md has a section for this version
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
has_section() {
awk -v hdr="## [$1]" 'index($0, hdr) == 1 { found = 1 } END { exit !found }' CHANGELOG.md
}
# A prerelease (0.2.1-rc.0) may reuse its base version's section (0.2.1).
if has_section "${VERSION}"; then
hdr_version="${VERSION}"
elif [ "${VERSION%%-*}" != "${VERSION}" ] && has_section "${VERSION%%-*}"; then
hdr_version="${VERSION%%-*}"
echo "Prerelease ${VERSION}: using the '## [${hdr_version}]' section."
else
echo "::error::CHANGELOG.md has no '## [${VERSION}]' section."
exit 1
fi
body=$(awk -v hdr="## [${hdr_version}]" '
index($0, hdr) == 1 { found = 1; next }
found && /^## / { exit }
found { print }
' CHANGELOG.md)
if ! printf '%s' "$body" | grep -q '[^[:space:]]'; then
echo "::error::CHANGELOG.md section '## [${hdr_version}]' is empty."
exit 1
fi
echo "Found '## [${hdr_version}]'."
# Same commands as test.yml. Offline only: no live tests, no secrets.
gates:
name: Gates (pytest)
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-python@v7
with:
python-version: "3.12"
cache: pip
cache-dependency-path: diffbot/requirements.txt
- run: pip install -r diffbot/requirements.txt pytest
- run: pytest -q
package:
name: Package .difypkg
needs: [verify, gates]
runs-on: ubuntu-latest
timeout-minutes: 10
env:
# Pinned dify CLI from https://github.com/langgenius/dify-plugin-daemon/releases.
# The release publishes no checksum file; the SHA256 is the asset digest GitHub
# reports for dify-plugin-linux-amd64. To bump (see the dev-docs standard):
# gh release view <tag> --repo langgenius/dify-plugin-daemon \
# --json assets --jq '.assets[] | select(.name=="dify-plugin-linux-amd64") | .digest'
# then update both values here in one PR and dispatch a dry run.
DIFY_CLI_VERSION: "0.6.15"
DIFY_CLI_SHA256: "d0a1e3b25bd6c5f6cd749cad2cf04817ea808344e6cc07a2c49bb0108019ab93"
VERSION: ${{ needs.verify.outputs.version }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install pinned dify CLI
run: |
set -euo pipefail
bin="${RUNNER_TEMP}/bin"
mkdir -p "$bin"
curl -fsSL --retry 3 -o "${bin}/dify" \
"https://github.com/langgenius/dify-plugin-daemon/releases/download/${DIFY_CLI_VERSION}/dify-plugin-linux-amd64"
echo "${DIFY_CLI_SHA256} ${bin}/dify" | sha256sum -c -
chmod +x "${bin}/dify"
echo "$bin" >> "$GITHUB_PATH"
"${bin}/dify" version
- name: Build package
run: |
set -euo pipefail
dify plugin package ./diffbot -o "diffbot-${VERSION}.difypkg"
# Sanity checks: the file exists, has a plausible size (the 0.1.0 package was
# about 49 KB), contains the manifest, and contains nothing that .difyignore
# should have kept out.
- name: Check package
run: |
set -euo pipefail
pkg="diffbot-${VERSION}.difypkg"
size=$(stat -c %s "$pkg")
if [ "$size" -lt 10240 ] || [ "$size" -gt 10485760 ]; then
echo "::error::${pkg} is ${size} bytes; expected between 10 KiB and 10 MiB."
exit 1
fi
files=$(unzip -Z1 "$pkg")
if ! printf '%s\n' "$files" | grep -qx 'manifest.yaml'; then
echo "::error::${pkg} has no top-level manifest.yaml."
exit 1
fi
if printf '%s\n' "$files" | grep -E '(^|/)(\.env|\.git/.*|\.venv/.*|__pycache__/.*|[^/]*\.pem)$'; then
echo "::error::${pkg} contains files that must not ship (listed above)."
exit 1
fi
sha=$(sha256sum "$pkg" | cut -d' ' -f1)
# The CLI logs "plugin checksum checksum=<hex>" on stderr.
dify_checksum=$(dify plugin checksum "$pkg" 2>&1 | sed -n 's/.*checksum=\([0-9a-f]\{64\}\).*/\1/p')
if [ -z "$dify_checksum" ]; then
echo "::error::Could not read a checksum from 'dify plugin checksum'."
exit 1
fi
{
echo "### ${pkg}"
echo ""
echo "- Size: ${size} bytes, $(printf '%s\n' "$files" | wc -l) files"
echo "- SHA256: \`${sha}\`"
echo "- \`dify plugin checksum\`: \`${dify_checksum}\`"
echo "- dify CLI: ${DIFY_CLI_VERSION}"
} >> "$GITHUB_STEP_SUMMARY"
cat "$GITHUB_STEP_SUMMARY"
- uses: actions/upload-artifact@v7
with:
name: difypkg
path: diffbot-${{ needs.verify.outputs.version }}.difypkg
if-no-files-found: error
retention-days: 30
github-release:
name: Publish GitHub Release
needs: [verify, package]
runs-on: ubuntu-latest
timeout-minutes: 5
# Only for real tag pushes; a workflow_dispatch (even on a tag ref) stops at package.
if: github.event_name == 'push' && github.ref_type == 'tag'
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/download-artifact@v8
with:
name: difypkg
path: ${{ runner.temp }}/difypkg
- name: Extract release notes from CHANGELOG.md
env:
VERSION: ${{ needs.verify.outputs.version }}
run: |
set -euo pipefail
# Everything after "## [VERSION]" up to the next "## " heading. A prerelease
# without its own section uses its base version's section.
hdr_version="${VERSION}"
if ! awk -v hdr="## [${VERSION}]" 'index($0, hdr) == 1 { found = 1 } END { exit !found }' CHANGELOG.md; then
hdr_version="${VERSION%%-*}"
fi
awk -v hdr="## [${hdr_version}]" '
index($0, hdr) == 1 { found = 1; next }
found && /^## / { exit }
found { print }
' CHANGELOG.md > "${RUNNER_TEMP}/notes.md"
if ! grep -q '[^[:space:]]' "${RUNNER_TEMP}/notes.md"; then
echo "::error::CHANGELOG.md section for ${VERSION} is empty."
exit 1
fi
wc -l "${RUNNER_TEMP}/notes.md"
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.verify.outputs.version }}
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
repo="${GITHUB_REPOSITORY}"
pkg="${RUNNER_TEMP}/difypkg/diffbot-${VERSION}.difypkg"
test -s "$pkg"
if gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
echo "Release $tag already exists; leaving its notes as they are and re-uploading the package."
gh release upload "$tag" "$pkg" --repo "$repo" --clobber
exit 0
fi
prerelease=()
case "$VERSION" in *-*) prerelease=(--prerelease) ;; esac
gh release create "$tag" "$pkg" \
--repo "$repo" \
--title "$tag" \
--verify-tag \
--notes-file "${RUNNER_TEMP}/notes.md" \
"${prerelease[@]}"