-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (129 loc) · 4.06 KB
/
Copy pathrelease.yml
File metadata and controls
154 lines (129 loc) · 4.06 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.2.2)"
required: true
type: string
skip_crates:
description: "Skip crates.io publish"
required: false
type: boolean
default: false
skip_docker:
description: "Skip Docker image push"
required: false
type: boolean
default: false
env:
CARGO_TERM_COLOR: always
DOCKER_IMAGE: ghcr.io/totte-dev/qhook
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Validate version matches Cargo.toml
run: |
cargo_version=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
if [ "$cargo_version" != "${{ inputs.version }}" ]; then
echo "::error::Version mismatch: Cargo.toml has $cargo_version, input is ${{ inputs.version }}"
exit 1
fi
- name: Validate version matches CHANGELOG.md
run: |
if ! grep -q "## \[${{ inputs.version }}\]" CHANGELOG.md; then
echo "::error::Version ${{ inputs.version }} not found in CHANGELOG.md"
exit 1
fi
- name: Check tag does not exist
run: |
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "::error::Tag v${{ inputs.version }} already exists"
exit 1
fi
test:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --check
- name: Clippy
run: cargo clippy --all-targets
- name: Tests (unit + E2E + scenarios)
run: cargo test
- name: Build release
run: cargo build --release
github-release:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Extract changelog for this version
id: changelog
run: |
# Extract the section for this version from CHANGELOG.md
awk '/^## \[${{ inputs.version }}\]/{found=1; next} /^## \[/{if(found) exit} found{print}' CHANGELOG.md > release_notes.md
cat release_notes.md
- name: Create tag and release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag "v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
gh release create "v${{ inputs.version }}" \
--title "v${{ inputs.version }}" \
--notes-file release_notes.md
crates-io:
needs: test
if: ${{ !inputs.skip_crates }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --allow-dirty
docker:
needs: test
if: ${{ !inputs.skip_docker }}
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
continue-on-error: true
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ env.DOCKER_IMAGE }}:${{ inputs.version }}
${{ env.DOCKER_IMAGE }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max