Skip to content

Commit b20441e

Browse files
committed
feat: Add continuous deployment workflow and update Taskfile for CD integration
Signed-off-by: Eden Reich <[email protected]>
1 parent 82d45c4 commit b20441e

File tree

5 files changed

+335
-118
lines changed

5 files changed

+335
-118
lines changed

.flox/env/manifest.lock

Lines changed: 116 additions & 116 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/cd.yml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
name: CD
3+
4+
on:
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: write
9+
issues: write
10+
pull-requests: write
11+
packages: write
12+
13+
jobs:
14+
release:
15+
name: Release
16+
runs-on: ubuntu-24.04
17+
outputs:
18+
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
19+
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
20+
steps:
21+
- name: Checkout code
22+
uses: actions/[email protected]
23+
with:
24+
ref: ${{ github.ref }}
25+
fetch-depth: 0
26+
persist-credentials: false
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Set up Go
29+
uses: actions/[email protected]
30+
with:
31+
go-version: 1.24
32+
cache: true
33+
34+
- name: Install Task
35+
uses: arduino/setup-task@v2
36+
with:
37+
version: 3.x
38+
39+
- name: Download dependencies
40+
run: go mod download
41+
42+
- name: Run tests
43+
run: task test
44+
45+
- name: Build
46+
run: task build
47+
48+
- name: Set up Node.js for semantic-release
49+
uses: actions/[email protected]
50+
with:
51+
node-version: 22
52+
53+
- name: Install semantic-release and plugins
54+
run: |
55+
npm install -g [email protected] \
56+
conventional-changelog-cli \
57+
conventional-changelog-conventionalcommits \
58+
@semantic-release/changelog \
59+
@semantic-release/git \
60+
@semantic-release/github
61+
62+
- name: Create a release if needed
63+
id: semantic
64+
env:
65+
CI: true
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
run: |
68+
# Create first release if not exists - Initial Release Version 0.1.0
69+
if ! gh release view v0.1.0 >/dev/null 2>&1; then
70+
gh release create v0.1.0 --title "Initial Release" --notes "Initial Release" --target main
71+
fi
72+
73+
# Run semantic-release in dry-run first to capture version
74+
DRY_OUTPUT=$(semantic-release --dry-run 2>&1 || true)
75+
76+
# Check if there are no changes
77+
if $(echo "$DRY_OUTPUT" | grep -q "no new version is released"); then
78+
echo "No new release needed"
79+
echo "new_release_published=false" >> $$GITHUB_OUTPUT
80+
exit 0
81+
fi
82+
83+
# Extract version from dry run output
84+
VERSION=$(echo "$DRY_OUTPUT" | grep -o "The next release version is [0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?" | cut -d ' ' -f6)
85+
if [ -z "$VERSION" ]; then
86+
echo "Error: Could not determine version"
87+
echo "Output: $DRY_OUTPUT"
88+
exit 1
89+
fi
90+
91+
echo "new_release_version=$VERSION" >> $$GITHUB_OUTPUT
92+
93+
# Run actual release
94+
if semantic-release; then
95+
echo "Successfully released version $VERSION"
96+
echo "new_release_published=true" >> $$GITHUB_OUTPUT
97+
else
98+
echo "Release failed"
99+
exit 1
100+
fi
101+
102+
build_and_push_image:
103+
name: Build and Push Container Image
104+
runs-on: ubuntu-24.04
105+
needs: release
106+
if: needs.release.outputs.new_release_published == 'true'
107+
steps:
108+
- name: Checkout code
109+
uses: actions/[email protected]
110+
with:
111+
ref: ${{ github.ref }}
112+
fetch-depth: 0
113+
114+
- name: Set up QEMU
115+
uses: docker/setup-qemu-action@v3
116+
with:
117+
platforms: all
118+
119+
- name: Set up Docker Buildx
120+
uses: docker/setup-buildx-action@v3
121+
with:
122+
version: latest
123+
124+
- name: Log in to GitHub Container Registry
125+
uses: docker/login-action@v3
126+
with:
127+
registry: ghcr.io
128+
username: ${{ github.actor }}
129+
password: ${{ secrets.GITHUB_TOKEN }}
130+
131+
- name: Extract metadata
132+
id: meta
133+
uses: docker/metadata-action@v5
134+
with:
135+
images: ghcr.io/${{ github.repository_owner }}/documentation-agent
136+
tags: |
137+
type=ref,event=branch
138+
type=ref,event=pr
139+
type=semver,pattern={{version}},value=${{ needs.release.outputs.new_release_version }}
140+
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release.outputs.new_release_version }}
141+
type=raw,value=latest
142+
143+
- name: Build and push Docker image
144+
uses: docker/build-push-action@v6
145+
with:
146+
context: .
147+
platforms: linux/amd64,linux/arm64
148+
push: true
149+
tags: ${{ steps.meta.outputs.tags }}
150+
labels: ${{ steps.meta.outputs.labels }}
151+
cache-from: type=gha
152+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)