Skip to content

Commit 66a0cc7

Browse files
CD pipeline - phase 1 (#12)
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
1 parent 54baf19 commit 66a0cc7

7 files changed

Lines changed: 367 additions & 18 deletions

File tree

.github/json_matrices/os-matrix.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,56 @@
55
"RUNNER": "ubuntu-24.04",
66
"ARCH": "x64",
77
"TARGET": "x86_64-unknown-linux-gnu",
8+
"tags": ["ci", "cd"],
89
"run": "always"
910
},
1011
{
1112
"OS": "ubuntu",
1213
"NAMED_OS": "linux",
1314
"RUNNER": "ubuntu-24.04-arm",
1415
"ARCH": "arm64",
15-
"TARGET": "aarch64-unknown-linux-gnu"
16+
"TARGET": "aarch64-unknown-linux-gnu",
17+
"tags": ["ci", "cd"]
1618
},
1719
{
1820
"OS": "macos",
1921
"NAMED_OS": "darwin",
2022
"RUNNER": "macos-15",
2123
"ARCH": "arm64",
22-
"TARGET": "aarch64-apple-darwin"
24+
"TARGET": "aarch64-apple-darwin",
25+
"tags": ["ci", "cd"]
2326
},
2427
{
2528
"OS": "macos",
2629
"NAMED_OS": "darwin",
2730
"RUNNER": "macos-13",
2831
"ARCH": "x64",
29-
"TARGET": "x86_64-apple-darwin"
32+
"TARGET": "x86_64-apple-darwin",
33+
"tags": ["ci", "cd"]
3034
},
3135
{
3236
"OS": "amazon-linux",
3337
"NAMED_OS": "linux",
3438
"RUNNER": "ubuntu-latest",
3539
"ARCH": "x64",
3640
"TARGET": "x86_64-unknown-linux-gnu",
41+
"tags": ["container"],
3742
"IMAGE": "amazonlinux:latest"
43+
},
44+
{
45+
"OS": "windows",
46+
"NAMED_OS": "windows",
47+
"RUNNER": "windows-2025",
48+
"ARCH": "x64",
49+
"TARGET": "x86_64-pc-windows-msvc",
50+
"tags": ["cd"]
51+
},
52+
{
53+
"OS": "windows",
54+
"NAMED_OS": "windows",
55+
"RUNNER": "windows-11-arm",
56+
"ARCH": "arm64",
57+
"TARGET": "aarch64-pc-windows-msvc",
58+
"tags": ["cd"]
3859
}
3960
]

