Skip to content

Commit b2fc5fc

Browse files
committed
fix(apply-repo-settings): detect+shadow wrong yq (kislyuk/Python)
Some runners pre-install kislyuk's Python yq (a jq wrapper) at /usr/bin/yq. The previous check skipped install when 'yq' was on PATH — but Python yq doesn't support '-o=json' and the action failed with exit 3 (jq compile error 'Unknown option -o=json'). Now: probe '--version' for the mikefarah marker. If absent, install mikefarah/yq to /usr/local/bin/yq and prepend it via GITHUB_PATH so subsequent steps shadow any wrong yq.
1 parent d5791c9 commit b2fc5fc

1 file changed

Lines changed: 36 additions & 5 deletions

File tree

‎.github/actions/apply-repo-settings/action.yml‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,46 @@ outputs:
4343
runs:
4444
using: 'composite'
4545
steps:
46-
- name: Ensure yq is available
46+
- name: Ensure mikefarah/yq is available
4747
shell: bash
4848
run: |
49-
if ! command -v yq >/dev/null 2>&1; then
50-
echo "Installing yq..."
51-
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
49+
set -euo pipefail
50+
# The action needs mikefarah's Go yq (supports `-o=json` for
51+
# YAML→JSON conversion). Some runners pre-install kislyuk's Python
52+
# yq — a `jq` wrapper that does NOT understand `-o=json` and exits
53+
# with cryptic "Unknown option" errors. Detect, and if the resolved
54+
# `yq` is the wrong one, install mikefarah's to /usr/local/bin/yq
55+
# and prepend that path for subsequent steps so it shadows the
56+
# pre-installed wrapper.
57+
install_mikefarah() {
58+
echo "Installing mikefarah/yq to /usr/local/bin/yq..."
59+
sudo wget -qO /usr/local/bin/yq \
60+
https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
5261
sudo chmod +x /usr/local/bin/yq
62+
}
63+
yq_is_mikefarah() {
64+
# mikefarah's --version line contains the github.com/mikefarah URL.
65+
"$1" --version 2>&1 | grep -q 'mikefarah'
66+
}
67+
if command -v yq >/dev/null 2>&1 && yq_is_mikefarah "$(command -v yq)"; then
68+
echo "mikefarah/yq already on PATH: $(command -v yq)"
69+
else
70+
if command -v yq >/dev/null 2>&1; then
71+
echo "Wrong yq detected at $(command -v yq) ($(yq --version 2>&1)); shadowing with mikefarah's."
72+
fi
73+
install_mikefarah
74+
echo "/usr/local/bin" >> "$GITHUB_PATH"
5375
fi
54-
yq --version
76+
# Sanity check: must be mikefarah's yq when action.sh runs in the next step.
77+
# We can't rely on $GITHUB_PATH having taken effect in THIS step, so
78+
# validate by absolute path if we just installed, else use what's on PATH.
79+
check_bin=$(command -v yq)
80+
if [[ -x /usr/local/bin/yq ]] && yq_is_mikefarah /usr/local/bin/yq; then
81+
check_bin=/usr/local/bin/yq
82+
fi
83+
echo "Verifying $check_bin..."
84+
"$check_bin" --version
85+
yq_is_mikefarah "$check_bin" || { echo "::error::yq sanity check failed: not mikefarah"; exit 1; }
5586
5687
- name: Apply settings
5788
id: apply

0 commit comments

Comments
 (0)