Skip to content

Commit 5d2def2

Browse files
author
Splitter
committed
refactor(workflows): replace grep/awk with yq for robust YAML parsing
1 parent 1b5b3d1 commit 5d2def2

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,31 @@ jobs:
5151
- name: Get Hugo Version
5252
id: hugo-version
5353
run: |
54-
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
54+
# Install pinned yq version for robust YAML parsing
55+
YQ_VERSION="v4.44.1"
56+
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
57+
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
58+
echo "::error::Failed to download yq"
59+
exit 1
60+
fi
61+
sudo mv /tmp/yq /usr/local/bin/yq
62+
sudo chmod +x /usr/local/bin/yq
63+
64+
# Read hugo_version from hugoblox.yaml
65+
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
66+
67+
# Fallback to a known stable version if not specified
68+
DEFAULT_VERSION="0.154.5"
69+
VERSION=${VERSION:-$DEFAULT_VERSION}
70+
71+
# Validate version format (basic check)
72+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
73+
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
74+
VERSION="$DEFAULT_VERSION"
75+
fi
76+
5577
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
78+
echo "Using Hugo version: $VERSION"
5679
5780
- name: Install dependencies
5881
run: |

.github/workflows/deploy.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,26 @@ jobs:
3434
- name: Check deploy host
3535
id: check
3636
run: |
37+
# Install pinned yq version for robust YAML parsing
38+
YQ_VERSION="v4.44.1"
39+
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
40+
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
41+
echo "::error::Failed to download yq"
42+
exit 1
43+
fi
44+
sudo mv /tmp/yq /usr/local/bin/yq
45+
sudo chmod +x /usr/local/bin/yq
46+
3747
# Read deploy.host from hugoblox.yaml, default to github-pages
38-
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
48+
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
3949
HOST=${HOST:-github-pages}
50+
51+
# Validate known hosts
52+
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
53+
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
54+
HOST="github-pages"
55+
fi
56+
4057
echo "host=$HOST" >> $GITHUB_OUTPUT
4158
echo "Deployment target: $HOST"
4259

0 commit comments

Comments
 (0)