Skip to content

Commit b44669b

Browse files
committed
ci(release): migrate to release-please
1 parent f6a347b commit b44669b

8 files changed

Lines changed: 209 additions & 241 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
# yamllint disable rule:line-length
3+
name: publish
4+
5+
on:
6+
pull_request:
7+
paths:
8+
- '.github/workflows/publish.yaml'
9+
- 'images/homelab-workspace/**'
10+
- 'templates/kubernetes/homelab-workspace/**'
11+
release:
12+
types:
13+
- published
14+
workflow_dispatch:
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.release.tag_name || github.ref }}
18+
cancel-in-progress: true
19+
20+
env:
21+
image_name: ${{ secrets.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace
22+
image_cache_name: ${{ secrets.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_REGISTRY_CACHE_PATH }}/coder-workspace
23+
image_path: images/homelab-workspace
24+
template_path: templates/kubernetes/homelab-workspace
25+
publish_mode: ${{ github.event_name == 'release' && 'release' || 'test' }}
26+
source_ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.pull_request.head.sha || github.sha }}
27+
28+
jobs:
29+
publish-image:
30+
permissions:
31+
contents: read
32+
packages: write
33+
uses: ppat/github-workflows/.github/workflows/build-docker-image.yaml@5a96ced8ceefd58062f6b91ee9d6f3a31cd06e1c # v6.0.0 (unmerged PR #615 -- repoint to the v6.0.0 tag before merge)
34+
with:
35+
image_context_path: images/homelab-workspace
36+
label_title: "Homelab Workspace"
37+
label_description: "Homelab workspace image"
38+
platforms: linux/amd64,linux/arm64
39+
private_registry_repository: ${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace
40+
private_registry_build_cache: ${{ vars.CONTAINER_REGISTRY_CACHE_PATH }}/coder-workspace
41+
git_ref: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.pull_request.head.sha || github.sha }}
42+
ghcr_repository: ${{ github.event_name == 'release' && 'ppat/coder-workspace' || '' }}
43+
timeout_minutes: 180
44+
secrets:
45+
private_registry_username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
46+
private_registry_token: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
47+
private_registry: ${{ secrets.CONTAINER_REGISTRY }}
48+
tailscale_oauth_client_id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }}
49+
tailscale_oauth_secret: ${{ secrets.TAILSCALE_OAUTH_SECRET }}
50+
build_secrets: |
51+
FETCH_GH_TOKEN=${{ secrets.GITHUB_TOKEN }}
52+
53+
publish-template:
54+
needs: [publish-image]
55+
runs-on: ubuntu-latest
56+
timeout-minutes: 15
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
60+
with:
61+
fetch-depth: 1
62+
persist-credentials: false
63+
ref: ${{ env.source_ref }}
64+
65+
- name: Tailscale Connect
66+
uses: tailscale/github-action@6cae46e2d796f265265cfcf628b72a32b4d7cade # v3
67+
with:
68+
oauth-client-id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }}
69+
oauth-secret: ${{ secrets.TAILSCALE_OAUTH_SECRET }}
70+
tags: tag:github-action-ci-runner
71+
# renovate: datasource=github-releases depName=tailscale/tailscale
72+
version: "1.102.3"
73+
74+
- name: Login to Coder
75+
id: login
76+
env:
77+
CODER_URL: "${{ secrets.CODER_URL }}"
78+
shell: bash
79+
# yamllint disable-line rule:indentation
80+
run: |
81+
while ! curl -fsSL "${CODER_URL}" > /dev/null; do
82+
echo "Waiting for coder service to be ready... sleep 5s!"
83+
sleep 5
84+
done
85+
echo "Coder service is accepting connections..."
86+
echo
87+
88+
echo "Generating authentication token..."
89+
export CODER_SESSION_TOKEN
90+
CODER_SESSION_TOKEN=$(curl -X POST "${CODER_URL}/api/v2/users/login" \
91+
-H 'Content-Type: application/json' \
92+
-H 'Accept: application/json' \
93+
--data '{"email": "'${{ secrets.CODER_EMAIL }}'", "password": "'${{ secrets.CODER_PASSWORD }}'"}' \
94+
| jq -r .session_token)
95+
echo "::add-mask::${CODER_SESSION_TOKEN}"
96+
if [[ -z "${CODER_SESSION_TOKEN}" || "${CODER_SESSION_TOKEN}" = "null" ]]; then
97+
echo "Error generating coder authentication token."
98+
exit 1
99+
fi
100+
echo "Authentication token generated."
101+
echo
102+
echo "Determining coder version..."
103+
export CODER_VERSION
104+
CODER_VERSION=$(curl -fsSL "${CODER_URL}/api/v2/buildinfo" | jq -r .version | cut -d'+' -f1 | cut -d'v' -f2)
105+
echo "Installing coder CLI..."
106+
curl -fsSL https://coder.com/install.sh | sh -s -- --method standalone --version "${CODER_VERSION}"
107+
echo
108+
echo "Logging into Coder..."
109+
coder login --use-token-as-session "${CODER_URL}"
110+
111+
- name: Publish template
112+
id: publish-template
113+
env:
114+
TEMPLATE_DIR: ${{ env.template_path }}
115+
TEMPLATE_VERSION: ${{ env.source_ref }}
116+
WORKSPACE_IMAGE: "${{ secrets.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace:${{ needs.publish-image.outputs.image_tag }}"
117+
PUBLISH_MODE: ${{ env.publish_mode }}
118+
shell: bash
119+
# yamllint disable-line rule:indentation
120+
run: |
121+
if [[ "${PUBLISH_MODE}" == "release" ]]; then
122+
export TEMPLATE_NAME
123+
TEMPLATE_NAME="$(echo "${TEMPLATE_DIR}" | cut -d/ -f3)"
124+
export RELEASE_MSG="[Release Notes](https://github.com/${{ github.repository }}/releases/tag/${TEMPLATE_VERSION})"
125+
export TEST_MODE=false
126+
else
127+
export TEMPLATE_NAME
128+
TEMPLATE_NAME="$(echo "${TEMPLATE_DIR}" | cut -d/ -f3)-test"
129+
export RELEASE_MSG="[Changes](https://github.com/${{ github.repository }}/commit/${TEMPLATE_VERSION})"
130+
export TEST_MODE=true
131+
fi
132+
echo "Publishing template ${TEMPLATE_DIR} as ${TEMPLATE_NAME}..."
133+
set -x
134+
coder template push \
135+
--directory "${TEMPLATE_DIR}" \
136+
--var "workspace_image=${WORKSPACE_IMAGE}" \
137+
--var test_mode=${TEST_MODE} \
138+
--name "${TEMPLATE_VERSION}" \
139+
--message "${RELEASE_MSG}" \
140+
--yes \
141+
"${TEMPLATE_NAME}"
142+
set +x
143+
echo
144+
echo "Confirming template has been published..."
145+
coder templates list --output json > /tmp/templates.json
146+
export SELECTED_TEMPLATE
147+
SELECTED_TEMPLATE=$(cat /tmp/templates.json | jq -r '.[] | select(.Template.name == "'"${TEMPLATE_NAME}"'")')
148+
if [[ -z $SELECTED_TEMPLATE ]]; then
149+
echo "Could not find any template published as $TEMPLATE_NAME."
150+
exit 1
151+
fi
152+
echo "Template has been published successfully."
153+
154+
- name: Tailscale Disconnect
155+
if: success() || failure()
156+
run: sudo -E tailscale logout

