Skip to content

Commit cc2f2ed

Browse files
author
Test User
committed
🚀 Add publish workflow to CI/CD pipeline
Add automated publishing to Docker Hub and crates.io Enhance the CI/CD workflow to automatically publish releases: - Configure Docker image publishing to Docker Hub on release - Set up crates.io publishing for Rust package releases - Connect workflow to existing Docker build configuration - Ensure proper versioning and tagging for published artifacts This complements the recently added Docker support by providing automated distribution channels for both container and package users.
1 parent 11348c9 commit cc2f2ed

File tree

1 file changed

+193
-34
lines changed

1 file changed

+193
-34
lines changed

.github/workflows/cicd.yml

Lines changed: 193 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ on:
1616
jobs:
1717
# This job runs for all pushes and pull requests
1818
build-and-test:
19+
name: 🧪 Build & Test (${{ matrix.build }})
1920
runs-on: ${{ matrix.os }}
2021
strategy:
2122
matrix:
@@ -26,31 +27,68 @@ jobs:
2627
cmd: cargo
2728

2829
steps:
29-
- name: Checkout repository
30+
- name: 📥 Checkout repository
3031
uses: actions/checkout@v4
3132
with:
3233
fetch-depth: 0
3334

34-
- name: Install Rust
35+
- name: 🦀 Install Rust
3536
uses: dtolnay/rust-toolchain@stable
3637
with:
3738
targets: ${{ matrix.target }}
3839

39-
- name: Rust cache
40+
- name: 📦 Rust cache
4041
uses: Swatinem/rust-cache@v2
4142
with:
4243
# Let action generate cache keys automatically
4344
workspaces: ". -> target"
44-
# The action will automatically include the OS and job name in the key
4545

46-
- name: Build
47-
run: ${{ matrix.cmd }} build --verbose --locked --target ${{ matrix.target }}
46+
- name: 🔨 Build
47+
run: |
48+
echo "::group::Building Git-Iris (${{ matrix.build }})"
49+
${{ matrix.cmd }} build --verbose --locked --target ${{ matrix.target }}
50+
echo "::endgroup::"
51+
52+
- name: 🧪 Run tests
53+
run: |
54+
echo "::group::Running tests (${{ matrix.build }})"
55+
${{ matrix.cmd }} test --verbose --locked --target ${{ matrix.target }}
56+
echo "::endgroup::"
57+
58+
# Test Docker image building and functionality
59+
docker-build-and-test:
60+
name: 🐳 Docker Build & Test
61+
runs-on: ubuntu-latest
62+
needs: build-and-test
63+
env:
64+
IMAGE_NAME: git-iris-test
65+
steps:
66+
- name: 📥 Checkout repository
67+
uses: actions/checkout@v4
68+
with:
69+
fetch-depth: 0
70+
71+
- name: 🔍 Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v3
73+
74+
- name: 🔨 Build Docker image
75+
working-directory: ./docker
76+
run: |
77+
echo "::group::Building Docker image"
78+
./build.sh $IMAGE_NAME
79+
echo "::endgroup::"
4880
49-
- name: Run tests
50-
run: ${{ matrix.cmd }} test --verbose --locked --target ${{ matrix.target }}
81+
- name: 🧪 Test Docker image
82+
working-directory: ./docker
83+
run: |
84+
echo "::group::Testing Docker image"
85+
# Run tests without auto-commit to avoid permission issues in CI
86+
CI=true ./test-image.sh $IMAGE_NAME
87+
echo "::endgroup::"
5188
5289
# The following jobs only run on tag pushes (i.e., releases)
5390
build-artifacts:
91+
name: 📦 Build Artifacts (${{ matrix.build }})
5492
if: startsWith(github.ref, 'refs/tags/')
5593
needs: build-and-test
5694
runs-on: ${{ matrix.os }}
@@ -73,28 +111,31 @@ jobs:
73111
binary_name: git-iris
74112

75113
steps:
76-
- name: Checkout code
114+
- name: 📥 Checkout code
77115
uses: actions/checkout@v4
78116
with:
79117
fetch-depth: 0
80118

81-
- name: Install Rust
119+
- name: 🦀 Install Rust
82120
uses: dtolnay/rust-toolchain@stable
83121
with:
84122
targets: ${{ matrix.target }}
85123

86-
- name: Rust cache
124+
- name: 📦 Rust cache
87125
uses: Swatinem/rust-cache@v2
88126
with:
89127
# Let action generate cache keys automatically
90128
workspaces: ". -> target/${{ matrix.target }}/release"
91129
# Additional cache suffix for release builds
92130
cache-on-failure: true
93131

