Skip to content

Commit b30ec6f

Browse files
committed
Refactor ddb-publish action to use action repository for artifact downloads and improve error handling
1 parent 9234b39 commit b30ec6f

1 file changed

Lines changed: 30 additions & 13 deletions

File tree

actions/ddb-publish/action.yml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ runs:
2828
shell: bash
2929
env:
3030
GH_TOKEN: ${{ github.token }}
31-
REPO: ${{ github.repository }}
31+
CALLER_REPO: ${{ github.repository }}
32+
ACTION_REPO: ${{ github.action_repository }}
3233
ACTION_REF: ${{ github.action_ref }}
3334
RELEASE_ASSET_NAME: ddb-publish-bundle.tgz
3435
WORKFLOW_ARTIFACT_NAME: ddb-publish-bundle
@@ -40,42 +41,58 @@ runs:
4041
4142
mkdir -p "${download_dir}" "${unpack_dir}"
4243
43-
echo "[ddb-publish] repo=${REPO}"
44+
echo "[ddb-publish] caller_repo=${CALLER_REPO}"
45+
echo "[ddb-publish] action_repo=${ACTION_REPO}"
4446
echo "[ddb-publish] action_ref=${ACTION_REF:-<empty>}"
4547
4648
if [[ -z "${ACTION_REF}" ]]; then
4749
echo "ERROR: github.action_ref is empty; unable to locate release asset or branch artifact." >&2
4850
exit 1
4951
fi
5052
51-
# Prefer release assets when the action ref is a tag with a matching release.
52-
if gh release view "${ACTION_REF}" --repo "${REPO}" >/dev/null 2>&1; then
53-
echo "[ddb-publish] Found release for ref '${ACTION_REF}'. Downloading release asset '${RELEASE_ASSET_NAME}'."
54-
gh release download "${ACTION_REF}" --repo "${REPO}" --pattern "${RELEASE_ASSET_NAME}" --dir "${download_dir}"
53+
if [[ -z "${ACTION_REPO}" ]]; then
54+
echo "ERROR: github.action_repository is empty; unable to determine where to fetch bundle artifacts." >&2
55+
exit 1
56+
fi
57+
58+
# Prefer release assets when the action ref is a tag with a matching release in the action repo.
59+
if gh release view "${ACTION_REF}" --repo "${ACTION_REPO}" >/dev/null 2>&1; then
60+
echo "[ddb-publish] Found release for ref '${ACTION_REF}' in '${ACTION_REPO}'. Downloading '${RELEASE_ASSET_NAME}'."
61+
gh release download "${ACTION_REF}" --repo "${ACTION_REPO}" --pattern "${RELEASE_ASSET_NAME}" --dir "${download_dir}"
5562
tar -xzf "${download_dir}/${RELEASE_ASSET_NAME}" -C "${unpack_dir}"
5663
echo "[ddb-publish] Bundle extracted from release asset."
5764
exit 0
5865
fi
5966
60-
# Otherwise treat the ref as a branch-like ref and fetch the latest successful CI artifact.
67+
# Otherwise treat the ref as a branch-like ref and fetch the latest successful CI artifact from the action repo.
6168
branch="${ACTION_REF#refs/heads/}"
62-
echo "[ddb-publish] No release found for ref '${ACTION_REF}'. Falling back to latest workflow artifact on branch '${branch}'."
69+
echo "[ddb-publish] No release found for ref '${ACTION_REF}'. Falling back to latest workflow artifact on branch '${branch}' from '${ACTION_REPO}'."
6370
71+
set +e
6472
run_id="$(gh run list \
65-
--repo "${REPO}" \
73+
--repo "${ACTION_REPO}" \
6674
--workflow "stage-3-build.yaml" \
6775
--branch "${branch}" \
6876
--status success \
6977
--json databaseId \
70-
--jq '.[0].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
7188
7289
if [[ -z "${run_id}" || "${run_id}" == "null" ]]; then
73-
echo "ERROR: Could not find a successful 'stage-3-build.yaml' run for branch '${branch}' to download artifact '${WORKFLOW_ARTIFACT_NAME}'." >&2
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
7491
exit 1
7592
fi
7693
77-
echo "[ddb-publish] Downloading artifact '${WORKFLOW_ARTIFACT_NAME}' from workflow run ${run_id}."
78-
gh run download "${run_id}" --repo "${REPO}" --name "${WORKFLOW_ARTIFACT_NAME}" --dir "${download_dir}"
94+
echo "[ddb-publish] Downloading artifact '${WORKFLOW_ARTIFACT_NAME}' from workflow run ${run_id} in '${ACTION_REPO}'."
95+
gh run download "${run_id}" --repo "${ACTION_REPO}" --name "${WORKFLOW_ARTIFACT_NAME}" --dir "${download_dir}"
7996
8097
tarball_path="${download_dir}/${RELEASE_ASSET_NAME}"
8198
if [[ ! -f "${tarball_path}" ]]; then

0 commit comments

Comments
 (0)