Skip to content

Commit 2fad078

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

8 files changed

Lines changed: 213 additions & 237 deletions

File tree

.github/workflows/publish.yaml

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

.github/workflows/release.yaml

Lines changed: 10 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -5,162 +5,24 @@ name: release
55
on:
66
pull_request:
77
paths:
8+
- '.release-please-manifest.json'
89
- '.github/workflows/release.yaml'
9-
- '.releaserc.js'
10-
- 'images/homelab-workspace/**'
11-
- 'templates/**'
10+
- 'release-please-config.json'
11+
push:
12+
branches:
13+
- main
1214
workflow_dispatch:
13-
inputs:
14-
test_publish:
15-
description: "Test Publish"
16-
required: true
17-
type: boolean
1815

1916
concurrency:
20-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
21-
cancel-in-progress: true
17+
group: ${{ github.workflow }}-${{ github.ref }}
2218

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
19+
permissions: {}
2920

3021
jobs:
31-
create-release:
32-
uses: ppat/github-workflows/.github/workflows/release-semantic.yaml@5a96ced8ceefd58062f6b91ee9d6f3a31cd06e1c # v6.0.0
22+
release:
23+
uses: ppat/github-workflows/.github/workflows/release-please.yaml@5a96ced8ceefd58062f6b91ee9d6f3a31cd06e1c # v6.0.0
3324
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 }}
25+
dry_run: ${{ github.event_name == 'pull_request' }}
3626
secrets:
3727
app_id: ${{ secrets.HOMELAB_BOT_APP_ID }}
3828
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)