Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: CI

on:
push:
branches: [main, "release/**"]
pull_request:
branches: [main]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true

- name: Check formatting
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "Files not formatted:"
echo "$unformatted"
exit 1
fi

- name: Vet
run: go vet ./...

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Staticcheck
run: staticcheck ./...

test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true

- name: Run tests with race detector
run: go test -race -coverprofile=coverage.out -count=1 ./...

- name: Enforce coverage >= 82%
run: |
set -euo pipefail
total=$(go tool cover -func=coverage.out | awk '/^total:/ {print $3}' | tr -d '%')
echo "Total coverage: ${total}%"
# Threshold reflects Go 1.24 coverage instrumentation (which counts a
# few more branches than newer toolchains). Reported total on the
# matrix Go version was ~83.3% on the initial baseline.
awk -v t="$total" 'BEGIN { exit (t + 0 < 82.0) ? 1 : 0 }'

- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
retention-days: 14

build:
name: Build (${{ matrix.os }})
runs-on: ${{ matrix.runner }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- os: linux
runner: ubuntu-latest
- os: macos
runner: macos-latest
- os: windows
runner: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true

- name: Build
run: go build -v ./cmd/cbz2epub
28 changes: 0 additions & 28 deletions .github/workflows/go.yml

This file was deleted.

232 changes: 232 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: "Version to release (e.g. 0.2.0). Do not include the leading 'v'."
required: true
type: string
prerelease:
description: "Mark as prerelease"
required: false
type: boolean
default: false

concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: write

jobs:
prepare:
name: Prepare release
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
version: ${{ steps.resolve.outputs.version }}
prerelease: ${{ steps.resolve.outputs.prerelease }}
steps:
- uses: actions/checkout@v4

- name: Resolve version
id: resolve
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
INPUT_PRERELEASE: ${{ github.event.inputs.prerelease }}
run: |
set -euo pipefail

if [ -z "${INPUT_VERSION:-}" ]; then
echo "version input is required" >&2
exit 1
fi
# Accept both "0.2.0" and "v0.2.0" — normalise to no-leading-v.
version="${INPUT_VERSION#v}"

# Validate semver (with optional pre-release/build suffix)
if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$'; then
echo "Invalid version: $version" >&2
exit 1
fi

# Auto-detect prerelease from suffix or manual input
prerelease=false
if printf '%s' "$version" | grep -Eq -- '-(alpha|beta|rc)'; then
prerelease=true
fi
if [ "${INPUT_PRERELEASE:-false}" = "true" ]; then
prerelease=true
fi

echo "version=$version" >> "$GITHUB_OUTPUT"
echo "prerelease=$prerelease" >> "$GITHUB_OUTPUT"
echo "Resolved version=$version prerelease=$prerelease"

- name: Create or reuse draft release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.resolve.outputs.version }}
PRERELEASE: ${{ steps.resolve.outputs.prerelease }}
TARGET_SHA: ${{ github.sha }}
run: |
set -euo pipefail
tag="v${VERSION}"

# Extract release notes from CHANGELOG.md for this version, fallback to generated notes.
notes_file="$(mktemp)"
awk -v ver="$VERSION" '
$0 ~ "^## \\[" ver "\\]" { capture=1; next }
capture && /^## \[/ { exit }
capture { print }
' CHANGELOG.md > "$notes_file" || true

if [ ! -s "$notes_file" ]; then
echo "No CHANGELOG section for $VERSION; will use generated notes."
fi

prerelease_flag=""
if [ "$PRERELEASE" = "true" ]; then
prerelease_flag="--prerelease"
fi

if gh release view "$tag" >/dev/null 2>&1; then
echo "Release $tag already exists; leaving as-is (draft assumed)."
elif [ -s "$notes_file" ]; then
gh release create "$tag" \
--draft \
--title "$tag" \
--target "$TARGET_SHA" \
--notes-file "$notes_file" \
$prerelease_flag
else
gh release create "$tag" \
--draft \
--title "$tag" \
--target "$TARGET_SHA" \
--generate-notes \
$prerelease_flag
fi

build:
name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
needs: prepare
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
ext: ".exe"
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
cache: true

- name: Build and package
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
EXT: ${{ matrix.ext }}
VERSION: ${{ needs.prepare.outputs.version }}
CGO_ENABLED: "0"
run: |
set -euo pipefail
mkdir -p dist
binname="cbz2epub${EXT:-}"
go build -trimpath -ldflags="-s -w -X main.version=v${VERSION}" -o "dist/${binname}" ./cmd/cbz2epub

base="cbz2epub-v${VERSION}-${GOOS}-${GOARCH}"
staging="dist/${base}"
mkdir -p "$staging"
cp "dist/${binname}" "$staging/"
cp README.md LICENSE "$staging/"

cd dist
if [ "${GOOS}" = "windows" ]; then
archive="${base}.zip"
zip -r "$archive" "$base" >/dev/null
else
archive="${base}.tar.gz"
tar -czf "$archive" "$base"
fi
sha256sum "$archive" > "${archive}.sha256"
echo "Built $archive"

- name: Upload assets to draft release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.prepare.outputs.version }}
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
set -euo pipefail
tag="v${VERSION}"
base="cbz2epub-v${VERSION}-${GOOS}-${GOARCH}"
cd dist
if [ "${GOOS}" = "windows" ]; then
archive="${base}.zip"
else
archive="${base}.tar.gz"
fi
gh release upload "$tag" "$archive" "${archive}.sha256" --clobber

publish:
name: Publish release
needs: [prepare, build]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Verify assets and publish
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
tag="v${VERSION}"

expected=(
"cbz2epub-v${VERSION}-linux-amd64.tar.gz"
"cbz2epub-v${VERSION}-linux-arm64.tar.gz"
"cbz2epub-v${VERSION}-darwin-amd64.tar.gz"
"cbz2epub-v${VERSION}-darwin-arm64.tar.gz"
"cbz2epub-v${VERSION}-windows-amd64.zip"
)

assets="$(gh release view "$tag" --json assets --jq '.assets[].name')"
echo "Uploaded assets:"
echo "$assets"

missing=0
for a in "${expected[@]}"; do
if ! printf '%s\n' "$assets" | grep -qx "$a"; then
echo "Missing expected asset: $a" >&2
missing=1
fi
done
if [ "$missing" -ne 0 ]; then
echo "One or more expected assets missing; not publishing." >&2
exit 1
fi

# Publish (un-draft) the release.
gh release edit "$tag" --draft=false
echo "Published $tag"
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
.idea/*
cbz2epub.iml

# Build artifacts
/cbz2epub
/cbz2epub.exe
/dist/

# Test / coverage output
coverage.out
*.out
cmd/cbz2epub/merged.cbz

# OS files
.DS_Store
Loading
Loading