Skip to content

Commit c57d300

Browse files
committed
Adds release publishing
1 parent a609835 commit c57d300

File tree

1 file changed

+148
-1
lines changed

1 file changed

+148
-1
lines changed

.github/workflows/docker-publish.yml

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,71 @@ jobs:
3838
- name: Build application
3939
run: go build -o bin/ctrl-hub-mcp-server cmd/server/main.go
4040

41-
build-and-push:
41+
create-release:
42+
name: Create Release
43+
needs: test
44+
runs-on: ubuntu-latest
45+
permissions:
46+
contents: write
47+
outputs:
48+
upload_url: ${{ steps.create_release.outputs.upload_url }}
49+
release_id: ${{ steps.create_release.outputs.id }}
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
56+
- name: Generate changelog
57+
id: changelog
58+
run: |
59+
# Get the previous tag
60+
PREVIOUS_TAG=$(git tag --sort=-version:refname | sed -n '2p')
61+
if [ -z "$PREVIOUS_TAG" ]; then
62+
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
63+
fi
64+
65+
# Generate changelog
66+
CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${PREVIOUS_TAG}..HEAD)
67+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
68+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
69+
echo "EOF" >> $GITHUB_OUTPUT
70+
71+
- name: Create Release
72+
id: create_release
73+
uses: actions/create-release@v1
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
with:
77+
tag_name: ${{ github.ref_name }}
78+
release_name: Release ${{ github.ref_name }}
79+
body: |
80+
## Changes in ${{ github.ref_name }}
81+
82+
${{ steps.changelog.outputs.changelog }}
83+
84+
## Docker Images
85+
86+
```bash
87+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
88+
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
89+
```
90+
91+
## Installation
92+
93+
### From Source
94+
```bash
95+
go install github.com/ctrl-hub/mcp/cmd/server@${{ github.ref_name }}
96+
```
97+
98+
### Docker
99+
```bash
100+
docker run -p 8080:8080 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
101+
```
102+
draft: false
103+
prerelease: ${{ contains(github.ref_name, '-') }}
104+
105+
build-docker-images:
42106
needs: test
43107
runs-on: ubuntu-latest
44108
permissions:
@@ -64,6 +128,7 @@ jobs:
64128
run: |
65129
# Extract version from tag (remove refs/tags/)
66130
VERSION=${GITHUB_REF#refs/tags/}
131+
VERSION=${VERSION#v}
67132
echo "version=$VERSION" >> $GITHUB_OUTPUT
68133
69134
# Create tags array based on semantic version
@@ -98,3 +163,85 @@ jobs:
98163
cache-to: type=gha,mode=max
99164
build-args: |
100165
VERSION=${{ steps.version.outputs.version }}
166+
167+
build-binaries:
168+
name: Build Release Binaries
169+
runs-on: ubuntu-latest
170+
needs: create-release
171+
permissions:
172+
contents: write
173+
strategy:
174+
matrix:
175+
include:
176+
- goos: linux
177+
goarch: amd64
178+
name: linux-amd64
179+
- goos: linux
180+
goarch: arm64
181+
name: linux-arm64
182+
- goos: darwin
183+
goarch: amd64
184+
name: darwin-amd64
185+
- goos: darwin
186+
goarch: arm64
187+
name: darwin-arm64
188+
- goos: windows
189+
goarch: amd64
190+
name: windows-amd64
191+
192+
steps:
193+
- name: Checkout code
194+
uses: actions/checkout@v4
195+
196+
- name: Set up Go
197+
uses: actions/setup-go@v5
198+
with:
199+
go-version: "1.24"
200+
201+
- name: Cache Go modules
202+
uses: actions/cache@v4
203+
with:
204+
path: ~/go/pkg/mod
205+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
206+
restore-keys: |
207+
${{ runner.os }}-go-
208+
209+
- name: Download dependencies
210+
run: go mod download
211+
212+
- name: Build binary
213+
env:
214+
GOOS: ${{ matrix.goos }}
215+
GOARCH: ${{ matrix.goarch }}
216+
CGO_ENABLED: 0
217+
run: |
218+
BINARY_NAME=ctrl-hub-mcp-server
219+
if [ "$GOOS" = "windows" ]; then
220+
BINARY_NAME="${BINARY_NAME}.exe"
221+
fi
222+
223+
go build \
224+
-ldflags="-w -s -X main.version=${{ github.ref_name }}" \
225+
-o ${BINARY_NAME} \
226+
cmd/server/main.go
227+
228+
# Create archive
229+
if [ "$GOOS" = "windows" ]; then
230+
zip ctrl-hub-mcp-server-${{ matrix.name }}.zip ${BINARY_NAME} README.md
231+
echo "ASSET_PATH=ctrl-hub-mcp-server-${{ matrix.name }}.zip" >> $GITHUB_ENV
232+
echo "ASSET_CONTENT_TYPE=application/zip" >> $GITHUB_ENV
233+
else
234+
tar -czf ctrl-hub-mcp-server-${{ matrix.name }}.tar.gz ${BINARY_NAME} README.md
235+
echo "ASSET_PATH=ctrl-hub-mcp-server-${{ matrix.name }}.tar.gz" >> $GITHUB_ENV
236+
echo "ASSET_CONTENT_TYPE=application/gzip" >> $GITHUB_ENV
237+
fi
238+
239+
- name: Upload Release Asset
240+
uses: actions/upload-release-asset@v1
241+
env:
242+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
243+
with:
244+
upload_url: ${{ needs.create-release.outputs.upload_url }}
245+
asset_path: ${{ env.ASSET_PATH }}
246+
asset_name: ${{ env.ASSET_PATH }}
247+
asset_content_type: ${{ env.ASSET_CONTENT_TYPE }}

0 commit comments

Comments
 (0)