@@ -24,34 +24,82 @@ inputs:
2424runs :
2525 using : " composite"
2626 steps :
27- - name : Download ddb-publish bundle from release
27+ - name : Resolve and download ddb-publish bundle
2828 shell : bash
2929 env :
3030 GH_TOKEN : ${{ github.token }}
31- RELEASE_TAG : ${{ github.action_ref }}
32- ASSET_NAME : ddb-publish-bundle.tgz
31+ REPO : ${{ github.repository }}
32+ ACTION_REF : ${{ github.action_ref }}
33+ RELEASE_ASSET_NAME : ddb-publish-bundle.tgz
34+ WORKFLOW_ARTIFACT_NAME : ddb-publish-bundle
3335 run : |
3436 set -euo pipefail
3537
36- if [[ "${RELEASE_TAG}" == "" ]]; then
37- echo "ERROR: github.action_ref is empty; can't determine which release asset to download." >&2
38+ download_dir="${RUNNER_TEMP}/ddb-publish"
39+ unpack_dir="${download_dir}/unpacked"
40+
41+ mkdir -p "${download_dir}" "${unpack_dir}"
42+
43+ echo "[ddb-publish] repo=${REPO}"
44+ echo "[ddb-publish] action_ref=${ACTION_REF:-<empty>}"
45+
46+ if [[ -z "${ACTION_REF}" ]]; then
47+ echo "ERROR: github.action_ref is empty; unable to locate release asset or branch artifact." >&2
3848 exit 1
3949 fi
4050
41- # GitHub provides a temporary token by default; no extra PAT needed.
42- gh release download "${RELEASE_TAG}" --repo "${GITHUB_REPOSITORY}" --pattern "${ASSET_NAME}" --dir "${RUNNER_TEMP}/ddb-publish"
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}"
55+ tar -xzf "${download_dir}/${RELEASE_ASSET_NAME}" -C "${unpack_dir}"
56+ echo "[ddb-publish] Bundle extracted from release asset."
57+ exit 0
58+ fi
59+
60+ # Otherwise treat the ref as a branch-like ref and fetch the latest successful CI artifact.
61+ 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}'."
63+
64+ run_id="$(gh run list \
65+ --repo "${REPO}" \
66+ --workflow "stage-3-build.yaml" \
67+ --branch "${branch}" \
68+ --status success \
69+ --json databaseId \
70+ --jq '.[0].databaseId')"
4371
44- mkdir -p "${RUNNER_TEMP}/ddb-publish/unpacked"
45- tar -xzf "${RUNNER_TEMP}/ddb-publish/${ASSET_NAME}" -C "${RUNNER_TEMP}/ddb-publish/unpacked"
72+ 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
74+ exit 1
75+ fi
76+
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}"
79+
80+ tarball_path="${download_dir}/${RELEASE_ASSET_NAME}"
81+ if [[ ! -f "${tarball_path}" ]]; then
82+ echo "ERROR: Downloaded artifact did not contain expected tarball '${RELEASE_ASSET_NAME}'." >&2
83+ ls -la "${download_dir}" >&2
84+ exit 1
85+ fi
86+
87+ tar -xzf "${tarball_path}" -C "${unpack_dir}"
88+ echo "[ddb-publish] Bundle extracted from workflow artifact."
4689
4790 - name : Run publisher
4891 shell : bash
4992 run : |
5093 set -euo pipefail
5194
95+ echo "[ddb-publish] Starting publish run"
96+ echo "[ddb-publish] source='${{ inputs.source-path }}' env='${{ inputs.target-env }}' table='${{ inputs.table-name }}' force='${{ inputs.force }}' dry-run='${{ inputs.dry-run }}'"
97+
5298 node "${RUNNER_TEMP}/ddb-publish/unpacked/index.cjs" \
5399 --source "${{ inputs.source-path }}" \
54100 --env "${{ inputs.target-env }}" \
55101 --table "${{ inputs.table-name }}" \
56102 $([[ "${{ inputs.force }}" == "true" ]] && echo "--force") \
57103 $([[ "${{ inputs.dry-run }}" == "true" ]] && echo "--dry-run")
104+
105+ echo "[ddb-publish] Publish run completed"
0 commit comments