Skip to content

Commit 0c81d05

Browse files
committed
ci(release-prechecks): improve test-goreleaser script
1 parent 8725c77 commit 0c81d05

File tree

5 files changed

+149
-209
lines changed

5 files changed

+149
-209
lines changed

.github/workflows/release-prechecks.yml

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,9 @@ on:
55
workflow_dispatch:
66

77
jobs:
8-
prerequisites:
9-
name: Prerequisites
10-
runs-on: ubuntu-latest
11-
steps:
12-
- name: Checkout code
13-
uses: actions/checkout@v5
14-
15-
- name: Set up Go
16-
uses: actions/setup-go@v5
17-
with:
18-
go-version-file: go.mod
19-
20-
- name: Validate prerequisites
21-
env:
22-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23-
RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
24-
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
25-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
26-
GPG_FINGERPRINT: ${{ secrets.GPG_FINGERPRINT }}
27-
run: ./scripts/validate-release-prerequisites.sh
28-
298
goreleaser-test:
309
name: GoReleaser Test
3110
runs-on: ubuntu-latest
32-
needs: [prerequisites]
3311
steps:
3412
- name: Checkout code
3513
uses: actions/checkout@v5
@@ -61,6 +39,9 @@ jobs:
6139
version: "~> v2"
6240
install-only: true
6341

42+
- name: Install Nix
43+
uses: cachix/install-nix-action@v31
44+
6445
- name: Run GoReleaser test
6546
env:
6647
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
with:
5656
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
5757

58+
- name: Install Nix
59+
uses: cachix/install-nix-action@v31
60+
5861
- name: Run GoReleaser
5962
uses: goreleaser/goreleaser-action@v6
6063
with:

.goreleaser.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version: 2
22

3+
project_name: emojify-go
4+
35
before:
46
hooks:
57
- make clean
@@ -128,6 +130,17 @@ winget:
128130
name: winget-pkgs
129131
branch: master
130132

133+
nix:
134+
- repository:
135+
owner: "damienbutt"
136+
name: nur
137+
token: "{{ .Env.RELEASE_TOKEN }}"
138+
homepage: https://github.com/damienbutt/emojify-go
139+
description: Lighting fast Emoji conversion on the command line 😱
140+
license: mit
141+
extra_install: |-
142+
installManPage ./man/emojify.1.gz
143+
131144
aurs:
132145
- name: emojify-go-bin
133146
homepage: https://github.com/damienbutt/emojify-go

scripts/test-goreleaser.sh

Lines changed: 130 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
#!/bin/bash
22

3-
# GoReleaser Testing Script
4-
# Tests configuration and build process without publishing
5-
63
set -e
74

8-
echo "🧪 GoReleaser Testing Suite"
9-
echo "=========================="
10-
echo
11-
12-
# Colors for output
135
RED='\033[0;31m'
146
GREEN='\033[0;32m'
157
YELLOW='\033[1;33m'
168
BLUE='\033[0;34m'
17-
NC='\033[0m' # No Color
9+
NC='\033[0m'
10+
11+
MISSING_SECRETS=()
12+
MISSING_REPOS=()
13+
MISSING_TOOLS=()
14+
WARNINGS=()
1815

1916
print_status() {
2017
echo -e "${BLUE}$1${NC}"
@@ -32,8 +29,50 @@ print_error() {
3229
echo -e "${RED}$1${NC}"
3330
}
3431

32+
check_secret() {
33+
local secret_name="$1"
34+
local description="$2"
35+
36+
if [ -z "${!secret_name}" ]; then
37+
MISSING_SECRETS+=("$secret_name - $description")
38+
print_error "Missing: $secret_name"
39+
else
40+
print_success "Found: $secret_name"
41+
fi
42+
}
43+
44+
check_github_repo() {
45+
local repo="$1"
46+
local description="$2"
47+
local token="$3"
48+
49+
local http_status
50+
http_status=$(curl -s -o /dev/null -w "%{http_code}" \
51+
-H "Authorization: token ${token}" \
52+
"https://api.github.com/repos/$repo")
53+
54+
if [ $http_status -eq 200 ]; then
55+
print_success "Repository exists: $repo"
56+
else
57+
MISSING_REPOS+=("$repo - $description (HTTP status: $http_status)")
58+
print_error "Missing repository: $repo (HTTP status: $http_status)"
59+
fi
60+
}
61+
62+
check_tool() {
63+
local tool="$1"
64+
65+
if ! command -v "$tool" &> /dev/null; then
66+
MISSING_TOOLS+=("$tool")
67+
print_error "Missing tool: $tool"
68+
else
69+
print_success "Found tool: $tool"
70+
fi
71+
}
72+
3573
# 1. Configuration validation
36-
print_status "1. Validating GoReleaser configuration..."
74+
print_status "1. 🔍 Validating GoReleaser Configuration..."
75+
3776
if go tool goreleaser check 2>/dev/null; then
3877
print_success "Configuration is valid"
3978
else
@@ -47,60 +86,106 @@ else
4786
fi
4887
}
4988
fi
50-
echo
5189

52-
# 2. Required secrets check
53-
print_status "2. Checking required secrets..."
90+
echo ""
5491

