Skip to content

Commit b190141

Browse files
authored
Merge pull request #195 from contentstack/development
Development
2 parents 9569279 + 52cd1e7 commit b190141

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
<use>false</use>
266266
<source>1.8</source>
267267
<links>
268-
<link>https://docs.oracle.com/en/java/javase/23/docs/api/index.html</link>
268+
<link>https://docs.oracle.com/en/java/javase/23/docs/api/</link>
269269
</links>
270270
<doclint>none</doclint>
271271
</configuration>
@@ -278,7 +278,7 @@
278278
<artifactId>maven-surefire-plugin</artifactId>
279279
<version>2.22.2</version>
280280
<configuration>
281-
<!-- <skipTests>true</skipTests> -->
281+
<skipTests>true</skipTests>
282282
</configuration>
283283
</plugin>
284284

send-report.sh

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
11
#!/bin/bash
2-
2+
# This script temporarily modifies the pom.xml file to enable tests,
3+
# runs the tests, generates a Surefire HTML report, and sends it to Slack.
4+
# It also ensures that the original pom.xml is restored afterward.
5+
# Usage: ./send-report.sh
6+
# Ensure the script is run from the root of the project
7+
# macOS and Linux compatible
38
set -e # Exit immediately if any command fails
49

10+
# Create a temporary file that won't be committed
11+
backup=$(mktemp)
12+
# Function to restore pom.xml and clean up
13+
restore_pom() {
14+
echo "🔄 Restoring original pom.xml..."
15+
cat "$backup" > pom.xml
16+
rm -f "$backup" # Clean up our temp file
17+
echo "✅ Original pom.xml restored."
18+
}
19+
# Set trap to restore pom.xml on exit (normal or error)
20+
trap restore_pom EXIT
21+
22+
echo "🔍 Backing up pom.xml..."
23+
cat pom.xml > "$backup"
24+
25+
echo "🔧 Temporarily modifying pom.xml to enable tests..."
26+
# Cross-platform sed command (works on both macOS and Linux)
27+
if [[ "$OSTYPE" == "darwin"* ]]; then
28+
# macOS/BSD sed
29+
sed -i '' 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml
30+
else
31+
# GNU sed (Linux, including GoCD agents)
32+
sed -i 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml
33+
fi
34+
35+
echo "🔧 Building project..."
36+
mvn clean package
37+
538
echo "🧪 Running tests..."
639
mvn clean test
740

@@ -11,4 +44,8 @@ mvn surefire-report:report-only
1144
echo "📤 Sending test report to Slack..."
1245
mvn compile exec:java -Dexec.mainClass="com.contentstack.sdk.SanityReport"
1346

14-
echo "✅ Done."
47+
# Restore pom.xml and clean up
48+
restore_pom
49+
trap - EXIT # Remove the trap
50+
51+
echo "✅ Done. All tests complete and original pom.xml restored."

src/main/java/com/contentstack/sdk/SanityReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class SanityReport {
1616

17-
private static final String PROPERTIES_FILE = "src/test/resources/test-config.properties";
17+
private static final String PROPERTIES_FILE = "src/test/resources/.env";
1818

1919
public void generateTestSummaryAndSendToSlack(File reportFile) throws IOException, SlackApiException {
2020
Properties properties = loadProperties(PROPERTIES_FILE);

src/test/java/com/contentstack/sdk/Credentials.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
public class Credentials {
88

9-
static Dotenv env = getEnv();
9+
static Dotenv env = Dotenv.configure()
10+
.directory("src/test/resources")
11+
.filename(".env") // or ".env" if you rename it
12+
.load();
13+
1014

1115
private static String envChecker() {
1216
String githubActions = System.getenv("GITHUB_ACTIONS");
@@ -17,15 +21,6 @@ private static String envChecker() {
1721
}
1822
}
1923

20-
public static Dotenv getEnv() {
21-
env = Dotenv.configure()
22-
.directory("src/test/resources")
23-
.filename("env") // instead of '.env', use 'env'
24-
.load();
25-
26-
return Dotenv.load();
27-
}
28-
2924
public static final String HOST = env.get("HOST", "cdn.contentstack.io");
3025
public static final String API_KEY = env.get("API_KEY", "");
3126
public static final String DELIVERY_TOKEN = env.get("DELIVERY_TOKEN", "");

0 commit comments

Comments
 (0)