Skip to content

Commit 9234b39

Browse files
committed
Add workflow artifact upload and improve ddb-publish bundle resolution
1 parent c2f003c commit 9234b39

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

.github/workflows/stage-3-build.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ jobs:
5454
uses: actions/checkout@v4
5555

5656
- name: "Bundle ddb-publish"
57+
id: bundle
5758
uses: ./.github/actions/bundle-ddb-publish
5859
with:
5960
node-version: "${{ inputs.nodejs_version }}"
6061
run-typecheck: "false"
6162

63+
- name: "Upload bundle as workflow artifact"
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: ddb-publish-bundle
67+
path: "${{ steps.bundle.outputs.tarball-path }}"
68+
6269
artefact-1:
6370
name: "Artefact 1"
6471
runs-on: ubuntu-latest

actions/ddb-publish/action.yml

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,82 @@ inputs:
2424
runs:
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

Comments
 (0)