.github/workflows/cd.yml

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
name: C# CD
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*.*"
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: "The release version of GLIDE, formatted as *.*.* or *.*.*-rc*"
11+
required: true
12+
nuget_publish:
13+
description: "Publish to NuGet"
14+
required: true
15+
type: boolean
16+
17+
permissions:
18+
contents: read
19+
id-token: write
20+
21+
concurrency:
22+
group: C#-CD-${{ github.head_ref || github.ref }}-${{ toJson(inputs) }}
23+
cancel-in-progress: true
24+
25+
run-name:
26+
# Set custom name if job is started manually and name is given
27+
${{ github.event_name == 'workflow_dispatch' && (inputs.name == '' && format('{0} @ {1} {2}', github.ref_name, github.sha, toJson(inputs)) || inputs.name) || '' }}
28+
29+
env:
30+
CARGO_TERM_COLOR: always
31+
32+
jobs:
33+
load-platform-matrix:
34+
runs-on: ubuntu-latest
35+
outputs:
36+
PLATFORM_MATRIX: ${{ steps.load-platform-matrix.outputs.PLATFORM_MATRIX }}
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
- name: load-platform-matrix
42+
id: load-platform-matrix
43+
working-directory: .github/json_matrices
44+
run: |
45+
jq -c "[.[] | select(any(.tags[] == \"cd\"; .))]" < os-matrix.json | awk '{ printf "PLATFORM_MATRIX=%s\n", $0 }' | tee -a $GITHUB_OUTPUT
46+
47+
set-release-version:
48+
runs-on: ubuntu-latest
49+
outputs:
50+
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
51+
steps:
52+
- name: Set the release version
53+
id: release-version
54+
shell: bash
55+
run: |
56+
if ${{ github.event_name == 'workflow_dispatch' }}; then
57+
R_VERSION="${{ env.INPUT_VERSION }}"
58+
else
59+
R_VERSION=${{ github.ref_name }}
60+
fi
61+
echo "RELEASE_VERSION=${R_VERSION}" >> $GITHUB_ENV
62+
echo "Release version detected: $R_VERSION"
63+
echo "RELEASE_VERSION=$R_VERSION" >> $GITHUB_OUTPUT
64+
env:
65+
INPUT_VERSION: ${{ github.event.inputs.version }}
66+
67+
create-binaries:
68+
needs: [load-platform-matrix]
69+
timeout-minutes: 35
70+
strategy:
71+
# Run all jobs
72+
fail-fast: false
73+
matrix:
74+
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
75+
runs-on: ${{ matrix.host.RUNNER }}
76+
77+
steps:
78+
- uses: actions/checkout@v4
79+
with:
80+
submodules: true
81+
82+
- name: Output Matrix Parameters for this job
83+
shell: bash
84+
run: |
85+
echo "Job running with the following matrix configuration:"
86+
echo "${{ toJson(matrix) }}"
87+
88+
- name: Install shared software dependencies
89+
uses: ./.github/workflows/install-shared-dependencies
90+
with:
91+
os: ${{ matrix.host.OS }}
92+
target: ${{ matrix.host.TARGET }}
93+
github-token: ${{ secrets.GITHUB_TOKEN }}
94+
engine-version: ${{ matrix.engine.version }}
95+
96+
- uses: actions/cache@v4
97+
with:
98+
path: rust/target
99+
key: rust-${{ matrix.host.TARGET }}
100+
101+
- name: Build native libs (linux gnu)
102+
if: ${{ contains(matrix.host.TARGET, 'linux-gnu') }}
103+
working-directory: rust
104+
run: |
105+
cargo zigbuild -r --target ${{ matrix.host.TARGET }}.2.17
106+
mkdir -p target/release
107+
cp target/*/release/libglide_rs.so target/release/
108+
109+
- name: Build native libs
110+
if: ${{ !contains(matrix.host.TARGET, 'linux-gnu') }}
111+
working-directory: rust
112+
run: cargo build --release --target ${{ matrix.host.TARGET }}
113+
114+
- name: Upload artifacts to publish
115+
continue-on-error: true
116+
uses: actions/upload-artifact@v4
117+
with:
118+
name: ${{ matrix.host.TARGET }}
119+
path: |
120+
rust/target/release/*.so
121+
rust/target/release/*.dylib
122+
rust/target/release/*.dll
123+
124+
build-package-to-publish:
125+
needs: [set-release-version, create-binaries]
126+
runs-on: ubuntu-latest
127+
env:
128+
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
129+
steps:
130+
- uses: actions/checkout@v4
131+
132+
- name: Download published artifacts
133+
uses: actions/download-artifact@v4
134+
with:
135+
path: bin
136+
137+
- name: Rename lib for windows
138+
working-directory: bin
139+
run: |
140+
find . -name glide_rs.dll -execdir mv {} libglide_rs.dll \;
141+
tree -h
142+
143+
- name: Set up dotnet
144+
uses: actions/setup-dotnet@v4
145+
with:
146+
# install all supported versions + latest dotnet too to use language features
147+
dotnet-version: |
148+
6
149+
8
150+
9
151+
env:
152+
DOTNET_INSTALL_DIR: ~/.dotnet
153+
154+
- name: Pack the client
155+
working-directory: sources/Valkey.Glide
156+
run: |
157+
dotnet build Valkey.Glide.csproj --configuration Release /property:Version=${{ env.RELEASE_VERSION }}
158+
dotnet pack Valkey.Glide.csproj --configuration Release -p:NuspecProperties=version=${{ env.RELEASE_VERSION }}
159+
tree -h bin/Release
160+
unzip -l bin/Release/Valkey.Glide.${{ env.RELEASE_VERSION }}.nupkg
161+
unzip -l bin/Release/Valkey.Glide.${{ env.RELEASE_VERSION }}.symbols.nupkg
162+
env:
163+
SkipCargo: true
164+
165+
- name: Upload artifacts to publish
166+
uses: actions/upload-artifact@v4
167+
with:
168+
name: package
169+
path: sources/Valkey.Glide/bin/Release/Valkey.Glide.*.nupkg
170+
171+
publish:
172+
environment: Release
173+
if: ${{ (inputs.nuget_publish == true || github.event_name == 'push') && github.repository_owner == 'valkey-io' }}
174+
needs: [build-package-to-publish]
175+
runs-on: ubuntu-latest
176+
steps:
177+
- name: Download package
178+
uses: actions/download-artifact@v4
179+
with:
180+
name: package
181+
182+
- name: Publish
183+
run: |
184+
ls -lh
185+
dotnet nuget push Valkey.Glide.*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
186+
187+
test:
188+
needs: [publish, set-release-version, load-platform-matrix]
189+
if: ${{ !cancelled() }}
190+
timeout-minutes: 35
191+
strategy:
192+
# Run all jobs
193+
fail-fast: false
194+
matrix:
195+
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
196+
runs-on: ${{ matrix.host.RUNNER }}
197+
env:
198+
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
199+
steps:
200+
- uses: actions/checkout@v4
201+
202+
- name: Download package
203+
if: ${{ needs.publish.result == 'skipped' }}
204+
uses: actions/download-artifact@v4
205+
with:
206+
name: package
207+
path: nuget.local
208+
209+
- name: Set up dotnet
210+
uses: actions/setup-dotnet@v4
211+
with:
212+
# install latest dotnet too to use language features
213+
dotnet-version: |
214+
8
215+
9
216+
217+
- name: Set up a local nuget
218+
if: ${{ needs.publish.result == 'skipped' }}
219+
shell: bash
220+
run: |
221+
ls -l $GITHUB_WORKSPACE/nuget.local
222+
dotnet nuget add source $GITHUB_WORKSPACE/nuget.local
223+
dotnet nuget config paths
224+
if [[ "$OS" != "Windows_NT" ]]; then
225+
dotnet nuget config paths | xargs cat
226+
else
227+
cat "C:\\Users\\runneradmin\\AppData\\Roaming\\NuGet\\NuGet.Config"
228+
fi
229+
230+
- name: Patch IT suite to run tests using freshly published version
231+
working-directory: tests/Valkey.Glide.IntegrationTests
232+
shell: bash
233+
run: |
234+
dotnet remove reference $(dotnet list reference | tail -n +3)
235+
dotnet add package Valkey.Glide --version ${{ env.RELEASE_VERSION }}
236+
git diff
237+
238+
- name: Install engine
239+
# TODO activate this on windows once fixed, see https://github.com/valkey-io/valkey-glide-csharp/issues/6
240+
if: ${{ matrix.host.OS != 'windows' }}
241+
uses: ./.github/workflows/install-engine
242+
with:
243+
engine-version: 8.1
244+
target: ${{ matrix.host.TARGET }}
245+
246+
- name: Run tests
247+
# TODO activate this on windows once fixed, see https://github.com/valkey-io/valkey-glide-csharp/issues/6
248+
if: ${{ matrix.host.OS != 'windows' }}
249+
working-directory: tests/Valkey.Glide.IntegrationTests
250+
run: |
251+
dotnet test --framework net8.0 --logger "console;verbosity=detailed" --logger "html;LogFileName=TestReport.html" --results-directory . --filter "FullyQualifiedName~CommandTests"
252+
253+
- name: Upload test reports
254+
if: always()
255+
continue-on-error: true
256+
uses: actions/upload-artifact@v4
257+
with:
258+
name: test-reports-${{ matrix.host.TARGET }}
259+
path: |
260+
TestReport.html
261+
valkey-glide/utils/clusters/**
262+
263+
remove-package-if-validation-fails:
264+
needs: [publish, test, set-release-version]
265+
if: ${{ !cancelled() }}
266+
runs-on: ubuntu-latest
267+
env:
268+
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
269+
steps:
270+
- name: Remove package from NuGet due to test failures
271+
if: ${{ needs.test.result == 'failure' && needs.publish.result == 'success' }}
272+
run: dotnet nuget delete Valkey.Glide ${{ env.RELEASE_VERSION }} --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --non-interactive

.github/workflows/create-test-matrices/action.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ inputs:
33
description: "Run the full matrix"
44
required: true
55
type: boolean
6-
containers:
7-
description: "Run in containers"
6+
tag:
7+
description: "Tag to filter hosts"
88
required: true
9-
default: false
10-
type: boolean
9+
type: string
10+
default: ci
1111

1212
outputs:
1313
server-matrix-output:
@@ -27,10 +27,10 @@ runs:
2727
shell: bash
2828
env:
2929
RUN_FULL_MATRIX: ${{ inputs.run-full-matrix }}
30-
CONTAINERS: ${{ inputs.containers }}
30+
TAG: ${{ inputs.tag }}
3131
run: |
3232
echo "RUN_FULL_MATRIX=$RUN_FULL_MATRIX" >> $GITHUB_ENV
33-
echo "CONTAINERS=$CONTAINERS" >> $GITHUB_ENV
33+
echo "TAG=$TAG" >> $GITHUB_ENV
3434
3535
- name: Load server matrix
3636
id: load-server-matrix
@@ -53,11 +53,10 @@ runs:
5353
working-directory: .github/json_matrices
5454
run: |
5555
set -o pipefail
56-
[[ "$CONTAINERS" == "true" ]] && CONDITION=".IMAGE?" || CONDITION=".IMAGE == null"
5756
echo 'Select runners (VMs) to run tests on'
5857
if [[ "$RUN_FULL_MATRIX" == "true" ]]; then
5958
echo 'Pick all runners - on cron (schedule) or if manually triggered job requires a full matrix'
60-
jq -c "[.[] | select($CONDITION)]" < os-matrix.json | awk '{ printf "os-matrix=%s\n", $0 }' | tee -a $GITHUB_OUTPUT
59+
jq -c "[.[] | select(any(.tags[] == \"$TAG\"; .))]" < os-matrix.json | awk '{ printf "os-matrix=%s\n", $0 }' | tee -a $GITHUB_OUTPUT
6160
else
6261
echo 'Pick runners marked as '"run": "always"' only - on PR, push or manually triggered job which does not require full matrix'
6362
jq -c '[.[] | select(.run == "always")]' < os-matrix.json | awk '{ printf "os-matrix=%s\n", $0 }' | tee -a $GITHUB_OUTPUT

0 commit comments

Comments
 (0)