Repository navigation
141 lines (135 loc) · 5.35 KB
/
Copy pathrelease.yml
File metadata and controls
141 lines (135 loc) · 5.35 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
name: Release
# Push a tag v<version> matching plugin.json to publish a GitHub Release.
# Lithe Store automatically tracks stable releases of eligible plugins.
on:
push:
tags: ["v*"]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
# GitHub only exposes draft releases to callers with push access.
contents: write
outputs:
exists: ${{ steps.release.outputs.exists }}
steps:
- name: Check whether the release already exists
id: release
env:
GH_TOKEN: ${{ github.token }}
run: |
state=$(gh api graphql \
-f query='query($owner: String!, $repo: String!, $tag: String!) {
repository(owner: $owner, name: $repo) {
release(tagName: $tag) { isDraft }
}
}' \
-f owner="$GITHUB_REPOSITORY_OWNER" -f repo="${GITHUB_REPOSITORY#*/}" -f tag="$GITHUB_REF_NAME" \
--jq '.data.repository |
if . == null then "unavailable"
elif .release == null then "missing"
elif .release.isDraft == true then "draft"
elif .release.isDraft == false then "published"
else "unavailable"
end')
case "$state" in
missing) echo "exists=false" >> "$GITHUB_OUTPUT" ;;
published) echo "exists=true" >> "$GITHUB_OUTPUT" ;;
draft)
echo "::error::A draft release exists for $GITHUB_REF_NAME. Review it and resolve the draft before rerunning."
exit 1
;;
*)
echo "::error::Could not determine the release state for $GITHUB_REF_NAME."
exit 1
;;
esac
package:
needs: check
if: needs.check.outputs.exists == 'false'
uses: ./.github/workflows/package.yml
with:
tag: ${{ github.ref_name }}
release:
needs: [check, package]
if: needs.check.outputs.exists == 'false'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: actions/download-artifact@v4
with:
pattern: python-support-archive-*
merge-multiple: true
path: dist
- name: Verify the six release archives
env:
LITHE_EXPECT_ALL_ARCHIVES: "1"
run: node --test --test-timeout=60000 scripts/package/*.test.mjs
- name: Set up optional delta generation
continue-on-error: true
run: command -v zstd || sudo apt-get install -y zstd
- name: Publish GitHub Release
env:
GH_TOKEN: ${{ github.token }}
PRERELEASE_TAGS: v0.1.0 v0.1.1 v1.2.0
run: |
release_flags=()
installation='Lithe Store 会在收录后提供此版本。打开 设置 → 插件 → 插件市场,搜索 Python Support。'
for tag in $PRERELEASE_TAGS; do
if [[ "$tag" == "$GITHUB_REF_NAME" ]]; then
release_flags+=(--prerelease)
installation='下载对应平台的 ZIP。打开 设置 → 插件 → 从文件安装…,核对 SHA-256 后确认。'
break
fi
done
if (( ${#release_flags[@]} == 0 )); then
if curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' \
--max-time 20 --max-filesize 5242880 \
-o "$RUNNER_TEMP/store-index.json" \
https://raw.githubusercontent.com/Lithe-IDEA/Lithe-store/HEAD/lithe-plugin-index.json &&
bash scripts/package/release-deltas.sh "$RUNNER_TEMP/store-index.json" dist "${GITHUB_REF_NAME#v}"; then
echo "Checked for optional plugin deltas."
else
echo "::warning::Could not prepare optional patches; publishing full ZIPs."
fi
fi
shopt -s nullglob
patches=(dist/*.zip.zst)
notes="docs/releases/$GITHUB_REF_NAME.md"
test -s "$notes"
{
cat "$notes"
echo
echo "$installation"
echo
echo 'SHA-256'
echo
echo '```'
(cd dist && sha256sum ./*.zip)
echo '```'
} > "$RUNNER_TEMP/notes.md"
# The artifacts came from the event checkout even if the remote tag has since moved.
packaged_commit=$(git rev-parse HEAD)
if ! remote_tag=$(git ls-remote --exit-code origin "$GITHUB_REF" "$GITHUB_REF^{}"); then
echo "::error::Could not resolve release tag $GITHUB_REF_NAME on origin. Check the tag before retrying."
exit 1
fi
remote_commit=$(awk -v ref="$GITHUB_REF" '
$2 == ref { object = $1 }
$2 == ref "^{}" { peeled = $1 }
END { print (peeled != "" ? peeled : object) }
' <<< "$remote_tag")
if [[ "$remote_commit" != "$packaged_commit" ]]; then
echo "::error::Release tag $GITHUB_REF_NAME no longer points to the packaged commit. Use the run for the current tag."
exit 1
fi
gh release create "$GITHUB_REF_NAME" dist/*.zip "${patches[@]}" --verify-tag --title "Python Support $GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" "${release_flags[@]}"