Skip to content

Commit 981092c

Browse files
committed
feat: dockerhub release
1 parent 0303f32 commit 981092c

6 files changed

Lines changed: 96 additions & 60 deletions

File tree

.github/workflows/docker.yml

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: docker
22

33
on:
4-
push:
5-
tags:
6-
- "v*"
74
workflow_dispatch:
85
inputs:
96
tag:
@@ -16,67 +13,70 @@ jobs:
1613
runs-on: ubuntu-latest
1714
permissions:
1815
contents: read
16+
packages: write
1917
env:
20-
IMAGE: ${{ github.repository_owner }}/diff-coverage
21-
ALPINE_VERSION: "3.20"
18+
IMAGE: ${{ github.repository_owner }}/diff-coverage-internal
19+
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/diff-coverage-internal
20+
strategy:
21+
matrix:
22+
include:
23+
- variant: alpine
24+
base_image: alpine:3.20
25+
rust_target_suffix: musl
26+
tag_suffix: alpine-3.20
27+
- variant: debian
28+
base_image: debian:trixie
29+
rust_target_suffix: gnu
30+
tag_suffix: debian-trixie
2231
steps:
2332
- uses: actions/checkout@v4
24-
- name: Set version
33+
with:
34+
fetch-depth: 0
35+
- name: Set version (manual)
36+
if: github.event_name == 'workflow_dispatch'
2537
run: |
2638
TAG="${{ inputs.tag }}"
27-
if [ -z "$TAG" ]; then TAG="$GITHUB_REF_NAME"; fi
39+
if [ -z "$TAG" ]; then
40+
echo "Release tag input is required" >&2
41+
exit 1
42+
fi
2843
VERSION="${TAG#v}"
2944
echo "TAG=$TAG" >> "$GITHUB_ENV"
3045
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
31-
- name: Wait for release binaries
32-
env:
33-
GH_TOKEN: ${{ github.token }}
34-
run: |
35-
set -euo pipefail
36-
for i in {1..60}; do
37-
assets="$(gh release view "$TAG" --json assets --jq '.assets[].name' || true)"
38-
if echo "$assets" | grep -q "diff-coverage-$TAG-x86_64-unknown-linux-musl" \
39-
&& echo "$assets" | grep -q "diff-coverage-$TAG-aarch64-unknown-linux-musl"; then
40-
exit 0
41-
fi
42-
echo "Waiting for release assets for $TAG..."
43-
sleep 10
44-
done
45-
echo "Release assets not found for $TAG"
46-
exit 1
4746
- name: Download release binaries
4847
env:
4948
GH_TOKEN: ${{ github.token }}
5049
run: |
5150
mkdir -p dist
52-
gh release download "$TAG" --pattern "diff-coverage-$TAG-x86_64-unknown-linux-musl" --dir dist
53-
gh release download "$TAG" --pattern "diff-coverage-$TAG-aarch64-unknown-linux-musl" --dir dist
54-
mv "dist/diff-coverage-$TAG-x86_64-unknown-linux-musl" "dist/diff-coverage-x86_64-unknown-linux-musl"
55-
mv "dist/diff-coverage-$TAG-aarch64-unknown-linux-musl" "dist/diff-coverage-aarch64-unknown-linux-musl"
56-
chmod +x dist/diff-coverage-x86_64-unknown-linux-musl dist/diff-coverage-aarch64-unknown-linux-musl
51+
gh release download "$TAG" --pattern "diff-coverage-$TAG-x86_64-unknown-linux-${{ matrix.rust_target_suffix }}.tar.gz" --dir dist
52+
gh release download "$TAG" --pattern "diff-coverage-$TAG-aarch64-unknown-linux-${{ matrix.rust_target_suffix }}.tar.gz" --dir dist
53+
tar -xzf "dist/diff-coverage-$TAG-x86_64-unknown-linux-${{ matrix.rust_target_suffix }}.tar.gz" -C dist
54+
mv "dist/diff-coverage" "dist/diff-coverage-x86_64-unknown-linux-${{ matrix.rust_target_suffix }}"
55+
tar -xzf "dist/diff-coverage-$TAG-aarch64-unknown-linux-${{ matrix.rust_target_suffix }}.tar.gz" -C dist
56+
mv "dist/diff-coverage" "dist/diff-coverage-aarch64-unknown-linux-${{ matrix.rust_target_suffix }}"
57+
rm -f dist/*.tar.gz
58+
chmod +x dist/diff-coverage-x86_64-unknown-linux-${{ matrix.rust_target_suffix }} dist/diff-coverage-aarch64-unknown-linux-${{ matrix.rust_target_suffix }}
5759
- uses: docker/setup-buildx-action@v3
5860
- uses: docker/login-action@v3
5961
with:
6062
username: ${{ github.repository_owner }}
6163
password: ${{ secrets.DOCKERHUB_TOKEN }}
64+
- uses: docker/login-action@v3
65+
with:
66+
registry: ghcr.io
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
6269
- name: Docker meta
6370
id: meta
6471
uses: docker/metadata-action@v5
6572
with:
66-
images: ${{ env.IMAGE }}
73+
images: |
74+
${{ env.IMAGE }}
75+
${{ env.GHCR_IMAGE }}
6776
tags: |
68-
type=raw,value=latest
69-
type=semver,pattern={{version}},value=${{ env.VERSION }}
70-
type=semver,pattern={{major}},value=${{ env.VERSION }}
71-
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }}
72-
type=raw,value=alpine
73-
type=raw,value=alpine-${{ env.ALPINE_VERSION }}
74-
type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-alpine
75-
type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-alpine
76-
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-alpine
77-
type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }}
78-
type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }}
79-
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-alpine-${{ env.ALPINE_VERSION }}
77+
type=semver,pattern={{version}},value=${{ env.VERSION }},suffix=-${{ matrix.tag_suffix }}
78+
type=semver,pattern={{major}},value=${{ env.VERSION }},suffix=-${{ matrix.tag_suffix }}
79+
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},suffix=-${{ matrix.tag_suffix }}
8080
- name: Build and push (linux)
8181
uses: docker/build-push-action@v5
8282
with:
@@ -85,6 +85,7 @@ jobs:
8585
platforms: linux/amd64,linux/arm64
8686
push: true
8787
build-args: |
88-
ALPINE_VERSION=${{ env.ALPINE_VERSION }}
88+
BASE_IMAGE=${{ matrix.base_image }}
89+
RUST_TARGET_SUFFIX=${{ matrix.rust_target_suffix }}
8990
tags: ${{ steps.meta.outputs.tags }}
90-
labels: ${{ steps.meta.outputs.labels }}
91+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/release.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,16 @@ jobs:
7474
if: "!startsWith(matrix.os, 'ubuntu')"
7575
run: cargo build --release --locked --target ${{ matrix.target }}
7676

77-
- name: Prepare release binary
77+
- name: Prepare release archive
7878
id: prepare
7979
shell: bash
8080
run: |
8181
mkdir -p dist
82-
asset="diff-coverage-${{ github.ref_name }}-${{ matrix.target }}${{ matrix.bin_ext }}"
83-
cp "target/${{ matrix.target }}/release/diff-coverage${{ matrix.bin_ext }}" "dist/$asset"
82+
binary="diff-coverage${{ matrix.bin_ext }}"
83+
asset="diff-coverage-${{ github.ref_name }}-${{ matrix.target }}.tar.gz"
84+
cp "target/${{ matrix.target }}/release/$binary" "dist/$binary"
85+
tar -C dist -czf "dist/$asset" "$binary"
86+
rm "dist/$binary"
8487
echo "asset=dist/$asset" >> "$GITHUB_OUTPUT"
8588
8689
- name: Upload release assets
@@ -89,6 +92,20 @@ jobs:
8992
files: |
9093
${{ steps.prepare.outputs.asset }}
9194
95+
dispatch-docker:
96+
needs: build
97+
runs-on: ubuntu-latest
98+
permissions:
99+
actions: write
100+
contents: read
101+
steps:
102+
- name: Trigger docker workflow
103+
env:
104+
GH_TOKEN: ${{ github.token }}
105+
run: |
106+
TAG="${{ github.ref_name }}"
107+
gh workflow run docker.yml -R "$GITHUB_REPOSITORY" --ref "$TAG" -f tag="$TAG"
108+
92109
publish:
93110
runs-on: ubuntu-latest
94111

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "diff-coverage"
3-
version = "0.2.5"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "Diff-coverage, supercharged in Rust. Fast, memory-efficient coverage on changed lines for CI."
66
license = "MIT"

Dockerfile.release

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
# syntax=docker/dockerfile:1.6
22
ARG ALPINE_VERSION=3.20
3-
ARG BUILDPLATFORM
4-
ARG TARGETPLATFORM
3+
ARG BASE_IMAGE=alpine:${ALPINE_VERSION}
54

6-
FROM alpine:${ALPINE_VERSION}
5+
FROM ${BASE_IMAGE}
76
ARG TARGETPLATFORM
8-
RUN apk add --no-cache ca-certificates
7+
ARG RUST_TARGET_SUFFIX=musl
8+
RUN set -eux; \
9+
if command -v apk >/dev/null 2>&1; then \
10+
apk add --no-cache ca-certificates; \
11+
elif command -v apt-get >/dev/null 2>&1; then \
12+
apt-get update; \
13+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates; \
14+
rm -rf /var/lib/apt/lists/*; \
15+
else \
16+
echo "Unsupported base image: missing apk/apt-get" >&2; \
17+
exit 1; \
18+
fi
919
COPY dist/ /dist/
20+
RUN echo "TARGETPLATFORM=${TARGETPLATFORM}"
1021
RUN case "$TARGETPLATFORM" in \
11-
"linux/arm64") echo "aarch64-unknown-linux-musl" > rust_target.txt ;; \
12-
"linux/amd64") echo "x86_64-unknown-linux-musl" > rust_target.txt ;; \
22+
"linux/arm64") echo "aarch64-unknown-linux-${RUST_TARGET_SUFFIX}" > rust_target.txt ;; \
23+
"linux/amd64") echo "x86_64-unknown-linux-${RUST_TARGET_SUFFIX}" > rust_target.txt ;; \
1324
*) exit 1 ;; \
1425
esac
1526
RUN set -eux; \
1627
mv "/dist/diff-coverage-$(cat rust_target.txt)" /usr/local/bin/diff-coverage; \
1728
chmod +x /usr/local/bin/diff-coverage; \
1829
rm -rf /dist rust_target.txt
19-
ENTRYPOINT ["diff-coverage"]
30+
ENTRYPOINT ["diff-coverage"]

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ⚡🧠️ diff-coverage
22

3-
Diff-cover, supercharged in Rust 🦀. Get instant, actionable coverage insights at ⚡ blazing speed ⚡ with
4-
a 🧠️ tiny memory footprint 🧠️. Built for modern CI and massive repos, it turns slow coverage checks into
3+
Diff-cover, supercharged in Rust 🦀. Get instant, actionable coverage insights at ⚡ blazing speed ⚡ with
4+
a 🧠️ tiny memory footprint 🧠️. Built for modern CI and massive repos, it turns slow coverage checks into
55
fast, reliable feedback you can trust.
66

77
## Usage
@@ -64,7 +64,7 @@ Options
6464

6565
### Prebuilt binaries
6666

67-
Download the prebuilt archives from the [GitHub Releases page](https://github.com/tilaven/diff-coverage/releases).
67+
Download the prebuilt archives from the [GitHub Releases page](https://github.com/tilaven/diff-coverage/releases).
6868

6969
### Cargo install
7070

@@ -75,7 +75,14 @@ cargo install diff-coverage
7575
### Docker
7676

7777
```bash
78-
docker run --rm -v "$PWD":/work -w /work <dockerhub-user>/diff-coverage:latest \
78+
docker run --rm -v "$PWD":/work -w /work tilaven/diff-coverage:<version>-alpine \
79+
coverage.xml --diff-file diff.diff
80+
```
81+
82+
Debian-based image (e.g. trixie) is available via versioned tags:
83+
84+
```bash
85+
docker run --rm -v "$PWD":/work -w /work tilaven/diff-coverage:<version>-debian-trixie \
7986
coverage.xml --diff-file diff.diff
8087
```
8188

@@ -85,7 +92,7 @@ docker run --rm -v "$PWD":/work -w /work <dockerhub-user>/diff-coverage:latest \
8592
cargo build
8693
```
8794

88-
## Run
95+
## Run
8996

9097
```bash
9198
cargo run

0 commit comments

Comments
 (0)