diff --git a/pom.xml b/pom.xml index 7068efe..5ab23a8 100644 --- a/pom.xml +++ b/pom.xml @@ -265,7 +265,7 @@ false 1.8 - https://docs.oracle.com/en/java/javase/23/docs/api/index.html + https://docs.oracle.com/en/java/javase/23/docs/api/ none @@ -278,7 +278,7 @@ maven-surefire-plugin 2.22.2 - + true diff --git a/send-report.sh b/send-report.sh index 14ec36b..e404380 100755 --- a/send-report.sh +++ b/send-report.sh @@ -1,7 +1,40 @@ #!/bin/bash - +# This script temporarily modifies the pom.xml file to enable tests, +# runs the tests, generates a Surefire HTML report, and sends it to Slack. +# It also ensures that the original pom.xml is restored afterward. +# Usage: ./send-report.sh +# Ensure the script is run from the root of the project +# macOS and Linux compatible set -e # Exit immediately if any command fails +# Create a temporary file that won't be committed +backup=$(mktemp) +# Function to restore pom.xml and clean up +restore_pom() { + echo "๐Ÿ”„ Restoring original pom.xml..." + cat "$backup" > pom.xml + rm -f "$backup" # Clean up our temp file + echo "โœ… Original pom.xml restored." +} +# Set trap to restore pom.xml on exit (normal or error) +trap restore_pom EXIT + +echo "๐Ÿ” Backing up pom.xml..." +cat pom.xml > "$backup" + +echo "๐Ÿ”ง Temporarily modifying pom.xml to enable tests..." +# Cross-platform sed command (works on both macOS and Linux) +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS/BSD sed + sed -i '' 's/true<\/skipTests>/false<\/skipTests>/g' pom.xml +else + # GNU sed (Linux, including GoCD agents) + sed -i 's/true<\/skipTests>/false<\/skipTests>/g' pom.xml +fi + +echo "๐Ÿ”ง Building project..." +mvn clean package + echo "๐Ÿงช Running tests..." mvn clean test @@ -11,4 +44,8 @@ mvn surefire-report:report-only echo "๐Ÿ“ค Sending test report to Slack..." mvn compile exec:java -Dexec.mainClass="com.contentstack.sdk.SanityReport" -echo "โœ… Done." +# Restore pom.xml and clean up +restore_pom +trap - EXIT # Remove the trap + +echo "โœ… Done. All tests complete and original pom.xml restored." \ No newline at end of file diff --git a/src/main/java/com/contentstack/sdk/SanityReport.java b/src/main/java/com/contentstack/sdk/SanityReport.java index b61a015..bf2fc92 100644 --- a/src/main/java/com/contentstack/sdk/SanityReport.java +++ b/src/main/java/com/contentstack/sdk/SanityReport.java @@ -14,7 +14,7 @@ public class SanityReport { - private static final String PROPERTIES_FILE = "src/test/resources/test-config.properties"; + private static final String PROPERTIES_FILE = "src/test/resources/.env"; public void generateTestSummaryAndSendToSlack(File reportFile) throws IOException, SlackApiException { Properties properties = loadProperties(PROPERTIES_FILE); diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index ea26750..99196ef 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -6,7 +6,11 @@ public class Credentials { - static Dotenv env = getEnv(); + static Dotenv env = Dotenv.configure() + .directory("src/test/resources") + .filename(".env") // or ".env" if you rename it + .load(); + private static String envChecker() { String githubActions = System.getenv("GITHUB_ACTIONS"); @@ -17,15 +21,6 @@ private static String envChecker() { } } - public static Dotenv getEnv() { - env = Dotenv.configure() - .directory("src/test/resources") - .filename("env") // instead of '.env', use 'env' - .load(); - - return Dotenv.load(); - } - public static final String HOST = env.get("HOST", "cdn.contentstack.io"); public static final String API_KEY = env.get("API_KEY", ""); public static final String DELIVERY_TOKEN = env.get("DELIVERY_TOKEN", "");