Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,40 @@ jobs:
fi

printf '%s' "${secret_value}" | gcloud secrets versions add "${secret_name}" --project "${GCP_PROJECT_ID}" --data-file=- >/dev/null
cleanup_secret_versions "${secret_name}"
}

cleanup_secret_versions() {
local secret_name="$1"
local old_versions

old_versions="$(
gcloud secrets versions list "${secret_name}" \
--project "${GCP_PROJECT_ID}" \
--format=json \
| python -c 'import json,sys
rows = json.load(sys.stdin)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Indent embedded Python inside the run block

In .github/workflows/main.yml, these newly added Python lines are not indented under the run: | block. Because YAML block scalar content must remain indented, rows = json.load(sys.stdin) terminates the shell script and becomes top-level YAML, so GitHub Actions cannot parse/load this workflow when this file is present.

Useful? React with 👍 / 👎.

active = [
int(row["name"].rsplit("/", 1)[-1])
for row in rows
if row.get("state") in {"ENABLED", "DISABLED"}
]
if len(active) <= 1:
sys.exit(0)
keep = max(active)
print("\n".join(str(version) for version in active if version != keep))
'
)"

while IFS= read -r version; do
if [ -z "${version}" ]; then
continue
fi
gcloud secrets versions destroy "${version}" \
--secret "${secret_name}" \
--project "${GCP_PROJECT_ID}" \
--quiet >/dev/null
done <<< "${old_versions}"
}

mask_if_present() {
Expand Down