Skip to content

Commit 614666b

Browse files
committed
ci: release, scan and publish in one step
1 parent ebf4763 commit 614666b

File tree

2 files changed

+46
-116
lines changed

2 files changed

+46
-116
lines changed

.github/workflows/release.yml

Lines changed: 43 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -9,145 +9,75 @@ on:
99
- 'v*'
1010

1111
jobs:
12-
build:
12+
build-and-upload:
1313
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
1416
steps:
15-
- uses: actions/checkout@v4
17+
- name: Checkout
18+
uses: actions/checkout@v4
1619
with:
1720
fetch-depth: 0
1821
fetch-tags: true
22+
1923
- name: Set up Go
2024
uses: actions/setup-go@v4
2125
with:
2226
go-version: '1.23'
23-
24-
- name: Install keepassxc-cli
25-
run: sudo apt-get update && sudo apt-get install -y keepassxc
2627

27-
- name: Build
28-
run: go build
28+
- name: Install system dependencies (keepassxc + clamav)
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y --no-install-recommends keepassxc clamav clamav-freshclam
32+
# Stop the auto-updater to avoid lock contention with manual freshclam
33+
sudo systemctl stop clamav-freshclam || true
34+
# Attempt DB update; use --stdout to bypass /var/log locking issues
35+
sudo freshclam --stdout --verbose || echo "Non-fatal: freshclam update failed or rate-limited; proceeding with packaged DB"
36+
echo "ClamAV version:"; clamscan --version || true
2937
30-
- name: Test
38+
- name: Run unit tests
3139
run: go test ./...
3240

33-
release:
34-
needs: build
35-
runs-on: ubuntu-latest
36-
steps:
37-
- uses: actions/checkout@v4
38-
with:
39-
fetch-depth: 0
40-
fetch-tags: true
41-
- name: Set up Go
42-
uses: actions/setup-go@v4
43-
with:
44-
go-version: '1.23'
45-
- name: Build with GoReleaser (no publish)
46-
uses: goreleaser/goreleaser-action@v5
41+
- name: Install GoReleaser (no execution yet)
42+
uses: goreleaser/goreleaser-action@v6
4743
with:
4844
distribution: goreleaser
49-
version: latest
50-
args: build --clean
45+
version: '~> v2'
46+
install-only: true
47+
48+
- name: GoReleaser release (build only, skip publish & announce)
5149
env:
5250
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
54-
- name: Upload artifacts for scanning
55-
uses: actions/upload-artifact@v4
56-
with:
57-
name: release-artifacts
58-
path: dist/
59-
retention-days: 1
51+
run: goreleaser release --clean --skip=publish --skip=announce
6052

61-
virus-scan:
62-
needs: release
63-
runs-on: ubuntu-latest
64-
steps:
65-
- name: Download release artifacts
66-
uses: actions/download-artifact@v4
67-
with:
68-
name: release-artifacts
69-
path: dist/
70-
71-
- name: Install ClamAV
72-
run: |
73-
sudo apt-get update
74-
sudo apt-get install -y clamav clamav-daemon
75-
sudo systemctl stop clamav-freshclam
76-
sudo freshclam
77-
sudo systemctl start clamav-daemon
78-
# Wait for daemon to start
79-
sleep 10
80-
81-
- name: Scan release artifacts
53+
- name: Virus scan dist artifacts
8254
run: |
83-
echo "Scanning release artifacts for viruses..."
84-
85-
clamscan --recursive --verbose --infected --bell dist/
86-
scan_result=$?
87-
88-
if [ $scan_result -eq 0 ]; then
89-
echo "✅ All artifacts are clean - no viruses detected"
90-
elif [ $scan_result -eq 1 ]; then
91-
echo "❌ Virus detected in artifacts!"
92-
exit 1
93-
else
94-
echo "⚠️ Scanner error occurred"
55+
echo "Scanning dist/ with ClamAV..."
56+
# clamscan returns 1 if a virus is found, 0 if none found.
57+
clamscan --recursive --infected --verbose dist/ || SCAN_STATUS=$?
58+
if [ "${SCAN_STATUS:-0}" -eq 1 ]; then
59+
echo "❌ Virus detected in build artifacts. Aborting publish." >&2
9560
exit 1
61+
elif [ "${SCAN_STATUS:-0}" -gt 1 ]; then
62+
echo "❌ ClamAV scan error (exit code $SCAN_STATUS). Aborting publish." >&2
63+
exit $SCAN_STATUS
9664
fi
97-
98-
- name: Upload clean artifacts
99-
if: success()
100-
uses: actions/upload-artifact@v4
101-
with:
102-
name: scanned-artifacts
103-
path: dist/
104-
retention-days: 1
65+
echo "✅ No viruses found. Proceeding to publish."
10566
106-
publish-release:
107-
needs: virus-scan
108-
runs-on: ubuntu-latest
109-
steps:
110-
- uses: actions/checkout@v4
111-
with:
112-
fetch-depth: 0
113-
fetch-tags: true
114-
115-
- name: Download scanned artifacts
116-
uses: actions/download-artifact@v4
67+
- name: Create GitHub Release & upload artifacts
68+
uses: softprops/action-gh-release@v2
11769
with:
118-
name: scanned-artifacts
119-
path: dist/
120-
121-
- name: Extract version from tag
122-
id: version
123-
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
124-
125-
- name: List available artifacts
126-
run: |
127-
echo "Available artifacts in dist/:"
128-
find dist/ -type f -ls
129-
130-
- name: Create release with scanned artifacts
131-
run: |
132-
# Collect standard release artifacts (archives and checksums)
133-
ARTIFACTS=$(find dist/ \( -name "*.tar.gz" -o -name "checksums.txt" \) -type f | tr '\n' ' ')
134-
135-
echo "Artifacts to upload: $ARTIFACTS"
136-
137-
if [ -z "$ARTIFACTS" ]; then
138-
echo "❌ No artifacts found to upload!"
139-
exit 1
140-
fi
141-
142-
gh release create ${{ steps.version.outputs.VERSION }} \
143-
--title "Release ${{ steps.version.outputs.VERSION }}" \
144-
--generate-notes \
145-
$ARTIFACTS
70+
tag_name: ${{ github.ref_name }}
71+
name: ${{ github.ref_name }}
72+
body_path: dist/CHANGELOG.md
73+
files: |
74+
dist/ctRestClient_*.tar.gz
75+
dist/checksums.txt
14676
env:
14777
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14878

149-
publish-versioned-docs:
150-
needs: publish-release
79+
publish-docs:
80+
needs: build-and-upload
15181
runs-on: ubuntu-latest
15282
permissions:
15383
contents: write

.goreleaser.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
version: 2
12
project_name: ctRestClient
23
builds:
34
- id: linux-amd64
@@ -38,7 +39,7 @@ builds:
3839
- -s -w
3940
archives:
4041
- id: platform-specific
41-
format: tar.gz
42+
formats: [tar.gz]
4243
name_template: >-
4344
{{ .ProjectName }}_
4445
{{- .Version }}_
@@ -50,8 +51,6 @@ archives:
5051
- LICENSE*
5152
checksum:
5253
name_template: 'checksums.txt'
53-
snapshot:
54-
name_template: "{{ incpatch .Version }}-next"
5554
changelog:
5655
sort: asc
5756
use: github
@@ -76,6 +75,7 @@ changelog:
7675
- '^refactor:'
7776
- Merge pull request
7877
- Merge branch
78+
7979
release:
8080
github:
8181
owner: mvach

0 commit comments

Comments
 (0)