Skip to content

Commit b58e2a4

Browse files
Release integration test framework - generate images during check action execution (#235)
- Release integration test framework - generate images during check action execution
1 parent 7752efe commit b58e2a4

File tree

6 files changed

+92
-27
lines changed

6 files changed

+92
-27
lines changed

.github/workflows/checks.yml

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,70 @@ on:
44
push:
55
workflow_dispatch:
66

7+
env:
8+
TEST_FRAMEWORK_PATH: core-codemods/src/test/java/io/codemodder/codemods/integration
9+
710
jobs:
811
check:
912
name: Check
1013
runs-on: ubuntu-latest
1114
steps:
12-
- uses: actions/checkout@v3
13-
- uses: actions/setup-python@v4
15+
- name: Clone repository
16+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
17+
18+
- name: Setup Java
19+
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
20+
with:
21+
distribution: 'temurin'
22+
java-version: '17'
23+
24+
# tar file generation, tar file contains codemodder executable file to be used in the codemodder-base image
25+
- name: Generate distribution
26+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
27+
with:
28+
arguments: core-codemods:distTar
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
32+
with:
33+
driver: docker
34+
35+
- name: Build codemodder base image
36+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
37+
with:
38+
context: .
39+
file: ${{ env.TEST_FRAMEWORK_PATH }}/baseimage/Dockerfile
40+
tags: codemodder/codemodder-base:latest
41+
42+
# defining the list of test projects for which an image will be generated
43+
- name: Setup test project names
44+
run: |
45+
TEST_PROJECT_NAMES=$(./gradlew core-codemods:getTestProjectNames -q)
46+
echo "TEST_PROJECT_NAMES<<EOF">> $GITHUB_ENV
47+
echo $TEST_PROJECT_NAMES >> $GITHUB_ENV
48+
echo "EOF" >> $GITHUB_ENV
49+
50+
- name: Build test projects images
51+
run: |
52+
for TEST_PROJECT_NAME in ${{ env.TEST_PROJECT_NAMES }}; do
53+
docker build \
54+
-f ${{ env.TEST_FRAMEWORK_PATH }}/projectimage/Dockerfile \
55+
--build-arg CODEMODDER_BASE_IMAGE=codemodder/codemodder-base \
56+
--build-arg CODEMOD_ID=${TEST_PROJECT_NAME} \
57+
-t codemodder/${TEST_PROJECT_NAME}:latest \
58+
.
59+
done
60+
61+
- name: Setup Python
62+
uses: actions/setup-python@v4
1463
with:
1564
python-version: '3.10'
65+
1666
- name: Install Semgrep
1767
run: python3 -m pip install semgrep==1.15.0
18-
- uses: actions/setup-java@v3
19-
with:
20-
distribution: 'temurin'
21-
java-version: '17'
22-
- uses: gradle/gradle-build-action@v2
68+
69+
- name: Run Check task
70+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
2371
with:
2472
arguments: check --stacktrace
2573
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

core-codemods/build.gradle.kts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,32 @@ tasks.named("check") {
6868
@Suppress("UnstableApiUsage")
6969
dependsOn(testing.suites.named(integrationTestSuiteName))
7070
}
71+
72+
val getTestProjectNames by tasks.registering {
73+
group = "custom"
74+
description = "Extracts codemodIds from IntegrationTestMetadata"
75+
76+
val sourceDir = file("src/test/java/io/codemodder/codemods/integration/tests")
77+
val codemodIdRegex = """codemodId\s*=\s*["']([^"']+)["']""".toRegex()
78+
79+
doLast {
80+
val codemodIds = mutableListOf<String>()
81+
sourceDir
82+
.walkTopDown()
83+
.filter { it.isFile && it.name.endsWith(".java") }
84+
.forEach { file ->
85+
val content = file.readText()
86+
val matchResult = codemodIdRegex.find(content)
87+
88+
if (matchResult != null) {
89+
codemodIds.add(matchResult.groupValues[1])
90+
}
91+
}
92+
93+
println(codemodIds.joinToString(" "))
94+
}
95+
}
96+
97+
tasks.withType(JavaCompile::class) {
98+
dependsOn(getTestProjectNames)
99+
}

core-codemods/src/test/java/io/codemodder/codemods/integration/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ARG CODEMOD_ID
22

3-
FROM $CODEMOD_ID
3+
FROM codemodder/$CODEMOD_ID
44

55
ARG RUN_CODEMOD=false
66
#defining the argument again because the value is unavailable after the first stage ends.

core-codemods/src/test/java/io/codemodder/codemods/integration/baseimage/Dockerfile

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ FROM openjdk:17-jdk-slim
22

33
RUN apt-get update
44

5-
# Install Python 3 and pip
6-
RUN apt-get install -y python3 python3-pip
7-
8-
# Update the package list and install wget
9-
RUN apt-get install -y wget unzip
5+
# Install Python 3, pip and wget
6+
RUN apt-get install -y python3 python3-pip wget unzip
107

118
# Install Gradle
129
ENV GRADLE_VERSION=8.2.1
@@ -19,16 +16,11 @@ RUN wget -q "https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-
1916
# Set environment variables
2017
ENV PATH="${GRADLE_HOME}/bin:${PATH}"
2118

22-
# Set Python as the default Python interpreter
23-
RUN ln -s /usr/bin/python3 /usr/bin/python
24-
25-
# Display the installed versions for verification
26-
RUN java -version
27-
RUN python --version
28-
RUN gradle --version
29-
30-
# Install Semgrep using pip
31-
RUN pip install semgrep
19+
RUN ln -s /usr/bin/python3 /usr/bin/python && \
20+
java -version && \
21+
python --version && \
22+
gradle --version && \
23+
python3 -m pip install semgrep==1.15.0
3224

3325
# Generate tool executable
3426
WORKDIR /codemodder-java

core-codemods/src/test/java/io/codemodder/codemods/integration/tests/MoveSwitchDefaultCaseLastCodemodIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import io.codemodder.codemods.integration.util.CodemodIntegrationTestMixin;
44
import io.codemodder.codemods.integration.util.IntegrationTestMetadata;
55
import io.codemodder.codemods.integration.util.IntegrationTestPropertiesMetadata;
6-
import org.junit.jupiter.api.Disabled;
76

8-
@Disabled
97
@IntegrationTestMetadata(
108
codemodId = "move-switch-default-last",
119
tests = {

core-codemods/src/test/java/io/codemodder/codemods/integration/tests/VerboseRequestMappingCodemodIntegrationTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import io.codemodder.codemods.integration.util.CodemodIntegrationTestMixin;
44
import io.codemodder.codemods.integration.util.IntegrationTestMetadata;
55
import io.codemodder.codemods.integration.util.IntegrationTestPropertiesMetadata;
6-
import org.junit.jupiter.api.Disabled;
76

8-
@Disabled
97
@IntegrationTestMetadata(
108
codemodId = "verbose-request-mapping",
119
tests = {

0 commit comments

Comments
 (0)