Skip to content

Commit 83bceed

Browse files
committed
ci(internal-workflows): make release publishing recoverable
1 parent eb6c8ab commit 83bceed

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎.github/workflows/publish.yaml‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ on:
66
release:
77
types:
88
- published
9+
workflow_dispatch:
10+
inputs:
11+
release_tag:
12+
description: Existing release tag to publish.
13+
required: true
14+
type: string
915

1016
concurrency:
11-
group: ${{ github.workflow }}-${{ github.event.release.tag_name }}
17+
group: ${{ github.workflow }}-${{ github.event.release.tag_name || inputs.release_tag }}
1218
cancel-in-progress: true
1319

1420
env:
@@ -17,8 +23,8 @@ env:
1723
image_path: images/homelab-workspace
1824
template_path: templates/kubernetes/homelab-workspace
1925
template_name: homelab-workspace
20-
source_ref: ${{ github.event.release.tag_name }}
21-
source_sha: ${{ github.event.release.tag_name }}
26+
source_ref: ${{ github.event.release.tag_name || inputs.release_tag }}
27+
source_sha: ${{ github.event.release.tag_name || inputs.release_tag }}
2228

2329
jobs:
2430
publish-image:
@@ -33,7 +39,7 @@ jobs:
3339
platforms: linux/amd64,linux/arm64
3440
private_registry_repository: ${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace
3541
private_registry_build_cache: ${{ vars.CONTAINER_REGISTRY_CACHE_PATH }}/coder-workspace
36-
git_ref: ${{ github.event.release.tag_name }}
42+
git_ref: ${{ github.event.release.tag_name || inputs.release_tag }}
3743
ghcr_repository: ppat/coder-workspace
3844
timeout_minutes: 180
3945
secrets:
@@ -50,11 +56,20 @@ jobs:
5056
runs-on: ubuntu-latest
5157
timeout-minutes: 15
5258
steps:
53-
- name: Checkout
59+
- name: Checkout publishing automation
5460
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
5561
with:
5662
fetch-depth: 1
5763
persist-credentials: false
64+
path: .automation
65+
ref: main
66+
67+
- name: Checkout release source
68+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
69+
with:
70+
fetch-depth: 1
71+
persist-credentials: false
72+
path: release
5873
ref: ${{ env.source_ref }}
5974

6075
- name: Tailscale Connect
@@ -67,16 +82,16 @@ jobs:
6782
version: "1.102.4"
6883

6984
- name: Login to Coder
70-
uses: ./actions/coder-cli-login
85+
uses: ./.automation/actions/coder-cli-login
7186
with:
7287
coder_url: ${{ secrets.CODER_URL }}
7388
coder_email: ${{ secrets.CODER_EMAIL }}
7489
coder_password: ${{ secrets.CODER_PASSWORD }}
7590

7691
- name: Publish template
77-
uses: ./actions/coder-template-push
92+
uses: ./.automation/actions/coder-template-push
7893
with:
79-
template_dir: ${{ env.template_path }}
94+
template_dir: release/${{ env.template_path }}
8095
template_name: ${{ env.template_name }}
8196
template_version: ${{ env.source_sha }}
8297
workspace_image: "ghcr.io/ppat/coder-workspace:${{ needs.publish-image.outputs.image_tag }}"

‎actions/coder-template-push/action.yaml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ runs:
5454
TEMPLATE_MESSAGE: ${{ inputs.message }}
5555
# yamllint disable-line rule:indentation
5656
run: |
57+
existing_version="$(coder templates versions list "${TEMPLATE_NAME}" --include-archived --output json | jq --compact-output \
58+
--arg name "${TEMPLATE_VERSION}" '.[] | select(.TemplateVersion.name == $name)')"
59+
if [[ -n "${existing_version}" ]]; then
60+
existing_status="$(jq --raw-output '.TemplateVersion.job.status' <<<"${existing_version}")"
61+
existing_active="$(jq --raw-output '.active' <<<"${existing_version}")"
62+
existing_id="$(jq --raw-output '.TemplateVersion.id' <<<"${existing_version}")"
63+
if [[ "${existing_status}" != "failed" || "${existing_active}" != "false" ]]; then
64+
echo "::error::Template version ${TEMPLATE_VERSION} already exists with status=${existing_status}, active=${existing_active}; refusing to replace it."
65+
exit 1
66+
fi
67+
68+
coder_url="$(<"${HOME}/.config/coderv2/url")"
69+
coder_session_token="$(<"${HOME}/.config/coderv2/session")"
70+
failed_version_name="${TEMPLATE_VERSION}-failed-${existing_id%%-*}"
71+
curl --fail --silent --show-error --request PATCH \
72+
--header "Coder-Session-Token: ${coder_session_token}" \
73+
--header "Content-Type: application/json" \
74+
--data "$(jq --null-input --arg name "${failed_version_name}" '{name: $name}')" \
75+
"${coder_url}/api/v2/templateversions/${existing_id}" >/dev/null
76+
fi
77+
5778
variables_file="${RUNNER_TEMP}/coder-template-variables.yaml"
5879
jq --null-input \
5980
--arg kubernetes_config_path "${KUBERNETES_CONFIG_PATH}" \

0 commit comments

Comments
 (0)