Skip to content

Workflow fix #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
<use>false</use>
<source>1.8</source>
<links>
<link>https://docs.oracle.com/en/java/javase/23/docs/api/index.html</link>
<link>https://docs.oracle.com/en/java/javase/23/docs/api/</link>
</links>
<doclint>none</doclint>
</configuration>
Expand All @@ -278,7 +278,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!-- <skipTests>true</skipTests> -->
<skipTests>true</skipTests>
</configuration>
</plugin>

Expand Down
41 changes: 39 additions & 2 deletions send-report.sh
Original file line number Diff line number Diff line change
@@ -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/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml
else
# GNU sed (Linux, including GoCD agents)
sed -i 's/<skipTests>true<\/skipTests>/<skipTests>false<\/skipTests>/g' pom.xml
fi

echo "🔧 Building project..."
mvn clean package

echo "🧪 Running tests..."
mvn clean test

Expand All @@ -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."
2 changes: 1 addition & 1 deletion src/main/java/com/contentstack/sdk/SanityReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 5 additions & 10 deletions src/test/java/com/contentstack/sdk/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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", "");
Expand Down
Loading