Skip to content

Commit 70ff42e

Browse files
committed
Enhance ddb-publish action to search multiple workflows for successful runs and improve error handling
1 parent b30ec6f commit 70ff42e

1 file changed

Lines changed: 37 additions & 19 deletions

File tree

actions/ddb-publish/action.yml

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,48 @@ runs:
6868
branch="${ACTION_REF#refs/heads/}"
6969
echo "[ddb-publish] No release found for ref '${ACTION_REF}'. Falling back to latest workflow artifact on branch '${branch}' from '${ACTION_REPO}'."
7070
71-
set +e
72-
run_id="$(gh run list \
73-
--repo "${ACTION_REPO}" \
74-
--workflow "stage-3-build.yaml" \
75-
--branch "${branch}" \
76-
--status success \
77-
--json databaseId \
78-
--jq '.[0].databaseId' 2>/tmp/ddb_publish_run_list_err.log)"
79-
rc=$?
80-
set -e
81-
82-
if [[ $rc -ne 0 ]]; then
83-
echo "ERROR: Failed to query workflow runs from '${ACTION_REPO}'." >&2
84-
cat /tmp/ddb_publish_run_list_err.log >&2 || true
85-
echo "HINT: ensure the token has read access to '${ACTION_REPO}' and workflow permissions allow actions read." >&2
86-
exit 1
87-
fi
71+
run_id=""
72+
workflow_used=""
73+
74+
for workflow_file in "stage-3-build.yaml" "cicd-1-pull-request.yaml"; do
75+
echo "[ddb-publish] Looking for successful runs in workflow '${workflow_file}'."
76+
77+
set +e
78+
run_id_candidate="$(gh run list \
79+
--repo "${ACTION_REPO}" \
80+
--workflow "${workflow_file}" \
81+
--branch "${branch}" \
82+
--status success \
83+
--json databaseId \
84+
--jq '.[0].databaseId' 2>/tmp/ddb_publish_run_list_err.log)"
85+
rc=$?
86+
set -e
87+
88+
if [[ $rc -ne 0 ]]; then
89+
if grep -q "HTTP 404" /tmp/ddb_publish_run_list_err.log; then
90+
echo "[ddb-publish] Workflow '${workflow_file}' not found on default branch; trying next workflow candidate."
91+
continue
92+
fi
93+
94+
echo "ERROR: Failed to query workflow runs from '${ACTION_REPO}' for workflow '${workflow_file}'." >&2
95+
cat /tmp/ddb_publish_run_list_err.log >&2 || true
96+
echo "HINT: ensure the token has read access to '${ACTION_REPO}' and workflow permissions allow actions read." >&2
97+
exit 1
98+
fi
99+
100+
if [[ -n "${run_id_candidate}" && "${run_id_candidate}" != "null" ]]; then
101+
run_id="${run_id_candidate}"
102+
workflow_used="${workflow_file}"
103+
break
104+
fi
105+
done
88106
89107
if [[ -z "${run_id}" || "${run_id}" == "null" ]]; then
90-
echo "ERROR: Could not find a successful 'stage-3-build.yaml' run for branch '${branch}' in '${ACTION_REPO}' to download artifact '${WORKFLOW_ARTIFACT_NAME}'." >&2
108+
echo "ERROR: Could not find a successful run on branch '${branch}' in '${ACTION_REPO}' containing artifact '${WORKFLOW_ARTIFACT_NAME}'. Checked workflows: stage-3-build.yaml, cicd-1-pull-request.yaml." >&2
91109
exit 1
92110
fi
93111
94-
echo "[ddb-publish] Downloading artifact '${WORKFLOW_ARTIFACT_NAME}' from workflow run ${run_id} in '${ACTION_REPO}'."
112+
echo "[ddb-publish] Downloading artifact '${WORKFLOW_ARTIFACT_NAME}' from workflow run ${run_id} (${workflow_used}) in '${ACTION_REPO}'."
95113
gh run download "${run_id}" --repo "${ACTION_REPO}" --name "${WORKFLOW_ARTIFACT_NAME}" --dir "${download_dir}"
96114
97115
tarball_path="${download_dir}/${RELEASE_ASSET_NAME}"

0 commit comments

Comments
 (0)