Skip to content

Commit 20c461a

Browse files
workflows: windows: Add chain workflow for windows unit testing (#8582)
* workflows: windows: Translate AppVeyor's unit testing flow to GHA Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> * internal: test: file: Handle newline character difference In Windows, the newline(\n) characters in internal test data are replaced with \r\n by git settings: core.autocrlf true. This settings accicdentally converting the newlines. This commit handles the converted characters. Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> * workflows: update to split tests Signed-off-by: Patrick Stephens <pat@chronosphere.io> * workflows: windows: Add quotes for $PWD Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> * test: internal: file: Remove needless lines Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> * workflows: windows: Display dependent DLLs by dumpbin Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> * Update .github/workflows/call-windows-unit-tests.yaml Signed-off-by: Pat <patrick.j.k.stephens@gmail.com> Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> * workflows: windows: Specify working directory for dumpbin step Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> --------- Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io> Signed-off-by: Patrick Stephens <pat@chronosphere.io> Signed-off-by: Pat <patrick.j.k.stephens@gmail.com> Co-authored-by: Patrick Stephens <pat@chronosphere.io> Co-authored-by: Pat <pat@calyptia.com>
1 parent ce7b583 commit 20c461a

File tree

3 files changed

+181
-1
lines changed

3 files changed

+181
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
name: Reusable workflow to run unit tests on Windows packages (only for x86 and x64)
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
version:
8+
description: The version of Fluent Bit to create.
9+
type: string
10+
required: true
11+
ref:
12+
description: The commit, tag or branch of Fluent Bit to checkout for building that creates the version above.
13+
type: string
14+
required: true
15+
environment:
16+
description: The Github environment to run this workflow on.
17+
type: string
18+
required: false
19+
unstable:
20+
description: Optionally add metadata to build to indicate an unstable build, set to the contents you want to add.
21+
type: string
22+
required: false
23+
default: ''
24+
secrets:
25+
token:
26+
description: The Github token or similar to authenticate with.
27+
required: true
28+
29+
jobs:
30+
call-build-windows-unit-test:
31+
runs-on: windows-latest
32+
environment: ${{ inputs.environment }}
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
config:
37+
- name: "Windows 32bit"
38+
arch: x86
39+
openssl_dir: C:\vcpkg\packages\openssl_x86-windows-static
40+
cmake_additional_opt: ""
41+
vcpkg_triplet: x86-windows-static
42+
- name: "Windows 64bit"
43+
arch: x64
44+
openssl_dir: C:\vcpkg\packages\openssl_x64-windows-static
45+
cmake_additional_opt: ""
46+
vcpkg_triplet: x64-windows-static
47+
permissions:
48+
contents: read
49+
# Default environment variables can be overridden below. To prevent library pollution - without this other random libraries may be found on the path leading to failures.
50+
env:
51+
PATH: C:\ProgramData\Chocolatey\bin;c:/Program Files/Git/cmd;c:/Windows/system32;C:/Windows/System32/WindowsPowerShell/v1.0;$ENV:WIX/bin;C:/Program Files/CMake/bin;C:\vcpkg;
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v4
55+
with:
56+
ref: ${{ inputs.ref }}
57+
58+
- name: Get dependencies
59+
run: |
60+
Invoke-WebRequest -OutFile winflexbison.zip $env:WINFLEXBISON
61+
Expand-Archive winflexbison.zip -Destination C:\WinFlexBison
62+
Copy-Item -Path C:\WinFlexBison/win_bison.exe C:\WinFlexBison/bison.exe
63+
Copy-Item -Path C:\WinFlexBison/win_flex.exe C:\WinFlexBison/flex.exe
64+
echo "C:\WinFlexBison" | Out-File -FilePath $env:GITHUB_PATH -Append
65+
env:
66+
WINFLEXBISON: https://github.com/lexxmark/winflexbison/releases/download/v2.5.22/win_flex_bison-2.5.22.zip
67+
shell: pwsh
68+
69+
- name: Set up with Developer Command Prompt for Microsoft Visual C++
70+
uses: ilammy/msvc-dev-cmd@v1
71+
with:
72+
arch: ${{ matrix.config.arch }}
73+
74+
- name: Get gzip command w/ chocolatey
75+
uses: crazy-max/ghaction-chocolatey@v3
76+
with:
77+
args: install gzip -y
78+
79+
# http://man7.org/linux/man-pages/man1/date.1.html
80+
- name: Get Date
81+
id: get-date
82+
run: |
83+
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
84+
shell: bash
85+
86+
- name: Restore cached packages of vcpkg
87+
id: cache-unit-test-vcpkg-sources
88+
uses: actions/cache/restore@v4
89+
with:
90+
path: |
91+
C:\vcpkg\packages
92+
key: ${{ runner.os }}-${{ matrix.config.arch }}-wintest-vcpkg-${{ steps.get-date.outputs.date }}
93+
restore-keys: |
94+
${{ runner.os }}-${{ matrix.config.arch }}-wintest-vcpkg-
95+
enableCrossOsArchive: false
96+
97+
- name: Build openssl with vcpkg
98+
run: |
99+
C:\vcpkg\vcpkg install --recurse openssl --triplet ${{ matrix.config.vcpkg_triplet }}
100+
shell: cmd
101+
102+
- name: Build libyaml with vcpkg
103+
run: |
104+
C:\vcpkg\vcpkg install --recurse libyaml --triplet ${{ matrix.config.vcpkg_triplet }}
105+
shell: cmd
106+
107+
- name: Save packages of vcpkg
108+
id: save-vcpkg-sources
109+
uses: actions/cache/save@v4
110+
with:
111+
path: |
112+
C:\vcpkg\packages
113+
key: ${{ steps.cache-unit-test-vcpkg-sources.outputs.cache-primary-key }}
114+
enableCrossOsArchive: false
115+
116+
- name: Build unit-test for Fluent Bit packages (only for x86 and x64)
117+
run: |
118+
cmake -G "NMake Makefiles" `
119+
-D FLB_TESTS_INTERNAL=On `
120+
-D FLB_NIGHTLY_BUILD='${{ inputs.unstable }}' `
121+
-D OPENSSL_ROOT_DIR='${{ matrix.config.openssl_dir }}' `
122+
${{ matrix.config.cmake_additional_opt }} `
123+
-D FLB_LIBYAML_DIR=C:\vcpkg\packages\libyaml_${{ matrix.config.vcpkg_triplet }} `
124+
-D FLB_WITHOUT_flb-rt-out_elasticsearch=On `
125+
-D FLB_WITHOUT_flb-rt-out_td=On `
126+
-D FLB_WITHOUT_flb-rt-out_forward=On `
127+
-D FLB_WITHOUT_flb-rt-in_disk=On `
128+
-D FLB_WITHOUT_flb-rt-in_proc=On `
129+
-D FLB_WITHOUT_flb-it-parser=On `
130+
-D FLB_WITHOUT_flb-it-unit_sizes=On `
131+
-D FLB_WITHOUT_flb-it-network=On `
132+
-D FLB_WITHOUT_flb-it-pack=On `
133+
-D FLB_WITHOUT_flb-it-signv4=On `
134+
-D FLB_WITHOUT_flb-it-aws_credentials=On `
135+
-D FLB_WITHOUT_flb-it-aws_credentials_ec2=On `
136+
-D FLB_WITHOUT_flb-it-aws_credentials_http=On `
137+
-D FLB_WITHOUT_flb-it-aws_credentials_profile=On `
138+
-D FLB_WITHOUT_flb-it-aws_credentials_sts=On `
139+
-D FLB_WITHOUT_flb-it-aws_util=On `
140+
-D FLB_WITHOUT_flb-it-input_chunk=On `
141+
../
142+
cmake --build .
143+
shell: pwsh
144+
working-directory: build
145+
146+
- name: Upload unit test binaries
147+
uses: actions/upload-artifact@v4
148+
with:
149+
name: windows-unit-tests-${{ matrix.config.arch }}
150+
path: |
151+
build/**/*.exe
152+
if-no-files-found: error
153+
154+
- name: Display dependencies w/ dumpbin
155+
run: |
156+
dumpbin /dependents .\bin\fluent-bit.exe
157+
working-directory: build
158+
159+
- name: Build unit-test for Fluent Bit packages (only for x86 and x64)
160+
run: |
161+
ctest --build-run-dir "$PWD" --output-on-failure
162+
shell: pwsh
163+
working-directory: build

.github/workflows/pr-windows-build.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ jobs:
3838
environment: pr
3939
secrets:
4040
token: ${{ secrets.GITHUB_TOKEN }}
41+
42+
run-windows-unit-tests:
43+
needs:
44+
- pr-windows-build
45+
uses: ./.github/workflows/call-windows-unit-tests.yaml
46+
with:
47+
version: ${{ github.sha }}
48+
ref: ${{ github.sha }}
49+
environment: pr
50+
secrets:
51+
token: ${{ secrets.GITHUB_TOKEN }}

tests/internal/file.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ static void check_equals(flb_sds_t result, const char *expected)
2323
static void test_file_read_text_file()
2424
{
2525
flb_sds_t result = flb_file_read(TEXT_FILE);
26-
check_equals(result, "Some text file\n\nline 3\n\nline 5\n");
26+
/* In Windows, \n is replaced with \r\n by git settings. */
27+
if (strstr(result, "\r\n") != NULL) {
28+
check_equals(result, "Some text file\r\n\r\nline 3\r\n\r\nline 5\r\n");
29+
}
30+
else {
31+
check_equals(result, "Some text file\n\nline 3\n\nline 5\n");
32+
}
2733
flb_sds_destroy(result);
2834
}
2935

0 commit comments

Comments
 (0)