Skip to content

Commit

Permalink
validate samples with independent runs
Browse files Browse the repository at this point in the history
  • Loading branch information
ktoso committed Dec 9, 2024
1 parent 561efe2 commit 69212ce
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 73 deletions.
32 changes: 32 additions & 0 deletions .github/scripts/validate_sample.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# shellcheck disable=SC2034
declare -r GREEN='\033[0;32m'
declare -r BOLD='\033[1m'
declare -r RESET='\033[0m'

declare -r sampleDir="$1"
declare -r CI_VALIDATE_SCRIPT='ci-validate.sh'

echo ""
echo ""
echo "========================================================================"
printf "Validate sample '${BOLD}%s${RESET}' using: " "$sampleDir"
cd "$sampleDir" || exit
if [[ $(find . -name ${CI_VALIDATE_SCRIPT} -maxdepth 1) ]]; then
echo -e "Custom ${BOLD}${CI_VALIDATE_SCRIPT}${RESET} script..."
./${CI_VALIDATE_SCRIPT} || exit
elif [[ $(find . -name 'build.gradle*' -maxdepth 1) ]]; then
echo -e "${BOLD}Gradle${RESET} build..."
./gradlew build || ./gradlew build --info # re-run to get better failure output
else
echo -e "${BOLD}SwiftPM${RESET} build..."
swift build || exit
fi

echo -e "Validated sample '${BOLD}${sampleDir}${RESET}': ${BOLD}passed${RESET}."
cd - || exit

echo
printf "Done validating sample: ${sampleDir}"
echo -e "${GREEN}done${RESET}."
37 changes: 0 additions & 37 deletions .github/scripts/validate_samples.sh

This file was deleted.

14 changes: 12 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,18 @@ jobs:
- uses: actions/checkout@v4
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Verify Samples (All)
run: .github/scripts/validate_samples.sh
- name: "Verify Sample: JavaDependencySampleApp"
run: .github/scripts/validate_sample.sh Samples/JavaDependencySampleApp
- name: "Verify Sample: JavaKitSampleApp"
run: .github/scripts/validate_sample.sh Samples/JavaKitSampleApp
- name: "Verify Sample: JavaProbablyPrime"
run: .github/scripts/validate_sample.sh Samples/JavaProbablyPrime
- name: "Verify Sample: JavaSieve"
run: .github/scripts/validate_sample.sh Samples/JavaSieve
- name: "Verify Sample: SwiftAndJavaJarSampleLib"
run: .github/scripts/validate_sample.sh Samples/SwiftAndJavaJarSampleLib
- name: "Verify Sample: SwiftKitSampleApp"
run: .github/scripts/validate_sample.sh Samples/SwiftKitSampleApp
# TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape.
# - name: Build (Swift) Benchmarks
# run: "swift package --package-path Benchmarks/ benchmark list"
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let path = "/example/path/executable.exe"
print("Path = \(path)")

let ext = try! FilenameUtilsClass.getExtension(path)
print("Java FilenameUtils found extension = \(ext)")
print("org.apache.commons.io.FilenameUtils.getExtension = \(ext)")
precondition(ext == "exe")

print("Done.")
33 changes: 1 addition & 32 deletions Samples/JavaDependencySampleApp/ci-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,4 @@
set -e
set -x

JAVASWIFT="../../.build/debug/Java2Swift"
cd ../../
echo "Build Java2Swift binary..."
swift build

cd -
MODULE_NAME="JavaCommonsCSV"
MODULE_CONFIG_DIR=$(pwd)/Sources/$MODULE_NAME/

### 1) downloads all the dependencies
echo "Resolve dependencies..."
"$JAVASWIFT" --fetch "$MODULE_CONFIG_DIR/swift-java.config" \
--module-name "$MODULE_NAME" \
--cache-dir "Plugins/outputs/javadependencysampleapp/${MODULE_NAME}/destination"
--output-directory "$MODULE_CONFIG_DIR"

#### 2) extract the config for the fetched dependency
MODULE_CONFIG_PATH="$MODULE_CONFIG_DIR/swift-java.config"
DEP_JAR_CP=$(jq .classpath "$MODULE_CONFIG_PATH")
DEP_JAR_CP=$(echo "$DEP_JAR_CP" | tr -d '"') # trim the "..."

# Import just a single class for our test purposes
# shellcheck disable=SC2086
"$JAVASWIFT" --jar $DEP_JAR_CP \
--module-name "$MODULE_NAME" \
--java-package-filter org.apache.commons.io.FilenameUtils \
--existing-config amend

# for now in CI we just use what we have already generated and comitted in the config

### 3) make wrappers for the module
swift run
swift run --disable-sandbox
1 change: 0 additions & 1 deletion Sources/JavaKitDependencyResolver/swift-java.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"dependencies": [
"dev.gradleplugins:gradle-api:8.10.1"
],
"classpath": "JavaKit/build/classes/java/main",
"classes": {
"org.swift.javakit.dependencies.DependencyResolver": "DependencyResolver"
}
Expand Down

0 comments on commit 69212ce

Please sign in to comment.