94-
- name: Build release binary
95-
run: cargo build --verbose --locked --release --target ${{ matrix.target }}
132+
- name: 🔨 Build release binary
133+
run: |
134+
echo "::group::Building release binary (${{ matrix.build }})"
135+
cargo build --verbose --locked --release --target ${{ matrix.target }}
136+
echo "::endgroup::"
96137
97-
- name: Upload artifact
138+
- name: 📤 Upload artifact
98139
uses: actions/upload-artifact@v4
99140
with:
100141
name: git-iris-${{ matrix.build }}
@@ -103,41 +144,45 @@ jobs:
103144
retention-days: 1
104145

105146
build-packages:
147+
name: 📦 Build Packages
106148
if: startsWith(github.ref, 'refs/tags/')
107149
needs: build-and-test
108150
runs-on: ubuntu-latest
109151
outputs:
110152
version: ${{ steps.get_version.outputs.VERSION }}
111153
steps:
112-
- name: Checkout code
154+
- name: 📥 Checkout code
113155
uses: actions/checkout@v4
114156
with:
115157
fetch-depth: 0
116158

117-
- name: Get version
159+
- name: 🏷️ Get version
118160
id: get_version
119161
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
120162

121-
- name: Install Rust
163+
- name: 🦀 Install Rust
122164
uses: dtolnay/rust-toolchain@stable
123165
with:
124166
targets: x86_64-unknown-linux-gnu
125167

126-
- name: Rust cache
168+
- name: 📦 Rust cache
127169
uses: Swatinem/rust-cache@v2
128170
with:
129171
# Let action generate cache keys automatically
130172
workspaces: "."
131173
cache-on-failure: true
132174

133175
# Build DEB package
134-
- name: Install cargo-deb
176+
- name: 📦 Install cargo-deb
135177
run: cargo install cargo-deb
136178

137-
- name: Build .deb package
138-
run: cargo deb
179+
- name: 🔨 Build .deb package
180+
run: |
181+
echo "::group::Building .deb package"
182+
cargo deb
183+
echo "::endgroup::"
139184
140-
- name: Upload DEB artifact
185+
- name: 📤 Upload DEB artifact
141186
uses: actions/upload-artifact@v4
142187
with:
143188
name: git-iris-deb
@@ -146,16 +191,19 @@ jobs:
146191
retention-days: 1
147192

148193
# Build RPM package
149-
- name: Install cargo-generate-rpm
194+
- name: 📦 Install cargo-generate-rpm
150195
run: cargo install cargo-generate-rpm
151196

152-
- name: Build Release Binary for RPM
197+
- name: 🔨 Build Release Binary for RPM
153198
run: cargo build --release
154199

155-
- name: Build .rpm package
156-
run: cargo generate-rpm
200+
- name: 🔨 Build .rpm package
201+
run: |
202+
echo "::group::Building .rpm package"
203+
cargo generate-rpm
204+
echo "::endgroup::"
157205
158-
- name: Upload RPM artifact
206+
- name: 📤 Upload RPM artifact
159207
uses: actions/upload-artifact@v4
160208
with:
161209
name: git-iris-rpm
@@ -164,43 +212,154 @@ jobs:
164212
retention-days: 1
165213

166214
# Upload man page as artifact
167-
- name: Upload man page artifact
215+
- name: 📤 Upload man page artifact
168216
uses: actions/upload-artifact@v4
169217
with:
170218
name: git-iris-man
171219
path: ./git-iris.1
172220
if-no-files-found: error
173221
retention-days: 1
174222

