From e8396034acca009716a8431b23aa924efaa057a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JC=20Gr=C3=BCnhage?= Date: Tue, 11 Mar 2025 23:59:30 +0100 Subject: [PATCH] fix(ci): fail meta using jq halt_error if data is unexpectedly missing (#11151) ## Problem When the githb API is having problems, we might not get data back, and are happily setting vars as empty. This causes problems down the line. See https://github.com/neondatabase/neon/actions/runs/13718859397/job/38381946590?pr=11132#step:5:1 for example. ## Summary of changes Fail the `meta` job if we don't get expected data back from github. --- .github/scripts/previous-releases.jq | 6 ++++++ .github/workflows/_meta.yml | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/scripts/previous-releases.jq b/.github/scripts/previous-releases.jq index b0b00bce18..51204da099 100644 --- a/.github/scripts/previous-releases.jq +++ b/.github/scripts/previous-releases.jq @@ -17,6 +17,12 @@ ({}; .[$entry.component] |= (if . == null or $entry.version > .version then $entry else . end)) +# Ensure that each component exists, or fail +| (["storage", "compute", "proxy"] - (keys)) as $missing +| if ($missing | length) > 0 then + "Error: Found no release for \($missing | join(", "))!\n" | halt_error(1) + else . end + # Convert the resulting object into an array of formatted strings | to_entries | map("\(.key)=\(.value.full)") diff --git a/.github/workflows/_meta.yml b/.github/workflows/_meta.yml index a3fc125648..cae7fae6a4 100644 --- a/.github/workflows/_meta.yml +++ b/.github/workflows/_meta.yml @@ -24,6 +24,10 @@ on: permissions: {} +defaults: + run: + shell: bash -euo pipefail {0} + jobs: tags: runs-on: ubuntu-22.04 @@ -83,7 +87,11 @@ jobs: echo "tag=release-compute-$(git rev-list --count HEAD)" | tee -a $GITHUB_OUTPUT ;; pr|storage-rc-pr|compute-rc-pr|proxy-rc-pr) - BUILD_AND_TEST_RUN_ID=$(gh run list -b $CURRENT_BRANCH -c $CURRENT_SHA -w 'Build and Test' -L 1 --json databaseId --jq '.[].databaseId') + BUILD_AND_TEST_RUN_ID=$(gh api --paginate \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/repos/${GITHUB_REPOSITORY}/actions/runs?head_sha=${CURRENT_SHA}&branch=${CURRENT_BRANCH}" \ + | jq '[.workflow_runs[] | select(.name == "Build and Test")][0].id // ("Error: No matching workflow run found." | halt_error(1))') echo "tag=$BUILD_AND_TEST_RUN_ID" | tee -a $GITHUB_OUTPUT ;; workflow-dispatch)