Skip to content

Commit a891895

Browse files
committed
chore: dev releases (binaries and container)
1 parent 3c06f79 commit a891895

3 files changed

Lines changed: 252 additions & 2 deletions

File tree

.github/release.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
changelog:
2+
categories:
3+
- title: "Breaking Changes"
4+
labels: ["type: breaking", "breaking-change"]
5+
- title: "Added"
6+
labels: ["type: feature", "enhancement"]
7+
- title: "Fixed"
8+
labels: ["type: bug", "bug"]
9+
- title: "Documentation"
10+
labels: ["type: docs", "documentation"]
11+
- title: "Maintenance"
12+
labels: ["type: chore", "chore", "dependencies"]
13+
exclude:
14+
labels: ["skip-changelog"]

.github/workflows/dev.yml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Dev build (binaries + docker)
2+
3+
on:
4+
push:
5+
branches: [dev]
6+
workflow_dispatch:
7+
8+
9+
concurrency:
10+
group: dev-build-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: write
15+
packages: write
16+
actions: read
17+
18+
env:
19+
RELEASE_TAG: dev-latest
20+
IMAGE: ghcr.io/${{ github.repository }}
21+
22+
jobs:
23+
24+
build-binaries:
25+
name: Build binaries (${{ matrix.name }})
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
include:
31+
- name: linux-x86_64
32+
os: ubuntu-latest
33+
target: x86_64-unknown-linux-gnu
34+
bin: rathole
35+
- name: windows-x86_64
36+
os: windows-latest
37+
target: x86_64-pc-windows-msvc
38+
bin: rathole.exe
39+
- name: macos-x86_64
40+
os: macos-15-intel
41+
target: x86_64-apple-darwin
42+
bin: rathole
43+
- name: macos-arm64
44+
os: macos-15
45+
target: aarch64-apple-darwin
46+
bin: rathole
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: actions-rust-lang/setup-rust-toolchain@v1
50+
with:
51+
target: ${{ matrix.target }}
52+
rustflags: ""
53+
- name: Build
54+
shell: bash
55+
run: |
56+
set -euxo pipefail
57+
cargo build --release --locked --bin rathole
58+
- name: Package
59+
shell: bash
60+
run: |
61+
set -euxo pipefail
62+
mkdir -p out dist
63+
cp "target/release/${{ matrix.bin }}" dist/
64+
tar -czf "out/rathole-dev-${{ matrix.target }}.tar.gz" -C dist .
65+
ls -lah out/
66+
67+
- uses: actions/upload-artifact@v4
68+
with:
69+
name: bin-${{ matrix.target }}
70+
path: out/rathole-dev-${{ matrix.target }}.tar.gz
71+
if-no-files-found: error
72+
73+
74+
docker:
75+
name: Build & push docker (dev)
76+
runs-on: ubuntu-latest
77+
outputs:
78+
digest: ${{ steps.build.outputs.digest }}
79+
steps:
80+
- uses: actions/checkout@v4
81+
- uses: docker/setup-qemu-action@v3
82+
- uses: docker/setup-buildx-action@v3
83+
- uses: docker/login-action@v3
84+
with:
85+
registry: ghcr.io
86+
username: ${{ github.actor }}
87+
password: ${{ secrets.GITHUB_TOKEN }}
88+
89+
- name: Docker metadata
90+
id: meta
91+
uses: docker/metadata-action@v5
92+
with:
93+
images: ${{ env.IMAGE }}
94+
tags: |
95+
type=raw,value=dev
96+
type=sha,format=short,prefix=dev-
97+
98+
- name: Build & push
99+
id: build
100+
uses: docker/build-push-action@v6
101+
with:
102+
context: .
103+
file: ./Dockerfile
104+
platforms: linux/amd64,linux/arm64
105+
push: true
106+
tags: ${{ steps.meta.outputs.tags }}
107+
labels: ${{ steps.meta.outputs.labels }}
108+
cache-from: type=gha
109+
cache-to: type=gha,mode=max
110+
111+
release:
112+
name: Update rolling dev release
113+
runs-on: ubuntu-latest
114+
needs: [build-binaries, docker]
115+
116+
steps:
117+
- uses: actions/checkout@v4
118+
with:
119+
fetch-depth: 0
120+
121+
- name: Fetch tags
122+
shell: bash
123+
run: git fetch --tags --force
124+
125+
- name: Remember previous dev tag (if exists)
126+
id: prev
127+
shell: bash
128+
run: |
129+
set -e
130+
if git rev-parse -q --verify "refs/tags/${RELEASE_TAG}" >/dev/null; then
131+
echo "sha=$(git rev-parse refs/tags/${RELEASE_TAG})" >> $GITHUB_OUTPUT
132+
else
133+
echo "sha=" >> $GITHUB_OUTPUT
134+
fi
135+
136+
- name: Move dev tag to this commit (and update prev tag)
137+
shell: bash
138+
run: |
139+
set -euxo pipefail
140+
PREV_TAG="${RELEASE_TAG}-prev"
141+
OLD_SHA="${{ steps.prev.outputs.sha }}"
142+
143+
if [[ -n "${OLD_SHA}" ]]; then
144+
git tag -f "${PREV_TAG}" "${OLD_SHA}"
145+
146+
if ! git push -f origin "refs/tags/${PREV_TAG}" 2>push_prev.err; then
147+
if grep -q "refusing to allow a GitHub App to create or update workflow" push_prev.err; then
148+
echo "::warning::Could not update ${PREV_TAG} because ${OLD_SHA} modifies .github/workflows/. Continuing without previous_tag_name this run."
149+
# Remove the local tag so later steps don't mistakenly think it exists remotely
150+
git tag -d "${PREV_TAG}" || true
151+
else
152+
echo "Unexpected failure pushing ${PREV_TAG}:"
153+
cat push_prev.err
154+
exit 1
155+
fi
156+
fi
157+
fi
158+
159+
git tag -f "${RELEASE_TAG}" "${GITHUB_SHA}"
160+
git push -f origin "refs/tags/${RELEASE_TAG}"
161+
162+
163+
- name: Download artifacts
164+
uses: actions/download-artifact@v4
165+
with:
166+
path: dist
167+
pattern: "bin-*"
168+
merge-multiple: true
169+
170+
- name: Generate PR-based notes + Update Release + upload assets
171+
env:
172+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
173+
DOCKER_DIGEST: ${{ needs.docker.outputs.digest }}
174+
shell: bash
175+
run: |
176+
set -euxo pipefail
177+
178+
SHORT_SHA="${GITHUB_SHA::7}"
179+
IMAGE="ghcr.io/${GITHUB_REPOSITORY}"
180+
PREV_TAG="${RELEASE_TAG}-prev"
181+
182+
ARGS=(-f tag_name="${RELEASE_TAG}" -f target_commitish="${GITHUB_SHA}")
183+
if git ls-remote --tags origin "refs/tags/${PREV_TAG}" | grep -q .; then
184+
ARGS+=(-f previous_tag_name="${PREV_TAG}")
185+
fi
186+
187+
GEN_NOTES="$(gh api \
188+
-H "Accept: application/vnd.github+json" \
189+
"repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
190+
"${ARGS[@]}" \
191+
--jq '.body'
192+
)"
193+
194+
cat > RELEASE_NOTES.md <<EOF
195+
Automated build from branch \`dev\`.
196+
197+
- Commit: \`${GITHUB_SHA}\`
198+
- Docker:
199+
- \`${IMAGE}:dev\` (moving)
200+
- \`${IMAGE}:dev-${SHORT_SHA}\` (pinned tag)
201+
- \`${IMAGE}@${DOCKER_DIGEST}\` (pinned digest)
202+
203+
Pull:
204+
\`\`\`bash
205+
docker pull ${IMAGE}:dev
206+
docker pull ${IMAGE}:dev-${SHORT_SHA}
207+
docker pull ${IMAGE}@${DOCKER_DIGEST}
208+
\`\`\`
209+
210+
---
211+
212+
${GEN_NOTES}
213+
EOF
214+
215+
TITLE="Dev build (${SHORT_SHA})"
216+
217+
if gh release view "${RELEASE_TAG}" >/dev/null 2>&1; then
218+
gh release edit "${RELEASE_TAG}" \
219+
--prerelease \
220+
--title "${TITLE}" \
221+
--notes-file RELEASE_NOTES.md
222+
else
223+
gh release create "${RELEASE_TAG}" \
224+
--prerelease \
225+
--title "${TITLE}" \
226+
--notes-file RELEASE_NOTES.md
227+
fi
228+
229+
mapfile -t FILES < <(find dist -type f -name '*.tar.gz' -print)
230+
if (( ${#FILES[@]} == 0 )); then
231+
echo "No *.tar.gz artifacts found under dist/"
232+
find dist -maxdepth 3 -type f -print || true
233+
exit 1
234+
fi
235+
gh release upload "${RELEASE_TAG}" "${FILES[@]}" --clobber
236+
237+

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ name: Release
22

33
on:
44
push:
5-
tags:
6-
- "*"
5+
branches: [main]
76

87
workflow_dispatch:
98

0 commit comments

Comments
 (0)