Repository navigation
166 lines (144 loc) · 5.18 KB
/
Copy pathrelease.yml
File metadata and controls
166 lines (144 loc) · 5.18 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
name: Release
on:
push:
tags: ["v*"]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@1.98.0
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Verify tag matches crate version
run: |
TAG="${GITHUB_REF#refs/tags/v}"
CRATE_VERSION=$(grep '^version' crates/mqdb-cli/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ "$TAG" != "$CRATE_VERSION" ]; then
echo "Tag v$TAG does not match mqdb-cli version $CRATE_VERSION"
exit 1
fi
- name: Publish mqdb-core
run: cargo publish --package mqdb-core || echo "already published"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Wait for crates.io index
run: sleep 30
- name: Publish mqdb-agent
run: cargo publish --package mqdb-agent || echo "already published"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish mqdb-wasm
run: cargo publish --manifest-path crates/mqdb-wasm/Cargo.toml --no-verify || echo "already published"
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-binaries:
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
name: mqdb-linux-amd64
- os: macos-latest
target: x86_64-apple-darwin
name: mqdb-macos-amd64
- os: macos-latest
target: aarch64-apple-darwin
name: mqdb-macos-arm64
- os: windows-latest
target: x86_64-pc-windows-msvc
name: mqdb-windows-amd64
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@1.98.0
with:
targets: ${{ matrix.target }}
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build
run: cargo build --profile dist --package mqdb-cli --no-default-features --features http-api --target ${{ matrix.target }}
- name: Prepare artifact (unix)
if: runner.os != 'Windows'
run: |
cp target/${{ matrix.target }}/dist/mqdb ${{ matrix.name }}
chmod +x ${{ matrix.name }}
- name: Prepare artifact (windows)
if: runner.os == 'Windows'
run: copy target\${{ matrix.target }}\dist\mqdb.exe ${{ matrix.name }}.exe
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ runner.os == 'Windows' && format('{0}.exe', matrix.name) || matrix.name }}
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [publish, build-binaries]
steps:
- uses: actions/checkout@v4
- name: Extract changelog
id: changelog
run: |
TAG="${GITHUB_REF#refs/tags/v}"
BODY=$(python3 - "$TAG" <<'PY'
import re, sys
tag = sys.argv[1]
lines = open("CHANGELOG.md").read().splitlines()
# Headings look like: ## YYYY-MM-DD — mqdb-<crate> <version>[, mqdb-... <version>]*
heading = re.compile(r"^## (\d{4}-\d{2}-\d{2}) — (.*)$")
# Find the heading that lists mqdb-cli <tag>; that anchors the release date.
anchor_date = None
for line in lines:
m = heading.match(line)
if m and re.search(rf"\bmqdb-cli\s+{re.escape(tag)}\b", m.group(2)):
anchor_date = m.group(1)
break
if anchor_date is None:
# No matching heading — emit empty body so the release still publishes.
sys.exit(0)
# Collect every section dated anchor_date (covers parallel crate bumps).
out, capturing = [], False
for line in lines:
m = heading.match(line)
if m:
capturing = (m.group(1) == anchor_date)
if capturing:
out.append(line)
continue
if capturing:
out.append(line)
# Trim trailing blank lines.
while out and out[-1].strip() == "":
out.pop()
print("\n".join(out))
PY
)
{
echo "body<<CHANGELOG_EOF"
echo "$BODY"
echo "CHANGELOG_EOF"
} >> "$GITHUB_OUTPUT"
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.body }}
files: |
artifacts/mqdb-linux-amd64/mqdb-linux-amd64
artifacts/mqdb-macos-amd64/mqdb-macos-amd64
artifacts/mqdb-macos-arm64/mqdb-macos-arm64
artifacts/mqdb-windows-amd64/mqdb-windows-amd64.exe