55-
check_secret() {
56-
local secret_name="$1"
57-
local required="$2"
92+
# 2. Required secrets check
93+
print_status "2. 📋 Checking Required Secrets..."
94+
95+
check_secret "GITHUB_TOKEN" "GitHub Actions token (auto-provided)"
96+
check_secret "RELEASE_TOKEN" "Token for Homebrew tap repository"
97+
check_secret "GPG_PRIVATE_KEY" "GPG private key for package signing"
98+
check_secret "GPG_FINGERPRINT" "GPG key fingerprint for package signing"
99+
check_secret "AUR_SSH_PRIVATE_KEY" "SSH private key for AUR publishing (both emojify-go and emojify-go-bin)"
100+
echo ""
101+
102+
# 3. Required repositories check
103+
print_status "3. 🏗️ Checking Required Repositories..."
104+
105+
check_github_repo "damienbutt/homebrew-tap" "Homebrew formula repository" "GITHUB_TOKEN"
106+
check_github_repo "damienbutt/scoop-bucket" "Scoop bucket repository" "GITHUB_TOKEN"
107+
check_github_repo "damienbutt/winget-pkgs" "Winget package repository" "GITHUB_TOKEN"
108+
check_github_repo "damienbutt/nur" "Nix User Repository (NUR)" "GITHUB_TOKEN"
109+
echo ""
110+
111+
# 4. Check build tools
112+
print_status "4. 🔧 Checking Build Tools..."
113+
114+
check_tool "go"
115+
check_tool "git"
116+
check_tool "gpg"
117+
check_tool "nix-hash"
118+
echo ""
119+
120+
print_status "5. 📊 Validation Summary"
121+
echo "======================"
122+
123+
if [ ${#MISSING_SECRETS[@]} -eq 0 ] && \
124+
[ ${#MISSING_REPOS[@]} -eq 0 ] && \
125+
[ ${#MISSING_TOOLS[@]} -eq 0 ]; then
126+
print_success "🎉 All required prerequisites are in place!"
127+
128+
# GO_VERSION=$(go version | cut -d' ' -f3 | sed 's/go//')
129+
# print_success "Go version: $GO_VERSION"
130+
131+
if [ ${#WARNINGS[@]} -gt 0 ]; then
132+
echo -e "\n${YELLOW}⚠️ Optional items:${NC}"
133+
print_warning "Optional items:"
134+
for warning in "${WARNINGS[@]}"; do
135+
echo -e "${YELLOW}$warning${NC}"
136+
done
137+
fi
138+
else
139+
echo -e "${RED}❌ Missing required prerequisites:${NC}"
140+
print_error "Missing required prerequisites:"
141+
142+
if [ ${#MISSING_SECRETS[@]} -gt 0 ]; then
143+
echo -e "\n${RED}❌ Missing Secrets:${NC}"
144+
for secret in "${MISSING_SECRETS[@]}"; do
145+
echo -e "${RED}$secret${NC}"
146+
done
147+
fi
58148

59-
if gh secret list | grep -q "$secret_name"; then
60-
print_success "$secret_name is configured"
61-
else
62-
if [[ "$required" == "true" ]]; then
63-
print_error "$secret_name is missing (required)"
64-
return 1
65-
else
66-
print_warning "$secret_name is missing (optional)"
67-
fi
149+
if [ ${#MISSING_REPOS[@]} -gt 0 ]; then
150+
echo -e "\n${RED}❌ Missing Repositories:${NC}"
151+
for repo in "${MISSING_REPOS[@]}"; do
152+
echo -e "${RED}$repo${NC}"
153+
done
68154
fi
69-
}
70155

71-
# Check essential secrets
72-
MISSING_SECRETS=0
73-
check_secret "RELEASE_TOKEN" "true" || ((MISSING_SECRETS++))
74-
check_secret "AUR_SSH_PRIVATE_KEY" "true" || ((MISSING_SECRETS++))
75-
check_secret "GPG_PRIVATE_KEY" "true" || ((MISSING_SECRETS++))
76-
check_secret "GPG_FINGERPRINT" "true" || ((MISSING_SECRETS++))
156+
if [ ${#MISSING_TOOLS[@]} -gt 0 ]; then
157+
echo -e "\n${RED}❌ Missing Tools:${NC}"
158+
for tool in "${MISSING_TOOLS[@]}"; do
159+
echo -e "${RED}$tool${NC}"
160+
done
161+
fi
77162

78-
if [[ $MISSING_SECRETS -eq 0 ]]; then
79-
print_success "All secrets configured ✅"
80-
else
81-
print_warning "$MISSING_SECRETS required secrets missing ⚠️"
82163
exit 1
83164
fi
84-
echo
85165

86-
# 3. GoReleaser Test (without publishing)
87-
print_status "3. Testing GoReleaser process (no publishing)..."
166+
# 6. GoReleaser Test (without publishing)
167+
print_status "6. Testing GoReleaser process (no publishing)..."
88168

89169
# Base skip flags - always skip these for testing
90-
SKIP_FLAGS="--skip=publish --skip=sign --skip=validate"
170+
SKIP_FLAGS="--skip=publish"
91171

92172
if go tool goreleaser release --snapshot --clean $SKIP_FLAGS --verbose; then
93173
print_success "GoReleaser process completed successfully"
94174
else
95175
print_error "GoReleaser process failed"
96176
exit 1
97177
fi
98-
echo
178+
echo ""
99179

100180
# 6. Summary
101181
print_status "📋 Test Summary"
102182
echo "==============="
103-
echo
104-
105-
print_success "Configuration valid ✅"
106-
print_success "GoReleaser process works ✅"
183+
echo ""
184+
185+
print_success "GoReleaser configuration is valid."
186+
print_success "All required secrets are present."
187+
print_success "All required repositories are accessible."
188+
print_success "All required build tools are installed."
189+
print_success "GoReleaser release process completed successfully."
190+
echo ""
191+
print_success "🚀 Ready to release!"

0 commit comments

Comments
 (0)