Skip to content

Commit 3eadab8

Browse files
authored
Update the clang-format job to give a patch (#469)
* Update the clang-format job to give a patch * Apply clang-format to the unit tests (#470) * Update the clang-format job to give a patch * Apply clang-format to the unit tests
1 parent 99e2ce1 commit 3eadab8

20 files changed

+1770
-2699
lines changed

.github/workflows/ci.yml

-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ on:
1010
- develop
1111
- master
1212
jobs:
13-
clang-format-check:
14-
runs-on: macos-latest
15-
steps:
16-
- name: Clone repository
17-
uses: actions/checkout@v3
18-
- name: Install clang-format
19-
run: |
20-
brew install clang-format
21-
clang-format --version
22-
- name: Run clang format check
23-
run: |
24-
bash scripts/check-clang.sh
25-
2613
mac-os-build-gcc:
2714
runs-on: macos-13
2815
permissions:

.github/workflows/clang-format.yml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: clang-format-check
2+
on: [ push ]
3+
jobs:
4+
check-format:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout code
8+
uses: actions/checkout@v4
9+
10+
- name: Set up clang-format
11+
run: |
12+
sudo apt-get update
13+
sudo apt-get install -y clang-format-14
14+
sudo ln -sf /usr/bin/clang-format-14 /usr/bin/clang-format
15+
16+
- name: Check clang
17+
run: |
18+
find . -name "*.c" -o -name "*.h" -o -name "*.cpp" | xargs clang-format -style=file --dry-run -Werror
19+
shell: bash
20+
21+
- name: Clang Format Success Summary
22+
if: success()
23+
run: |
24+
echo "# 🎉 Clang Format Check Passed!" >> $GITHUB_STEP_SUMMARY
25+
echo "All files are properly formatted." >> $GITHUB_STEP_SUMMARY
26+
27+
format-and-upload:
28+
runs-on: ubuntu-latest
29+
needs: check-format
30+
if: failure() # Only run this job if the check-format job fails
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- name: Set up clang-format
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y clang-format-14
40+
sudo ln -sf /usr/bin/clang-format-14 /usr/bin/clang-format
41+
42+
- name: Find and format .c, .h, and .cpp files
43+
run: |
44+
git add -u
45+
# Apply formatting
46+
find . -name "*.c" -o -name "*.h" -o -name "*.cpp" | xargs clang-format -i -style=file
47+
# Check which files were modified by clang-format
48+
git diff --name-only > modified_files.txt
49+
git diff > clang-format-fix.patch
50+
echo "Modified files: $(cat modified_files.txt)"
51+
shell: bash
52+
53+
- name: Archive formatted files
54+
run: |
55+
mkdir -p formatted_files
56+
while IFS= read -r file; do
57+
echo "Compressing $file ..."
58+
# Copy only modified files to the formatted_files directory, preserving structure
59+
mkdir -p "formatted_files/$(dirname "$file")"
60+
cp "$file" "formatted_files/$file"
61+
done < modified_files.txt
62+
shell: bash
63+
64+
- name: Upload formatted files
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: formatted-files
68+
path: formatted_files
69+
70+
- name: Upload patch file
71+
uses: actions/upload-artifact@v4
72+
with:
73+
name: clang-format-fix.patch
74+
path: clang-format-fix.patch
75+
76+
- name: Generate Markdown Summary for Corrected Files
77+
run: |
78+
echo "# ❌ Clang Format Check Failed" >> $GITHUB_STEP_SUMMARY
79+
echo "$(wc -l < modified_files.txt) file(s) are not clang-format compliant. Please review the list of affected files below:" >> $GITHUB_STEP_SUMMARY
80+
echo "" >> $GITHUB_STEP_SUMMARY
81+
while IFS= read -r file; do
82+
echo "- \`$file\`" >> $GITHUB_STEP_SUMMARY
83+
done < modified_files.txt
84+
echo "" >> $GITHUB_STEP_SUMMARY
85+
echo "## 🛠️ Fixed files" >> $GITHUB_STEP_SUMMARY
86+
echo "**Total Files Formatted**: $(wc -l < modified_files.txt)" >> $GITHUB_STEP_SUMMARY
87+
echo "" >> $GITHUB_STEP_SUMMARY
88+
echo "ℹ️ Check the \"Artifacts\" below for the corrected files." >> $GITHUB_STEP_SUMMARY
89+
echo "" >> $GITHUB_STEP_SUMMARY
90+
echo "To apply the formatting fixes locally, download the patch file below and place it in the repository root. Then run this command from the repository root:" >> $GITHUB_STEP_SUMMARY
91+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
92+
echo "git apply clang-format-fix.patch" >> $GITHUB_STEP_SUMMARY
93+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

tst/AuthCallbackTest.cpp

+23-49
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#include "ProducerTestFixture.h"
22

3-
namespace com { namespace amazonaws { namespace kinesis { namespace video {
3+
namespace com {
4+
namespace amazonaws {
5+
namespace kinesis {
6+
namespace video {
47

5-
class AuthCallbackTest : public ProducerClientTestBase {
6-
};
8+
class AuthCallbackTest : public ProducerClientTestBase {};
79

810
TEST_F(AuthCallbackTest, RotatingStaticAuthCallback_ReturnsExtendedExpiration)
911
{
10-
1112
// check AWSCredentials is extended by rotation period for stream token function.
12-
1313
}
1414

1515
TEST_F(AuthCallbackTest, ioTExpirationParsing_Returns_Success)
1616
{
17-
1817
UINT64 iotTimeInEpoch = 1548972059;
1918
CHAR validFormatIotExpirationTimeStamp[] = "2019-01-31T23:00:59Z"; // expiration is current time + 1 hour
2019
UINT64 expirationTimestampInEpoch = 0;
@@ -23,24 +22,20 @@ TEST_F(AuthCallbackTest, ioTExpirationParsing_Returns_Success)
2322

2423
EXPECT_TRUE(iotTimeInEpoch == expirationTimestampInEpoch / HUNDREDS_OF_NANOS_IN_A_SECOND - 3600);
2524

26-
iotTimeInEpoch = 1548975659; // iot expiration same as current time
25+
iotTimeInEpoch = 1548975659; // iot expiration same as current time
2726

2827
convertTimestampToEpoch(validFormatIotExpirationTimeStamp, iotTimeInEpoch, &expirationTimestampInEpoch);
2928

3029
EXPECT_TRUE(iotTimeInEpoch == expirationTimestampInEpoch / HUNDREDS_OF_NANOS_IN_A_SECOND);
3130

32-
iotTimeInEpoch = 1548975660; // iot expiration occurs in the past
31+
iotTimeInEpoch = 1548975660; // iot expiration occurs in the past
3332

3433
EXPECT_EQ(STATUS_IOT_EXPIRATION_OCCURS_IN_PAST,
35-
convertTimestampToEpoch(validFormatIotExpirationTimeStamp,
36-
iotTimeInEpoch,
37-
&expirationTimestampInEpoch));
38-
34+
convertTimestampToEpoch(validFormatIotExpirationTimeStamp, iotTimeInEpoch, &expirationTimestampInEpoch));
3935
}
4036

4137
TEST_F(AuthCallbackTest, invalidIoTExpirationParsing_Returns_Failure)
4238
{
43-
4439
UINT64 iotTimeInEpoch = 1548972059;
4540
UINT64 expirationTimestampInEpoch = 0;
4641
CHAR invalidIotExpirationTimeStamp[] = "2019-00-31T23:00:59Z";
@@ -51,13 +46,10 @@ TEST_F(AuthCallbackTest, invalidIoTExpirationParsing_Returns_Failure)
5146
convertTimestampToEpoch(invalidIotExpirationTimeStamp, iotTimeInEpoch, &expirationTimestampInEpoch));
5247

5348
EXPECT_EQ(STATUS_IOT_EXPIRATION_PARSING_FAILED,
54-
convertTimestampToEpoch(invalidFormatIotExpirationTimeStamp,
55-
iotTimeInEpoch,
56-
&expirationTimestampInEpoch));
49+
convertTimestampToEpoch(invalidFormatIotExpirationTimeStamp, iotTimeInEpoch, &expirationTimestampInEpoch));
5750

5851
EXPECT_EQ(STATUS_TIMESTAMP_STRING_UNRECOGNIZED_FORMAT,
5952
convertTimestampToEpoch(emptyIotExpirationTimestamp, iotTimeInEpoch, &expirationTimestampInEpoch));
60-
6153
}
6254

6355
TEST_F(AuthCallbackTest, verify_fileAuthCallback_provider_works)
@@ -82,19 +74,11 @@ TEST_F(AuthCallbackTest, verify_fileAuthCallback_provider_works)
8274
EXPECT_EQ(STATUS_SUCCESS, createDefaultDeviceInfo(&pDeviceInfo));
8375
pDeviceInfo->clientInfo.loggerLogLevel = this->loggerLogLevel;
8476
EXPECT_EQ(STATUS_SUCCESS, createRealtimeVideoStreamInfoProvider(streamName, TEST_RETENTION_PERIOD, TEST_STREAM_BUFFER_DURATION, &pStreamInfo));
85-
EXPECT_EQ(STATUS_SUCCESS, createAbstractDefaultCallbacksProvider(TEST_DEFAULT_CHAIN_COUNT,
86-
API_CALL_CACHE_TYPE_NONE,
87-
TEST_CACHING_ENDPOINT_PERIOD,
88-
mRegion,
89-
TEST_CONTROL_PLANE_URI,
90-
mCaCertPath,
91-
NULL,
92-
NULL,
93-
&pClientCallbacks));
94-
95-
EXPECT_EQ(STATUS_SUCCESS, createFileAuthCallbacks(pClientCallbacks,
96-
authFilePath,
97-
&pAuthCallbacks));
77+
EXPECT_EQ(STATUS_SUCCESS,
78+
createAbstractDefaultCallbacksProvider(TEST_DEFAULT_CHAIN_COUNT, API_CALL_CACHE_TYPE_NONE, TEST_CACHING_ENDPOINT_PERIOD, mRegion,
79+
TEST_CONTROL_PLANE_URI, mCaCertPath, NULL, NULL, &pClientCallbacks));
80+
81+
EXPECT_EQ(STATUS_SUCCESS, createFileAuthCallbacks(pClientCallbacks, authFilePath, &pAuthCallbacks));
9882

9983
EXPECT_EQ(STATUS_SUCCESS, createKinesisVideoClientSync(pDeviceInfo, pClientCallbacks, &clientHandle));
10084
EXPECT_EQ(STATUS_SUCCESS, createKinesisVideoStreamSync(clientHandle, pStreamInfo, &streamHandle));
@@ -122,23 +106,13 @@ TEST_F(AuthCallbackTest, credential_provider_auth_callbacks_test)
122106
streamName[MAX_STREAM_NAME_LEN] = '\0';
123107
EXPECT_EQ(STATUS_SUCCESS, createDefaultDeviceInfo(&pDeviceInfo));
124108
pDeviceInfo->clientInfo.loggerLogLevel = this->loggerLogLevel;
125-
EXPECT_EQ(STATUS_SUCCESS, createRealtimeVideoStreamInfoProvider(streamName,
126-
TEST_RETENTION_PERIOD,
127-
TEST_STREAM_BUFFER_DURATION,
128-
&pStreamInfo));
129-
EXPECT_EQ(STATUS_SUCCESS, createAbstractDefaultCallbacksProvider(TEST_DEFAULT_CHAIN_COUNT,
130-
API_CALL_CACHE_TYPE_NONE,
131-
TEST_CACHING_ENDPOINT_PERIOD,
132-
mRegion,
133-
TEST_CONTROL_PLANE_URI,
134-
mCaCertPath,
135-
NULL,
136-
NULL,
137-
&pClientCallbacks));
109+
EXPECT_EQ(STATUS_SUCCESS, createRealtimeVideoStreamInfoProvider(streamName, TEST_RETENTION_PERIOD, TEST_STREAM_BUFFER_DURATION, &pStreamInfo));
110+
EXPECT_EQ(STATUS_SUCCESS,
111+
createAbstractDefaultCallbacksProvider(TEST_DEFAULT_CHAIN_COUNT, API_CALL_CACHE_TYPE_NONE, TEST_CACHING_ENDPOINT_PERIOD, mRegion,
112+
TEST_CONTROL_PLANE_URI, mCaCertPath, NULL, NULL, &pClientCallbacks));
138113

139114
// Create the credential provider based on static credentials which will be used with auth callbacks
140-
EXPECT_EQ(STATUS_SUCCESS, createStaticCredentialProvider(mAccessKey, 0, mSecretKey, 0, mSessionToken, 0,
141-
MAX_UINT64, &pAwsCredentialProvider));
115+
EXPECT_EQ(STATUS_SUCCESS, createStaticCredentialProvider(mAccessKey, 0, mSecretKey, 0, mSessionToken, 0, MAX_UINT64, &pAwsCredentialProvider));
142116

143117
// Creating client should fail with missing auth callbacks
144118
EXPECT_EQ(STATUS_SERVICE_CALL_CALLBACKS_MISSING, createKinesisVideoClientSync(pDeviceInfo, pClientCallbacks, &clientHandle));
@@ -161,7 +135,7 @@ TEST_F(AuthCallbackTest, credential_provider_auth_callbacks_test)
161135
EXPECT_EQ(STATUS_SUCCESS, freeCallbacksProvider(&pClientCallbacks));
162136
EXPECT_EQ(STATUS_SUCCESS, freeStaticCredentialProvider(&pAwsCredentialProvider));
163137
}
164-
} // namespace video
165-
} // namespace kinesis
166-
} // namespace amazonaws
167-
} // namespace com;
138+
} // namespace video
139+
} // namespace kinesis
140+
} // namespace amazonaws
141+
} // namespace com

0 commit comments

Comments
 (0)