Skip to content

Commit 995f34f

Browse files
Release integration test framework - generate and upload official images (#237)
* Release integration test framework - generate and upload official images
1 parent 6abec22 commit 995f34f

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# After each commit to main, this action will be triggered in order to build and push the images into the public registry.
2+
# the images from the public registry will be pulled and used during the execution of the integration test locally
3+
name: Release integration test framework
4+
5+
on:
6+
push:
7+
branches:
8+
- 'main'
9+
10+
11+
env:
12+
TEST_FRAMEWORK_PATH: core-codemods/src/test/java/io/codemodder/codemods/integration
13+
14+
jobs:
15+
upload-images:
16+
name: Upload images to Dockerhub
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Clone repository
20+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
21+
22+
- name: Setup Java
23+
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0
24+
with:
25+
distribution: 'temurin'
26+
java-version: '17'
27+
28+
# tar file generation, tar file contains codemodder executable file to be used in the codemodder-base image
29+
- name: Generate distribution
30+
uses: gradle/gradle-build-action@842c587ad8aa4c68eeba24c396e15af4c2e9f30a # v2.9.0
31+
with:
32+
arguments: core-codemods:distTar
33+
34+
- name: Login to Docker Hub
35+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
36+
with:
37+
username: ${{ vars.DOCKERHUB_USERNAME }}
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
42+
with:
43+
driver: docker
44+
45+
- name: Build codemodder base image
46+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
47+
with:
48+
context: .
49+
file: ${{ env.TEST_FRAMEWORK_PATH }}/baseimage/Dockerfile
50+
push: true
51+
tags: codemodder/codemodder-base:latest
52+
53+
# defining the list of test projects for which an image will be generated
54+
- name: Setup test project names
55+
run: |
56+
TEST_PROJECT_NAMES=$(./gradlew core-codemods:getTestProjectNames -q)
57+
echo "TEST_PROJECT_NAMES<<EOF">> $GITHUB_ENV
58+
echo $TEST_PROJECT_NAMES >> $GITHUB_ENV
59+
echo "EOF" >> $GITHUB_ENV
60+
61+
- name: Build test projects images
62+
run: |
63+
for TEST_PROJECT_NAME in ${{ env.TEST_PROJECT_NAMES }}; do
64+
docker build \
65+
-f ${{ env.TEST_FRAMEWORK_PATH }}/projectimage/Dockerfile \
66+
--build-arg CODEMODDER_BASE_IMAGE=codemodder/codemodder-base \
67+
--build-arg CODEMOD_ID=${TEST_PROJECT_NAME} \
68+
-t codemodder/${TEST_PROJECT_NAME}:latest \
69+
.
70+
docker push codemodder/${TEST_PROJECT_NAME}:latest
71+
done

core-codemods/src/test/java/io/codemodder/codemods/integration/README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,45 @@ This is a test framework, built to test that each codemod does not break the fun
88
- A main Dockerfile will be used to generate two containers, the generated images will use a specific test project image as base and the codemod will be run in just one of them. Finally, we will have two containers running the same application but one of them will have undergone a code transformation.
99
- A request to an endpoint in the test application will be performed to verify the functionality has not changed.
1010

11-
### Running test locally
11+
### How the framework works during CI/CD
12+
- Codemodder base image is built at the pipeline context with the last changes in a PR.
13+
- Test projects images are built at the pipeline context with the last changes in a PR.
14+
- Integration tests are executed using the latest generated images.
15+
- Generated images only live during the pipeline execution, a new commit wil generate new images.
16+
17+
### Running an integration test locally
18+
All what you need to do is running the integration test, required images will be pulled from the public
19+
repository https://hub.docker.com/repositories/codemodder
20+
21+
All the test framework images are re-built and pushed to the registry with the latest changes in each commit to main.
22+
23+
#### Running integration test for a specific codemod
24+
```
25+
./gradlew :core-codemods:test --tests io.codemodder.codemods.integration.tests.MoveSwitchDefaultCaseLastCodemodIntegrationTest
26+
```
27+
#### Running all the tests
28+
```
29+
./gradlew test
30+
```
31+
32+
33+
### Generating framework images locally
1234
#### Generate codemodder base image
1335
- Run `gradle distTar` command in the `core-codemods` root directory to generate `.tar` file used in the base image generation.
1436
- Run the `docker build`command in the root of the project.
1537
```
16-
docker build -f core-codemods/src/test/java/io/codemodder/codemods/integration/baseimage/Dockerfile -t codemodder-base:latest .
38+
docker build -f core-codemods/src/test/java/io/codemodder/codemods/integration/baseimage/Dockerfile -t codemodder/codemodder-base:latest .
1739
```
1840

1941
#### Generate test project base image
2042
Run the `docker build`command in the `codemodder-java` root directory, the `CODEMOD_ID` argument must have the value of the ID of the codemod we want to test
2143
and the `CODEMODDER_BASE_IMAGE` argument should have the name of the codemodder base image we want to use as name.
2244
The image tag must be the codemod ID also.
2345
```
24-
docker build -f core-codemods/src/test/java/io/codemodder/codemods/integration/projectimage/Dockerfile --build-arg CODEMOD_ID=move-switch-default-last --build-arg CODEMODDER_BASE_IMAGE=codemodder-base -t move-switch-default-last .
46+
docker build -f core-codemods/src/test/java/io/codemodder/codemods/integration/projectimage/Dockerfile --build-arg CODEMOD_ID=move-switch-default-last --build-arg CODEMODDER_BASE_IMAGE=codemodder/codemodder-base -t codemodder/move-switch-default-last .
2547
```
2648

27-
#### Running the integration test for a specific codemod
49+
#### Running integration test for a specific codemod
2850
```
2951
./gradlew :core-codemods:test --tests io.codemodder.codemods.integration.tests.MoveSwitchDefaultCaseLastCodemodIntegrationTest
3052
```

0 commit comments

Comments
 (0)