-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (198 loc) · 7.56 KB
/
release.yaml
File metadata and controls
204 lines (198 loc) · 7.56 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release, for example 0.1.0 or v0.1.0"
required: true
type: string
previous_version:
description: "Optional previous version for Full Changelog, for example 0.0.9 or v0.0.9"
required: false
type: string
permissions:
contents: write
env:
BIN_NAME: codes
REPO_SLUG: 4fuu/code-search-cli
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
version: ${{ steps.normalize.outputs.version }}
tag: ${{ steps.normalize.outputs.tag }}
title: ${{ steps.normalize.outputs.title }}
steps:
- name: Normalize version
id: normalize
shell: bash
run: |
set -euo pipefail
RAW="${{ inputs.version }}"
VERSION="${RAW#v}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version: $RAW" >&2
exit 1
fi
TAG="v$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "title=codes $TAG" >> "$GITHUB_OUTPUT"
build:
name: Build (${{ matrix.target }})
needs: prepare
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
archive_ext: tar.gz
- os: macos-latest
target: x86_64-apple-darwin
archive_ext: tar.gz
- os: macos-latest
target: aarch64-apple-darwin
archive_ext: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
archive_ext: zip
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build
env:
CODES_VERSION: ${{ needs.prepare.outputs.version }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package Unix archive
if: runner.os != 'Windows'
shell: bash
env:
TAG: ${{ needs.prepare.outputs.tag }}
TARGET: ${{ matrix.target }}
EXT: ${{ matrix.archive_ext }}
run: |
set -euo pipefail
STAGE="$RUNNER_TEMP/package"
mkdir -p "$STAGE"
cp "target/$TARGET/release/$BIN_NAME" "$STAGE/$BIN_NAME"
cp LICENSE README.md README.zh-CN.md "$STAGE/"
ARCHIVE="$BIN_NAME-$TAG-$TARGET.$EXT"
tar -C "$STAGE" -czf "$ARCHIVE" .
echo "ARCHIVE_NAME=$ARCHIVE" >> "$GITHUB_ENV"
- name: Package Windows archive
if: runner.os == 'Windows'
shell: pwsh
env:
TAG: ${{ needs.prepare.outputs.tag }}
TARGET: ${{ matrix.target }}
EXT: ${{ matrix.archive_ext }}
run: |
$stage = Join-Path $env:RUNNER_TEMP "package"
New-Item -ItemType Directory -Force -Path $stage | Out-Null
Copy-Item "target/$env:TARGET/release/$env:BIN_NAME.exe" (Join-Path $stage "$env:BIN_NAME.exe")
Copy-Item LICENSE, README.md, README.zh-CN.md $stage
$archive = "$env:BIN_NAME-$env:TAG-$env:TARGET.$env:EXT"
Compress-Archive -Path (Join-Path $stage '*') -DestinationPath $archive -Force
"ARCHIVE_NAME=$archive" | Out-File -FilePath $env:GITHUB_ENV -Append
- uses: actions/upload-artifact@v6
with:
name: ${{ matrix.target }}
path: ${{ env.ARCHIVE_NAME }}
release:
name: Publish Release
needs:
- prepare
- build
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.version }}
TAG: ${{ needs.prepare.outputs.tag }}
TITLE: ${{ needs.prepare.outputs.title }}
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v8
with:
path: dist
- name: Flatten artifacts
shell: bash
run: |
set -euo pipefail
mkdir -p release
find dist -type f -maxdepth 2 -exec mv {} release/ \;
ls -la release
- name: Generate checksums
shell: bash
run: |
set -euo pipefail
cd release
sha256sum * > SHA256SUMS.txt
- name: Generate placeholder release notes
shell: bash
run: |
set -euo pipefail
prev="${{ inputs.previous_version }}"
if [[ -n "$prev" ]]; then
prev="${prev#v}"
printf 'Full Changelog: %s...%s\n' "$prev" "$VERSION" > release/RELEASE_NOTES.md
else
: > release/RELEASE_NOTES.md
fi
- name: Render Homebrew formula
shell: bash
run: |
set -euo pipefail
cd release
linux_sha=$(grep "codes-$TAG-x86_64-unknown-linux-gnu.tar.gz" SHA256SUMS.txt | awk '{print $1}')
macos_x64_sha=$(grep "codes-$TAG-x86_64-apple-darwin.tar.gz" SHA256SUMS.txt | awk '{print $1}')
macos_arm_sha=$(grep "codes-$TAG-aarch64-apple-darwin.tar.gz" SHA256SUMS.txt | awk '{print $1}')
sed -i "s|version \".*\"|version \"$VERSION\"|" ../Formula/codes.rb
sed -i -E "s|/download/[^/]+/|/download/$TAG/|g" ../Formula/codes.rb
sed -i -E "s|codes-v[0-9]+\\.[0-9]+\\.[0-9]+-aarch64-apple-darwin\\.tar\\.gz|codes-$TAG-aarch64-apple-darwin.tar.gz|" ../Formula/codes.rb
sed -i -E "s|codes-v[0-9]+\\.[0-9]+\\.[0-9]+-x86_64-apple-darwin\\.tar\\.gz|codes-$TAG-x86_64-apple-darwin.tar.gz|" ../Formula/codes.rb
sed -i -E "s|codes-v[0-9]+\\.[0-9]+\\.[0-9]+-x86_64-unknown-linux-gnu\\.tar\\.gz|codes-$TAG-x86_64-unknown-linux-gnu.tar.gz|" ../Formula/codes.rb
sed -i "s|sha256 \".*\" # macos_arm64|sha256 \"$macos_arm_sha\" # macos_arm64|" ../Formula/codes.rb
sed -i "s|sha256 \".*\" # macos_x86|sha256 \"$macos_x64_sha\" # macos_x86|" ../Formula/codes.rb
sed -i "s|sha256 \".*\" # linux_x86|sha256 \"$linux_sha\" # linux_x86|" ../Formula/codes.rb
- name: Render Scoop manifest
shell: bash
run: |
set -euo pipefail
cd release
windows_sha=$(grep "codes-$TAG-x86_64-pc-windows-msvc.zip" SHA256SUMS.txt | awk '{print $1}')
sed -i "s|\"version\": \".*\"|\"version\": \"$VERSION\"|" ../bucket/codes.json
sed -i -E "s|/download/[^/]+/|/download/$TAG/|g" ../bucket/codes.json
sed -i -E "s|codes-v[0-9]+\\.[0-9]+\\.[0-9]+-x86_64-pc-windows-msvc\\.zip|codes-$TAG-x86_64-pc-windows-msvc.zip|" ../bucket/codes.json
sed -i "s|\"hash\": \".*\"|\"hash\": \"$windows_sha\"|" ../bucket/codes.json
- name: Commit package manifests
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add Formula/codes.rb bucket/codes.json
if git diff --cached --quiet; then
exit 0
fi
git commit -m "release: update package manifests for $TAG"
git push origin HEAD:${GITHUB_REF_NAME}
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
assets=(release/*.tar.gz release/*.zip release/SHA256SUMS.txt)
gh release create "$TAG" \
--repo "$REPO_SLUG" \
--title "$TITLE" \
--notes-file release/RELEASE_NOTES.md \
--target "$GITHUB_SHA" \
"${assets[@]}"