.github/workflows/release.yaml

Lines changed: 7 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -3,164 +3,19 @@
33
name: release
44

55
on:
6-
pull_request:
7-
paths:
8-
- '.github/workflows/release.yaml'
9-
- '.releaserc.js'
10-
- 'images/homelab-workspace/**'
11-
- 'templates/**'
6+
push:
7+
branches:
8+
- main
129
workflow_dispatch:
13-
inputs:
14-
test_publish:
15-
description: "Test Publish"
16-
required: true
17-
type: boolean
1810

1911
concurrency:
20-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
21-
cancel-in-progress: true
12+
group: ${{ github.workflow }}-${{ github.ref }}
2213

23-
env:
24-
image_name: ${{ secrets.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace
25-
image_cache_name: ${{ secrets.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_REGISTRY_CACHE_PATH }}/coder-workspace
26-
image_path: images/homelab-workspace
27-
template_path: templates/kubernetes/homelab-workspace
28-
default_branch: main
14+
permissions: {}
2915

3016
jobs:
31-
create-release:
32-
uses: ppat/github-workflows/.github/workflows/release-semantic.yaml@5a96ced8ceefd58062f6b91ee9d6f3a31cd06e1c # v6.0.0
33-
with:
34-
dry_run: ${{ (github.event_name == 'pull_request') || (github.event_name == 'workflow_dispatch' && github.event.inputs.test_publish == 'true') }}
35-
release_branch: ${{ github.head_ref || github.ref_name }}
17+
release:
18+
uses: ppat/github-workflows/.github/workflows/release-please.yaml@5a96ced8ceefd58062f6b91ee9d6f3a31cd06e1c # v6.0.0
3619
secrets:
3720
app_id: ${{ secrets.HOMELAB_BOT_APP_ID }}
3821
app_private_key: ${{ secrets.HOMELAB_BOT_APP_PRIVATE_KEY }}
39-
40-
publish-image:
41-
needs: [create-release]
42-
permissions:
43-
contents: read
44-
packages: write
45-
uses: ppat/github-workflows/.github/workflows/build-docker-image.yaml@5a96ced8ceefd58062f6b91ee9d6f3a31cd06e1c # v6.0.0 (unmerged PR #615 -- repoint to the v6.0.0 tag before merge)
46-
with:
47-
image_context_path: images/homelab-workspace
48-
label_title: "Homelab Workspace"
49-
label_description: "Homelab workspace image"
50-
platforms: linux/amd64,linux/arm64
51-
private_registry_repository: ${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace
52-
private_registry_build_cache: ${{ vars.CONTAINER_REGISTRY_CACHE_PATH }}/coder-workspace
53-
git_ref: ${{ needs.create-release.outputs.released_gitref }}
54-
ghcr_repository: ${{ needs.create-release.outputs.released_version != 'v0.0.0' && 'ppat/coder-workspace' || '' }}
55-
timeout_minutes: 180
56-
secrets:
57-
private_registry_username: ${{ secrets.CONTAINER_REGISTRY_USERNAME }}
58-
private_registry_token: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }}
59-
private_registry: ${{ secrets.CONTAINER_REGISTRY }}
60-
tailscale_oauth_client_id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }}
61-
tailscale_oauth_secret: ${{ secrets.TAILSCALE_OAUTH_SECRET }}
62-
build_secrets: |
63-
FETCH_GH_TOKEN=${{ secrets.GITHUB_TOKEN }}
64-
65-
publish-template:
66-
needs: [create-release, publish-image]
67-
runs-on: ubuntu-latest
68-
timeout-minutes: 15
69-
steps:
70-
- name: Checkout
71-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
72-
with:
73-
fetch-depth: 1
74-
persist-credentials: false
75-
76-
- name: Tailscale Connect
77-
uses: tailscale/github-action@6cae46e2d796f265265cfcf628b72a32b4d7cade # v3
78-
with:
79-
oauth-client-id: ${{ secrets.TAILSCALE_OAUTH_CLIENT_ID }}
80-
oauth-secret: ${{ secrets.TAILSCALE_OAUTH_SECRET }}
81-
tags: tag:github-action-ci-runner
82-
# renovate: datasource=github-releases depName=tailscale/tailscale
83-
version: "1.102.3"
84-
85-
- name: Login to Coder
86-
id: login
87-
env:
88-
CODER_URL: "${{ secrets.CODER_URL }}"
89-
shell: bash
90-
# yamllint disable-line rule:indentation
91-
run: |
92-
while ! curl -fsSL "${CODER_URL}" > /dev/null; do
93-
echo "Waiting for coder service to be ready... sleep 5s!"
94-
sleep 5
95-
done
96-
echo "Coder service is accepting connections..."
97-
echo
98-
99-
echo "Generating authentication token..."
100-
export CODER_SESSION_TOKEN
101-
CODER_SESSION_TOKEN=$(curl -X POST "${CODER_URL}/api/v2/users/login" \
102-
-H 'Content-Type: application/json' \
103-
-H 'Accept: application/json' \
104-
--data '{"email": "'${{ secrets.CODER_EMAIL }}'", "password": "'${{ secrets.CODER_PASSWORD }}'"}' \
105-
| jq -r .session_token)
106-
echo "::add-mask::${CODER_SESSION_TOKEN}"
107-
if [[ -z "${CODER_SESSION_TOKEN}" || "${CODER_SESSION_TOKEN}" = "null" ]]; then
108-
echo "Error generating coder authentication token."
109-
exit 1
110-
fi
111-
echo "Authentication token generated."
112-
echo
113-
echo "Determining coder version..."
114-
export CODER_VERSION
115-
CODER_VERSION=$(curl -fsSL "${CODER_URL}/api/v2/buildinfo" | jq -r .version | cut -d'+' -f1 | cut -d'v' -f2)
116-
echo "Installing coder CLI..."
117-
curl -fsSL https://coder.com/install.sh | sh -s -- --method standalone --version "${CODER_VERSION}"
118-
echo
119-
echo "Logging into Coder..."
120-
coder login --use-token-as-session "${CODER_URL}"
121-
122-
- name: Publish template
123-
id: publish-template
124-
env:
125-
TEMPLATE_DIR: ${{ env.template_path }}
126-
TEMPLATE_VERSION: "${{ needs.create-release.outputs.released_version != 'v0.0.0' && needs.create-release.outputs.released_version || needs.create-release.outputs.released_sha }}"
127-
WORKSPACE_IMAGE: "${{ secrets.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_REGISTRY_PATH }}/coder-workspace:${{ needs.publish-image.outputs.image_tag }}"
128-
shell: bash
129-
# yamllint disable-line rule:indentation
130-
run: |
131-
if echo "$TEMPLATE_VERSION" | grep -E '[0-9]+\.[0-9]+\.[0-9]+'; then
132-
export TEMPLATE_NAME
133-
TEMPLATE_NAME="$(echo "${TEMPLATE_DIR}" | cut -d/ -f3)"
134-
export RELEASE_MSG="[Release Notes](https://github.com/${{ github.repository }}/releases/tag/${TEMPLATE_VERSION})"
135-
export TEST_MODE=false
136-
else
137-
export TEMPLATE_NAME
138-
TEMPLATE_NAME="$(echo "${TEMPLATE_DIR}" | cut -d/ -f3)-test"
139-
export RELEASE_MSG="[Changes](https://github.com/${{ github.repository }}/commit/${TEMPLATE_VERSION})"
140-
export TEST_MODE=true
141-
fi
142-
echo "Publishing template ${TEMPLATE_DIR} as ${TEMPLATE_NAME}..."
143-
set -x
144-
coder template push \
145-
--directory "${TEMPLATE_DIR}" \
146-
--var "workspace_image=${WORKSPACE_IMAGE}" \
147-
--var test_mode=${TEST_MODE} \
148-
--name "${TEMPLATE_VERSION}" \
149-
--message "${RELEASE_MSG}" \
150-
--yes \
151-
"${TEMPLATE_NAME}"
152-
set +x
153-
echo
154-
echo "Confirming template has been published..."
155-
coder templates list --output json > /tmp/templates.json
156-
export SELECTED_TEMPLATE
157-
SELECTED_TEMPLATE=$(cat /tmp/templates.json | jq -r '.[] | select(.Template.name == "'"${TEMPLATE_NAME}"'")')
158-
if [[ -z $SELECTED_TEMPLATE ]]; then
159-
echo "Could not find any template published as $TEMPLATE_NAME."
160-
exit 1
161-
fi
162-
echo "Template has been published successfully."
163-
164-
- name: Tailscale Disconnect
165-
if: success() || failure()
166-
run: sudo -E tailscale logout

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "2.27.1"
3+
}

0 commit comments

Comments
 (0)