-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (133 loc) · 5.22 KB
/
Copy pathrelease.yml
File metadata and controls
157 lines (133 loc) · 5.22 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --verbose
- name: Get current version
id: current
run: |
# Read version from [workspace.package] section specifically
VERSION=$(sed -n '/\[workspace\.package\]/,/\[/{ s/^version = "\(.*\)"/\1/p }' Cargo.toml)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Current version: $VERSION"
- name: Bump version
id: bump
run: |
IFS='.' read -r major minor patch <<< "${{ steps.current.outputs.version }}"
case "${{ inputs.bump }}" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
NEW_VERSION="${major}.${minor}.${patch}"
SHORT_VERSION="${major}.${minor}"
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "Bumping to: $NEW_VERSION (short: $SHORT_VERSION)"
# ── 1. Workspace root version ──
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
# ── 2. Internal dependency version pins ──
# Handles both orderings:
# llmg-xxx = { version = "...", path = "..." }
# llmg-xxx = { path = "...", version = "..." }
for f in llmg-providers/Cargo.toml llmg-gateway/Cargo.toml; do
sed -i -E "s/(llmg-[a-z_]+ = \{[^}]*version = )\"[^\"]+\"/\1\"$NEW_VERSION\"/" "$f"
done
# ── 3. README.md version references ──
sed -i -E "s/llmg-core = \"[0-9]+\.[0-9]+(\.[0-9]+)?\"/llmg-core = \"$NEW_VERSION\"/" README.md
sed -i -E "s/(llmg-providers = \{ version = )\"[0-9]+\.[0-9]+(\.[0-9]+)?\"/\1\"$NEW_VERSION\"/" README.md
# ── 4. Documentation version references (all .md/.mdx under docs/, skip CHANGELOG) ──
find docs -type f \( -name "*.md" -o -name "*.mdx" \) ! -name "CHANGELOG.md" | while read -r f; do
# Cargo.toml-style: llmg-core = "0.1" or "0.1.8"
sed -i -E "s/llmg-core = \"[0-9]+\.[0-9]+(\.[0-9]+)?\"/llmg-core = \"$NEW_VERSION\"/" "$f"
# Cargo.toml-style: llmg-providers = { version = "0.1" or "0.1.8", ... }
sed -i -E "s/(llmg-providers = \{ version = )\"[0-9]+\.[0-9]+(\.[0-9]+)?\"/\1\"$NEW_VERSION\"/" "$f"
# JSON-style: "version": "0.1.0"
sed -i -E "s/\"version\": \"[0-9]+\.[0-9]+\.[0-9]+\"/\"version\": \"$NEW_VERSION\"/" "$f"
done
- name: Verify build
run: cargo build --release
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit and tag
run: |
git add -A
git commit -m "release: v${{ steps.bump.outputs.version }}"
git tag "v${{ steps.bump.outputs.version }}"
git push origin ${{ github.ref_name }} --tags
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: "v${{ steps.bump.outputs.version }}"
name: "v${{ steps.bump.outputs.version }}"
generate_release_notes: true
- name: Publish llmg-core to crates.io
run: cargo publish -p llmg-core --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true
- name: Publish llmg-providers to crates.io
run: cargo publish -p llmg-providers --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true
- name: Publish llmg-gateway to crates.io
run: cargo publish -p llmg-gateway --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
continue-on-error: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=v${{ steps.bump.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ steps.bump.outputs.version }}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max