Skip to content

Commit 224d068

Browse files
authored
fix: validate GitHub API response is an array before parsing releases (#13)
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent ee63ad1 commit 224d068

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

.github/workflows/autobump.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,18 @@ jobs:
7070
- name: Get latest upstream version
7171
id: upstream
7272
run: |
73-
TAG=$(curl -sL \
73+
RESPONSE=$(curl -fsSL \
7474
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
75-
"https://api.github.com/repos/${{ matrix.upstream_repo }}/releases?per_page=100" \
75+
-H "Accept: application/vnd.github+json" \
76+
-H "X-GitHub-Api-Version: 2022-11-28" \
77+
"https://api.github.com/repos/${{ matrix.upstream_repo }}/releases?per_page=100")
78+
79+
if ! echo "$RESPONSE" | jq -e 'type == "array"' > /dev/null 2>&1; then
80+
echo "::error::GitHub API did not return an array for ${{ matrix.upstream_repo }}/releases. Response: $(echo "$RESPONSE" | jq -c .)"
81+
exit 1
82+
fi
83+
84+
TAG=$(echo "$RESPONSE" \
7685
| jq -r --arg prefix "${{ matrix.tag_prefix }}" \
7786
'[.[] | select(.tag_name | startswith($prefix) and (contains("/") | not))] | first | .tag_name | ltrimstr($prefix)')
7887
echo "version=$TAG" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)