Skip to content
This repository was archived by the owner on Jun 13, 2026. It is now read-only.

Commit 97ef621

Browse files
committed
fix: Add workflow-level permissions and GITHUB_TOKEN for Docker push
- Add workflow-level permissions for packages:write - Explicitly pass GITHUB_TOKEN to build.py - Update pre-commit to match CI Ruff configuration exactly
1 parent 20abb71 commit 97ef621

3 files changed

Lines changed: 47 additions & 39 deletions

File tree

.github/workflows/release.yml

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ on:
1111
required: true
1212
type: string
1313

14+
permissions:
15+
contents: write
16+
packages: write
17+
id-token: write
18+
1419
env:
1520
REGISTRY: ghcr.io
1621
IMAGE_NAME: ${{ github.repository }}
@@ -49,7 +54,7 @@ jobs:
4954
contents: write
5055
packages: write
5156
id-token: write
52-
57+
5358
steps:
5459
- name: Checkout code
5560
uses: actions/checkout@v4
@@ -92,66 +97,66 @@ jobs:
9297
run: |
9398
# Get the previous tag
9499
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "${VERSION}^" 2>/dev/null || echo "")
95-
100+
96101
if [ -z "$PREVIOUS_TAG" ]; then
97102
echo "No previous tag found, including all commits"
98103
COMMIT_RANGE=""
99104
else
100105
echo "Generating changelog from $PREVIOUS_TAG to $VERSION"
101106
COMMIT_RANGE="$PREVIOUS_TAG..$VERSION"
102107
fi
103-
108+
104109
# Generate changelog
105110
{
106111
echo "CHANGELOG<<EOF"
107112
echo "## 🚀 What's Changed"
108113
echo ""
109-
114+
110115
# Features
111116
FEATURES=$(git log $COMMIT_RANGE --pretty=format:"* %s (%h)" --grep="^feat" 2>/dev/null)
112117
if [ -n "$FEATURES" ]; then
113118
echo "### ✨ Features"
114119
echo "$FEATURES"
115120
echo ""
116121
fi
117-
122+
118123
# Bug fixes
119124
FIXES=$(git log $COMMIT_RANGE --pretty=format:"* %s (%h)" --grep="^fix" 2>/dev/null)
120125
if [ -n "$FIXES" ]; then
121126
echo "### 🐛 Bug Fixes"
122127
echo "$FIXES"
123128
echo ""
124129
fi
125-
130+
126131
# Documentation
127132
DOCS=$(git log $COMMIT_RANGE --pretty=format:"* %s (%h)" --grep="^docs" 2>/dev/null)
128133
if [ -n "$DOCS" ]; then
129134
echo "### 📚 Documentation"
130135
echo "$DOCS"
131136
echo ""
132137
fi
133-
138+
134139
# Performance
135140
PERF=$(git log $COMMIT_RANGE --pretty=format:"* %s (%h)" --grep="^perf" 2>/dev/null)
136141
if [ -n "$PERF" ]; then
137142
echo "### ⚡ Performance"
138143
echo "$PERF"
139144
echo ""
140145
fi
141-
146+
142147
# All other commits
143148
OTHER=$(git log $COMMIT_RANGE --pretty=format:"* %s (%h)" --grep="^feat" --grep="^fix" --grep="^docs" --grep="^perf" --invert-grep 2>/dev/null)
144149
if [ -n "$OTHER" ]; then
145150
echo "### 🔧 Other Changes"
146151
echo "$OTHER"
147152
echo ""
148153
fi
149-
154+
150155
# Contributors
151156
echo "### 👥 Contributors"
152157
git log $COMMIT_RANGE --pretty=format:"* @%an" | sort -u
153158
echo ""
154-
159+
155160
# Statistics
156161
if [ -n "$COMMIT_RANGE" ]; then
157162
echo "### 📊 Statistics"
@@ -160,32 +165,34 @@ jobs:
160165
echo "* $COMMITS commits"
161166
echo "* $FILES"
162167
fi
163-
168+
164169
echo "EOF"
165170
} >> $GITHUB_OUTPUT
166171
167172
- name: Build and push with build.py
173+
env:
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168175
run: |
169176
# Install Python dependencies for build script
170177
pip install rich click semver pyyaml
171-
178+
172179
# Set CI environment variable to ensure proper tagging
173180
export CI=true
174-
181+
175182
# Build and push with the specific version tag
176183
python build.py --version-tag ${{ steps.version.outputs.version_number }}
177-
184+
178185
# Additional tags for releases
179186
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.version.outputs.version_number }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
180187
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
181-
188+
182189
# Create major and minor version tags
183190
MAJOR=$(echo ${{ steps.version.outputs.version_number }} | cut -d. -f1)
184191
MINOR=$(echo ${{ steps.version.outputs.version_number }} | cut -d. -f1,2)
185-
192+
186193
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.version.outputs.version_number }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${MAJOR}
187194
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${MAJOR}
188-
195+
189196
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.version.outputs.version_number }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${MINOR}
190197
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${MINOR}
191198
@@ -203,7 +210,7 @@ jobs:
203210
# Install cosign
204211
curl -sSL https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 -o /tmp/cosign
205212
chmod +x /tmp/cosign
206-
213+
207214
# Sign the images
208215
/tmp/cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.version.outputs.version_number }}
209216
/tmp/cosign sign --yes ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
@@ -221,32 +228,32 @@ jobs:
221228
sbom.spdx.json
222229
body: |
223230
## 🐳 Docker Images
224-
231+
225232
### Pull the image:
226233
```bash
227234
# Latest version
228235
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
229-
236+
230237
# Specific version
231238
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
232-
239+
233240
# Major version (will update with patches)
234241
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v$(echo ${{ steps.version.outputs.version_number }} | cut -d. -f1)
235242
```
236-
243+
237244
### Run the container:
238245
```bash
239246
# Using docker-compose (recommended)
240247
docker-compose up -d
241-
248+
242249
# Or using docker run
243250
docker run -d \
244251
--name sensor-log-generator \
245252
-v $(pwd)/data:/app/data \
246253
-v $(pwd)/config:/app/config \
247254
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
248255
```
249-
256+
250257
### Run with WAL mode disabled (for Docker Desktop on Mac/Windows):
251258
```bash
252259
docker run -d \
@@ -255,17 +262,17 @@ jobs:
255262
-e SENSOR_WAL=false \
256263
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
257264
```
258-
265+
259266
---
260-
267+
261268
${{ steps.changelog.outputs.CHANGELOG }}
262-
269+
263270
---
264-
271+
265272
## 📦 Assets
266273
- **SBOM**: Software Bill of Materials attached below
267274
- **Container Signature**: Images are signed with Cosign/Sigstore
268-
275+
269276
## 🔗 Quick Links
270277
- [Documentation](https://github.com/${{ github.repository }}/blob/main/README.md)
271278
- [Container Registry](https://github.com/${{ github.repository }}/pkgs/container/${{ github.event.repository.name }})

.pre-commit-config.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ repos:
99
- id: check-ast
1010
name: Check Python syntax
1111

12-
# Ruff - Auto-fix formatting and basic linting issues
12+
# Ruff - Auto-fix formatting and linting issues (uses pyproject.toml config)
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
1414
rev: v0.12.10
1515
hooks:
1616
- id: ruff
1717
name: Ruff auto-fix
18-
args: [--fix, --select, "F,E,W,I,TRY", --ignore, "E501,W293,TRY401"] # Include TRY rules, ignore redundant exception in log
18+
args: [--fix] # Uses config from pyproject.toml
19+
files: ^(src/|tests/|main\.py)
1920
- id: ruff-format
2021
name: Ruff formatter
22+
files: ^(src/|tests/|main\.py)
2123

2224
# Basic file checks (fast)
2325
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -48,8 +50,8 @@ repos:
4850
- repo: local
4951
hooks:
5052
- id: full-lint
51-
name: Full linting check
52-
entry: uv run ruff check src/ tests/ main.py
53+
name: Full linting check (same as CI)
54+
entry: bash -c 'uv run ruff check src/ tests/ main.py && uv run ruff format --check src/ tests/ main.py'
5355
language: system
5456
pass_filenames: false
5557
stages: [manual]

build.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import sys
2020
from datetime import datetime
2121
from pathlib import Path
22-
from typing import Optional
2322

2423
import click
2524
import semver
@@ -39,7 +38,7 @@ class BuildError(Exception):
3938
class DockerComposeBuilder:
4039
def __init__(
4140
self,
42-
image_name: Optional[str] = None,
41+
image_name: str | None = None,
4342
platforms: str = "linux/amd64,linux/arm64",
4443
dockerfile: str = "Dockerfile",
4544
registry: str = "ghcr.io",
@@ -366,7 +365,7 @@ def setup_buildx_builder(self):
366365
console.print("[green]✓[/green] Builder created and ready")
367366
return True
368367

369-
def get_current_version(self) -> Optional[semver.Version]:
368+
def get_current_version(self) -> semver.Version | None:
370369
"""Get the current version from git tags"""
371370
try:
372371
result = self._run_command(["git", "tag", "--list", "v*"], check=False)
@@ -389,7 +388,7 @@ def get_current_version(self) -> Optional[semver.Version]:
389388
pass
390389
return None
391390

392-
def bump_version(self, current: Optional[semver.Version], bump_type: str) -> semver.Version:
391+
def bump_version(self, current: semver.Version | None, bump_type: str) -> semver.Version:
393392
"""Bump the version based on type"""
394393
if current is None:
395394
# Start with 1.0.0 if no version exists
@@ -677,11 +676,11 @@ def cleanup(self):
677676
help="Docker Compose file for building",
678677
)
679678
def main(
680-
image_name: Optional[str],
679+
image_name: str | None,
681680
platforms: str,
682681
dockerfile: str,
683682
registry: str,
684-
version_tag: Optional[str],
683+
version_tag: str | None,
685684
version_bump: str,
686685
dev_mode: bool,
687686
skip_push: bool,

0 commit comments

Comments
 (0)