-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (200 loc) · 6.96 KB
/
Copy pathpublish.yml
File metadata and controls
222 lines (200 loc) · 6.96 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Publish
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to publish (e.g., v1.2.3)'
required: true
type: string
permissions:
contents: write
packages: write
jobs:
# ============================================
# Extract Version from Tag
# ============================================
prepare:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps:
- name: Extract version from tag
id: version
run: |
TAG="${{ inputs.tag }}"
VERSION="${TAG#v}"
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Releasing version: $VERSION (tag: $TAG)"
# ============================================
# Publish to crates.io
# ============================================
publish-crates:
name: Publish to crates.io
needs: prepare
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.tag }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
# ============================================
# Build Binaries (reusable workflow)
# ============================================
build-binaries:
name: Build Binaries
needs: prepare
uses: ./.github/workflows/_build-binaries.yml
with:
ref: ${{ needs.prepare.outputs.tag }}
upload-artifacts: true
artifact-retention-days: 1
# ============================================
# Build Packages (reusable workflow)
# ============================================
build-packages:
name: Build Packages
needs: prepare
uses: ./.github/workflows/_build-packages.yml
with:
ref: ${{ needs.prepare.outputs.tag }}
version: ${{ needs.prepare.outputs.version }}
artifact-retention-days: 1
# ============================================
# Create GitHub Release with All Assets
# ============================================
create-github-release:
name: Create GitHub Release
needs: [prepare, build-binaries, build-packages]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.tag }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure
run: ls -R artifacts
- name: Extract release notes from CHANGELOG
id: release_notes
run: |
VERSION="${{ needs.prepare.outputs.version }}"
# Extract the section for this version from CHANGELOG.md
# The changelog format is: ## [version](url) (date)
# We want everything between this version header and the next ## header
# Use awk to extract the section
NOTES=$(awk -v ver="$VERSION" '
/^## \[/ {
if (found) exit
if (index($0, "[" ver "]")) found=1
next
}
found { print }
' CHANGELOG.md)
# If no notes found, use a default message
if [ -z "$NOTES" ]; then
NOTES="Release v$VERSION"
fi
# Write to file to handle multiline content
echo "$NOTES" > release_notes.md
echo "Release notes extracted for v$VERSION"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.prepare.outputs.tag }}
name: ${{ needs.prepare.outputs.tag }}
body_path: release_notes.md
files: artifacts/**/*
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ============================================
# Docker Build & Push
# ============================================
docker:
name: Build and Push Docker Image
needs: [prepare, build-binaries]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.tag }}
- 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.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ needs.prepare.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.prepare.outputs.version }}
type=semver,pattern={{major}},value=${{ needs.prepare.outputs.version }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
# ============================================
# Trigger External Package Repository Updates
# ============================================
update-package-repos:
name: Trigger ${{ matrix.name }} Update
needs: [prepare, create-github-release]
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: Homebrew
repo: bordeux/homebrew-tap
token_env: HOMEBREW_TAP_TOKEN
- name: APT Repository
repo: bordeux/apt-repo
token_env: APT_REPO_TOKEN
- name: APK Repository
repo: bordeux/apk-repo
token_env: APK_REPO_TOKEN
- name: RPM Repository
repo: bordeux/rpm-repo
token_env: RPM_REPO_TOKEN
- name: ARCH Repository
repo: bordeux/arch-repo
token_env: ARCH_REPO_TOKEN
steps:
- name: Trigger ${{ matrix.name }} workflow
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
APT_REPO_TOKEN: ${{ secrets.APT_REPO_TOKEN }}
APK_REPO_TOKEN: ${{ secrets.APK_REPO_TOKEN }}
RPM_REPO_TOKEN: ${{ secrets.RPM_REPO_TOKEN }}
ARCH_REPO_TOKEN: ${{ secrets.ARCH_REPO_TOKEN }}
run: |
TOKEN_VAR="${{ matrix.token_env }}"
TOKEN="${!TOKEN_VAR}"
curl -X POST \
-H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ matrix.repo }}/actions/workflows/update-repo.yml/dispatches" \
-d '{"ref":"master","inputs":{"project":"bordeux/tmpltool"}}'