refactor(workflows): replace grep/awk with yq for robust YAML parsing

Pin yq v4.44.1 in all template workflows with retry logic,
error handling, and input validation.
This commit is contained in:
George Cushen committed 2026-01-26 01:30:00 +00:00
1 parent 58f7dcdaf9
commit a139f74289
16 files changed
+336 -16

No files matched your search

+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"
+24 -1
View File
@@ -51,8 +51,31 @@ jobs:
- name: Get Hugo Version
id: hugo-version
run: |
VERSION=$(grep "hugo_version" hugoblox.yaml | awk '{print $2}' | tr -d "'\""")
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read hugo_version from hugoblox.yaml
VERSION=$(yq '.hugo_version // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
# Fallback to a known stable version if not specified
DEFAULT_VERSION="0.154.5"
VERSION=${VERSION:-$DEFAULT_VERSION}
# Validate version format (basic check)
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::warning::Invalid hugo_version format '$VERSION', using default $DEFAULT_VERSION"
VERSION="$DEFAULT_VERSION"
fi
echo "HUGO_VERSION=$VERSION" >> $GITHUB_ENV
echo "Using Hugo version: $VERSION"
- name: Install dependencies
run: |
+18 -1
View File
@@ -34,9 +34,26 @@ jobs:
- name: Check deploy host
id: check
run: |
# Install pinned yq version for robust YAML parsing
YQ_VERSION="v4.44.1"
if ! wget -q --tries=3 --waitretry=1 -O /tmp/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"; then
echo "::error::Failed to download yq"
exit 1
fi
sudo mv /tmp/yq /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
# Read deploy.host from hugoblox.yaml, default to github-pages
HOST=$(grep -A5 "^deploy:" hugoblox.yaml 2>/dev/null | grep "host:" | awk '{print $2}' | tr -d "'\""" || echo "github-pages")
HOST=$(yq '.deploy.host // ""' hugoblox.yaml 2>/dev/null | grep -v '^null$' || true)
HOST=${HOST:-github-pages}
# Validate known hosts
if [[ ! "$HOST" =~ ^(github-pages|netlify|vercel|cloudflare|none)$ ]]; then
echo "::warning::Unknown deploy host '$HOST', defaulting to github-pages"
HOST="github-pages"
fi
echo "host=$HOST" >> $GITHUB_OUTPUT
echo "Deployment target: $HOST"