11#! /bin/bash
22
3- # GoReleaser Testing Script
4- # Tests configuration and build process without publishing
5-
63set -e
74
8- echo " 🧪 GoReleaser Testing Suite"
9- echo " =========================="
10- echo
11-
12- # Colors for output
135RED=' \033[0;31m'
146GREEN=' \033[0;32m'
157YELLOW=' \033[1;33m'
168BLUE=' \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
1916print_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+
3776if go tool goreleaser check 2> /dev/null; then
3877 print_success " Configuration is valid"
3978else
@@ -47,60 +86,106 @@ else
4786 fi
4887 }
4988fi
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
83164fi
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
92172if go tool goreleaser release --snapshot --clean $SKIP_FLAGS --verbose; then
93173 print_success " GoReleaser process completed successfully"
94174else
95175 print_error " GoReleaser process failed"
96176 exit 1
97177fi
98- echo
178+ echo " "
99179
100180# 6. Summary
101181print_status " 📋 Test Summary"
102182echo " ==============="
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