From 81e8ddd541bb95a7a89d93e94da020e0296f9051 Mon Sep 17 00:00:00 2001
From: SkyeBeFreeman <928016560@qq.com>
Date: Fri, 24 Jun 2022 17:20:56 +0800
Subject: [PATCH] Update GitHub Actions workflow
---
.github/workflows/junit_test.yml | 39 +++++++++++++++----
CHANGELOG.md | 1 +
pom.xml | 2 +-
.../listener/ConfigChangeListenerTest.java | 2 +-
.../cloud/common/util/ResourceFileUtils.java | 10 ++---
.../common/util/ResourceFileUtilsTest.java | 2 +-
.../src/test/resources/test.txt | 2 +-
7 files changed, 39 insertions(+), 19 deletions(-)
diff --git a/.github/workflows/junit_test.yml b/.github/workflows/junit_test.yml
index 35fed41eb..51e9cce15 100644
--- a/.github/workflows/junit_test.yml
+++ b/.github/workflows/junit_test.yml
@@ -5,24 +5,47 @@ name: Test with Junit
on:
push:
- branches: [ 2021.0 ]
+ branches:
+ - main
+ - 2021.0
+ - 2020.0
+ - greenwich
pull_request:
- branches: [ 2021.0 ]
+ branches:
+ - main
+ - 2021.0
+ - 2020.0
+ - greenwich
jobs:
build:
+ strategy:
+ matrix:
+ java: [ 8, 11, 17 ]
+ os: [ 'windows-latest', 'macos-latest', 'ubuntu-latest' ]
- runs-on: ubuntu-latest
+ runs-on: ${{ matrix.os }}
steps:
- name: Checkout codes
- uses: actions/checkout@v2
- - name: Set up JDK 8
- uses: actions/setup-java@v2
+ uses: actions/checkout@v3
+ - name: Set up JDK ${{ matrix.java }}
+ uses: actions/setup-java@v3
with:
- java-version: '8'
- distribution: 'adopt'
+ distribution: 'temurin'
+ java-version: ${{ matrix.java }}
+ - name: Cache local Maven repository
+ uses: actions/cache@v3
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
# - name: Build with Maven
# run: mvn -B package --file pom.xml
- name: Test with Maven
run: mvn -B test --file pom.xml
+ - name: Upload coverage to Codecov
+ uses: codecov/codecov-action@v3
+ with:
+ file: '**/target/site/jacoco/jacoco.xml'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ca47946c..49aec3daa 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,3 +7,4 @@
- [fix:solve ratelimit-callee-service UnknownHostException.](https://github.com/Tencent/spring-cloud-tencent/pull/292)
- [Feature: Add config change listener feature support](https://github.com/Tencent/spring-cloud-tencent/pull/299)
- [Feature: Add config module unit test](https://github.com/Tencent/spring-cloud-tencent/pull/301)
+- [Update GitHub Actions workflow](https://github.com/Tencent/spring-cloud-tencent/pull/305)
diff --git a/pom.xml b/pom.xml
index 1721c6596..2561f4430 100644
--- a/pom.xml
+++ b/pom.xml
@@ -95,7 +95,7 @@
5.3.21
- 0.8.3
+ 0.8.8
3.2.0
1.2.7
3.0.1
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/listener/ConfigChangeListenerTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/listener/ConfigChangeListenerTest.java
index f3f70b4bc..c408f4f54 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/listener/ConfigChangeListenerTest.java
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/listener/ConfigChangeListenerTest.java
@@ -66,7 +66,7 @@ public class ConfigChangeListenerTest {
Sets.newHashSet("timeout"));
applicationEventPublisher.publishEvent(event);
-
+ Thread.sleep(200);
//after change
Assert.assertEquals(2, testConfig.getChangeCnt());
Assert.assertEquals(2000, testConfig.getTimeout());
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ResourceFileUtils.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ResourceFileUtils.java
index d79bfce8b..b5ea45d5d 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ResourceFileUtils.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/util/ResourceFileUtils.java
@@ -23,6 +23,7 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.StreamUtils;
/**
* Read file content from classpath resource.
@@ -35,20 +36,15 @@ public final class ResourceFileUtils {
}
public static String readFile(String path) throws IOException {
- StringBuilder sb = new StringBuilder();
ClassPathResource classPathResource = new ClassPathResource(path);
if (classPathResource.exists() && classPathResource.isReadable()) {
try (InputStream inputStream = classPathResource.getInputStream()) {
- byte[] buffer = new byte[1024 * 10];
- int len;
- while ((len = inputStream.read(buffer)) != -1) {
- sb.append(new String(buffer, 0, len, StandardCharsets.UTF_8));
- }
+ return StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
}
}
- return sb.toString();
+ return "";
}
}
diff --git a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/util/ResourceFileUtilsTest.java b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/util/ResourceFileUtilsTest.java
index 334cd4e20..769d99ce7 100644
--- a/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/util/ResourceFileUtilsTest.java
+++ b/spring-cloud-tencent-commons/src/test/java/com/tencent/cloud/common/util/ResourceFileUtilsTest.java
@@ -35,7 +35,7 @@ public class ResourceFileUtilsTest {
@Test
public void testReadExistedFile() throws IOException {
String content = ResourceFileUtils.readFile("test.txt");
- Assert.assertEquals("just for test\n", content);
+ Assert.assertEquals("just for test", content);
}
@Test
diff --git a/spring-cloud-tencent-commons/src/test/resources/test.txt b/spring-cloud-tencent-commons/src/test/resources/test.txt
index 63d3c2d75..e18c37483 100644
--- a/spring-cloud-tencent-commons/src/test/resources/test.txt
+++ b/spring-cloud-tencent-commons/src/test/resources/test.txt
@@ -1 +1 @@
-just for test
+just for test
\ No newline at end of file