-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (146 loc) · 5.27 KB
/
Copy pathrelease.yml
File metadata and controls
162 lines (146 loc) · 5.27 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
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: write
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Determine version
id: version
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
tag="${GITHUB_REF_NAME}"
version="${tag#v}"
else
# Auto-increment patch from latest tag.
latest=$(git tag -l 'v*' --sort=-v:refname | head -n1)
if [ -z "$latest" ]; then
version="1.0.0"
else
base="${latest#v}"
IFS='.' read -r major minor patch <<< "$base"
patch=$((patch + 1))
version="${major}.${minor}.${patch}"
fi
tag="v${version}"
# Update manifest.json so the catalog tool sees the correct version.
jq --arg v "$version" '.version = $v' manifest.json > manifest.tmp && mv manifest.tmp manifest.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add manifest.json
git commit -m "chore: bump version to ${version} [skip ci]"
git tag "$tag"
git push origin HEAD:main --tags
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
build:
needs: version
strategy:
matrix:
include:
- os: ubuntu-latest
goos: linux
goarch: amd64
- os: ubuntu-latest
goos: linux
goarch: arm64
- os: macos-latest
goos: darwin
goarch: arm64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.version.outputs.tag }}
- uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: Configure module resolution
run: |
go env -w GOPROXY=direct
go env -w GOPRIVATE=github.com/Silo-Server/*
go env -w GONOSUMDB=github.com/Silo-Server/*
- name: Reject committed local SDK replaces
run: |
if grep -Eq '^replace github.com/Silo-Server/silo-plugin-sdk => /' go.mod; then
echo "go.mod contains a machine-local silo-plugin-sdk replace."
exit 1
fi
- name: Build plugin binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: '0'
GOWORK: off
run: |
mkdir -p dist
binary="plugin-${GOOS}-${GOARCH}"
version="${{ needs.version.outputs.version }}"
go build -trimpath -ldflags="-s -w -X main.version=${version}" -o "dist/${binary}" .
checksum=$(shasum -a 256 "dist/${binary}" | awk '{print $1}')
printf '%s %s\n' "$checksum" "$binary" > dist/checksums.txt
sed "s/__CHECKSUM__/${checksum}/" manifest.json > "dist/manifest-${GOOS}-${GOARCH}.json"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: plugin-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
dist/plugin-${{ matrix.goos }}-${{ matrix.goarch }}
dist/checksums.txt
dist/manifest-${{ matrix.goos }}-${{ matrix.goarch }}.json
release:
needs: [version, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release
: > release/checksums.txt
for dir in artifacts/plugin-*; do
platform=$(basename "$dir" | sed 's/plugin-//')
cp "${dir}/plugin-${platform}" "release/plugin-${platform}"
cat "${dir}/checksums.txt" >> release/checksums.txt
done
sort -u -o release/checksums.txt release/checksums.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.version.outputs.tag }}
files: |
release/plugin-linux-amd64
release/plugin-linux-arm64
release/plugin-darwin-arm64
release/checksums.txt
generate_release_notes: true
- name: Notify silo-plugins catalog
env:
DISPATCH_TOKEN: ${{ secrets.SILO_PLUGINS_DISPATCH_TOKEN }}
run: |
if [ -z "$DISPATCH_TOKEN" ]; then
echo "SILO_PLUGINS_DISPATCH_TOKEN is not set; skipping catalog dispatch."
exit 0
fi
curl --fail --silent --show-error \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${DISPATCH_TOKEN}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Silo-Server/silo-plugins/dispatches \
-d "$(printf '{"event_type":"plugin_release_published","client_payload":{"repo":"Silo-Server/silo-plugin-tmdb","tag":"%s"}}' "${{ needs.version.outputs.tag }}")"