175-
create-release:
223+
# Publish Docker image for releases
224+
docker-publish:
225+
name: 🐳 Publish Docker Image
226+
if: startsWith(github.ref, 'refs/tags/')
227+
needs: [build-and-test, docker-build-and-test, build-packages]
228+
runs-on: ubuntu-latest
229+
env:
230+
REGISTRY: docker.io
231+
IMAGE_NAME: hyperb1iss/git-iris
232+
steps:
233+
- name: 📥 Checkout code
234+
uses: actions/checkout@v4
235+
with:
236+
fetch-depth: 0
237+
238+
- name: 🏷️ Get version
239+
id: get_version
240+
run: |
241+
VERSION=${GITHUB_REF_NAME#v}
242+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
243+
echo "Building Docker image for version $VERSION"
244+
245+
- name: 🔑 Login to DockerHub
246+
uses: docker/login-action@v3
247+
with:
248+
username: ${{ secrets.DOCKER_USERNAME }}
249+
password: ${{ secrets.DOCKER_TOKEN }}
250+
251+
- name: 🔍 Set up Docker Buildx
252+
uses: docker/setup-buildx-action@v3
253+
254+
- name: 🔨 Build and push Docker image
255+
uses: docker/build-push-action@v5
256+
with:
257+
context: .
258+
file: ./docker/Dockerfile
259+
push: true
260+
tags: |
261+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
262+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}
263+
cache-from: type=gha
264+
cache-to: type=gha,mode=max
265+
266+
- name: 🎉 Docker image published
267+
run: |
268+
echo "✨ Successfully published Docker images:"
269+
echo " • ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest"
270+
echo " • ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_version.outputs.VERSION }}"
271+
272+
# Add crates.io publishing
273+
cargo-publish:
274+
name: 📦 Publish to crates.io
176275
if: startsWith(github.ref, 'refs/tags/')
177276
needs: [build-artifacts, build-packages]
178277
runs-on: ubuntu-latest
278+
steps:
279+
- name: 📥 Checkout code
280+
uses: actions/checkout@v4
281+
with:
282+
fetch-depth: 0
283+
284+
- name: 🦀 Install Rust
285+
uses: dtolnay/rust-toolchain@stable
286+
287+
- name: 📦 Rust cache
288+
uses: Swatinem/rust-cache@v2
289+
290+
- name: 🔑 Setup crates.io token
291+
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}
292+
293+
- name: 📤 Publish to crates.io
294+
run: |
295+
echo "::group::Publishing to crates.io"
296+
cargo publish
297+
echo "::endgroup::"
298+
299+
- name: 🎉 crates.io publish successful
300+
run: echo "✨ Successfully published to crates.io"
301+
302+
create-release:
303+
name: 🚀 Create GitHub Release
304+
if: startsWith(github.ref, 'refs/tags/')
305+
needs: [build-artifacts, build-packages, docker-publish, cargo-publish]
306+
runs-on: ubuntu-latest
179307
permissions:
180308
contents: write
181309
steps:
182-
- name: Checkout code
310+
- name: 📥 Checkout code
183311
uses: actions/checkout@v4
184312
with:
185313
fetch-depth: 0
186314

187-
- name: Download all artifacts
315+
- name: 📥 Download all artifacts
188316
uses: actions/download-artifact@v4
189317
with:
190318
path: ./artifacts
191319

192-
- name: Prepare release assets
320+
- name: 🔨 Prepare release assets
193321
run: |
322+
echo "::group::Preparing release assets"
194323
mkdir -p release-assets
195324
find ./artifacts -type f -exec cp {} ./release-assets/ \;
196325
ls -la ./release-assets
326+
echo "::endgroup::"
197327
198-
- name: Create GitHub Release
328+
- name: 📝 Generate release notes with git-iris
329+
env:
330+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
331+
run: |
332+
echo "::group::Generating release notes"
333+
if [ -n "$OPENAI_API_KEY" ]; then
334+
# Build git-iris locally to generate release notes
335+
cargo build --release
336+
337+
# Get previous tag
338+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
339+
340+
if [ -n "$PREVIOUS_TAG" ]; then
341+
# Generate release notes using git-iris
342+
./target/release/git-iris release-notes --from "$PREVIOUS_TAG" --to "$GITHUB_REF_NAME" --print > RELEASE_NOTES.md
343+
echo "✨ Generated release notes with git-iris"
344+
else
345+
echo "No previous tag found, using default release notes"
346+
echo "# Release $GITHUB_REF_NAME" > RELEASE_NOTES.md
347+
echo "See commit history for changes." >> RELEASE_NOTES.md
348+
fi
349+
else
350+
echo "No OpenAI API key available, using default release notes"
351+
echo "# Release $GITHUB_REF_NAME" > RELEASE_NOTES.md
352+
echo "See commit history for changes." >> RELEASE_NOTES.md
353+
fi
354+
cat RELEASE_NOTES.md
355+
echo "::endgroup::"
356+
357+
- name: 🚀 Create GitHub Release
199358
uses: softprops/action-gh-release@v2
200359
with:
201360
name: Release ${{ github.ref_name }}
202361
draft: false
203362
prerelease: false
204363
files: |
205364
./release-assets/*
206-
generate_release_notes: true
365+
body_path: RELEASE_NOTES.md

0 commit comments

Comments
 (0)