Skip to content

Commit 2f98b13

Browse files
committed
ci: handle devcontainer metadata properly
1 parent 7e8d786 commit 2f98b13

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

.github/workflows/wc-build-push.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,20 @@ jobs:
8989
id: metadata
9090
with:
9191
images: ${{ needs.sanitize-image-name.outputs.fully-qualified-image-name }}
92-
# Generate image LABEL for devcontainer.metadata
93-
# the sed expression is a workaround for quotes being eaten in arrays (e.g. ["x", "y", "z"] -> ["x",y,"z"])
94-
- run: echo "metadata=$(jq -cj '[.]' ".devcontainer/${CONTAINER_FLAVOR}/devcontainer-metadata-vscode.json" | sed 's/,"/, "/g')" >> "$GITHUB_OUTPUT"
92+
- name: Generate image LABEL for devcontainer.metadata
93+
run: |
94+
set -Eeuo pipefail
95+
96+
if ([ -z "${DEVCONTAINER_METADATA:-}" ] || [ ! -f "${DEVCONTAINER_METADATA}" ]); then
97+
echo "devcontainer-metadata input not set or file does not exist, skipping devcontainer.metadata label"
98+
echo "metadata=" >> "$GITHUB_OUTPUT"
99+
exit 0
100+
fi
101+
102+
# the sed expression is a workaround for quotes being eaten in arrays (e.g. ["x", "y", "z"] -> ["x",y,"z"])
103+
echo "metadata=devcontainer.metadata\=$(jq -cj '[.]' "${DEVCONTAINER_METADATA}" | sed 's/,"/, "/g')" >> "$GITHUB_OUTPUT"
104+
env:
105+
DEVCONTAINER_METADATA: ${{ inputs.devcontainer-metadata }}
95106
id: devcontainer-metadata
96107
- run: echo "git-commit-epoch=$(git log -1 --pretty=%ct)" >> "$GITHUB_OUTPUT"
97108
id: devcontainer-epoch
@@ -107,7 +118,7 @@ jobs:
107118
tags: ${{ needs.sanitize-image-name.outputs.fully-qualified-image-name }}
108119
labels: |
109120
${{ steps.metadata.outputs.labels }}
110-
devcontainer.metadata=${{ steps.devcontainer-metadata.outputs.metadata }}
121+
${{ steps.devcontainer-metadata.outputs.metadata }}
111122
annotations: ${{ steps.metadata.outputs.annotations }}
112123
sbom: true
113124
outputs: type=image,push-by-digest=true,name-canonical=true

0 commit comments

Comments
 (0)