Skip to content

Commit 5f4ebbd

Browse files
committed
Create Test Script
1 parent 0e4b16b commit 5f4ebbd

File tree

3 files changed

+61
-33
lines changed

3 files changed

+61
-33
lines changed

.github/test.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# Build Docker
4+
5+
docker build -t codemc/mariadb src/test/docker/mariadb
6+
docker run -d -p 3306:3306 --name mariadb codemc/mariadb
7+
8+
docker build -t codemc/jenkins src/test/docker/jenkins
9+
docker run -d -p 8080:8080 --name jenkins-rest codemc/jenkins
10+
11+
docker build -t codemc/nexus src/test/docker/nexus
12+
docker run -d -p 8081:8081 --name nexus-rest codemc/nexus
13+
14+
# Wait for Services
15+
16+
echo "Waiting for MariaDB to be ready..."
17+
until docker exec mariadb mariadb -u root -e "SELECT 1"; do
18+
sleep 2
19+
done
20+
21+
echo "Waiting for Jenkins to be ready..."
22+
until curl -s "http://localhost:8080" | grep "Dashboard"; do
23+
sleep 2
24+
done
25+
26+
echo "Waiting for Nexus to be ready..."
27+
until curl -s "http://localhost:8081"; do
28+
sleep 2
29+
done
30+
31+
# Run Docker
32+
33+
docker cp nexus-rest:/nexus-data/admin.password /tmp/admin.password
34+
./gradlew clean test
35+
rm -rf /tmp/admin.password

.github/workflows/build.yml

+4-25
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,8 @@ jobs:
4242
cache: 'gradle'
4343
- name: Change Permissions
4444
run: chmod +x ./gradlew
45-
- name: Setup Servers
46-
run: |
47-
docker build -t nexus-rest/nexus src/test/docker/nexus
48-
docker run -d -p 8081:8081 --name nexus-rest nexus-rest/nexus
49-
50-
docker build -t jenkins-rest/jenkins src/test/docker/jenkins
51-
docker run -d -p 8080:8080 --name jenkins-rest jenkins-rest/jenkins
52-
- name: Wait for Jenkins
53-
run: |
54-
echo "Waiting for Jenkins to be ready..."
55-
sleep 60
56-
until curl -s http://localhost:8080 | grep "Dashboard"; do
57-
sleep 10
58-
done
59-
- name: Wait for Nexus
60-
run: |
61-
echo "Waiting for Nexus to be ready..."
62-
sleep 60
63-
until curl -s http://localhost:8081; do
64-
sleep 10
65-
done
6645
- name: Gradle Test
67-
run: |
68-
docker cp nexus-rest:/nexus-data/admin.password /tmp/admin.password
69-
./gradlew test
70-
rm -rf /tmp/admin.password
46+
run: bash .github/test.sh
7147
- name: Stop Servers
7248
if: success() || failure()
7349
run: |
@@ -76,6 +52,9 @@ jobs:
7652
7753
docker stop nexus-rest
7854
docker rm nexus-rest
55+
56+
docker stop mariadb
57+
docker rm mariadb
7958
- name: Collect JaCoCo Report
8059
if: ${{ github.event_name != 'pull_request' }}
8160
id: jacoco_reporter

README.md

+22-8
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ dependencies {
6666

6767
## Local Testing
6868

69-
Test suites rely on both an active Nexus and Jenkins instance at ports `8081` and `8080` respectively.
69+
Test suites rely on both an active services, such as Nexus and Jenkins instances.
7070
Luckily, the project comes with Docker files to set these up yourself.
7171

7272
Without the services, some test suites will fail.
7373

74-
### [Act](https://nektosact.com) (preferred)
74+
### Test Script (preferred)
75+
76+
A bash script is provided to build the containers and run the tests. This is the easiest way to test the project.
77+
78+
Requires [Docker](https://www.docker.com) to be installed.
79+
80+
```bash
81+
bash .github/test.sh
82+
```
83+
84+
### [Act](https://nektosact.com)
7585

7686
Test the project by using Act, a GitHub Action emulator. This will set up and test everything for you.
7787

@@ -84,16 +94,20 @@ act push -j 'test'
8494
First, build and run both containers:
8595

8696
```bash
87-
# Docker
88-
docker build -t nexus-rest/nexus src/test/docker/nexus
89-
docker run -d -p 8081:8081 --name nexus-rest nexus-rest/nexus
97+
# MariaDB
98+
docker build -t codemc/mariadb src/test/docker/mariadb
99+
docker run -d -p 3306:3306 --name mariadb codemc/mariadb
90100

91101
# Jenkins
92-
docker build -t jenkins-rest/jenkins src/test/docker/jenkins
93-
docker run -d -p 8080:8080 --name jenkins-rest jenkins-rest/jenkins
102+
docker build -t codemc/jenkins src/test/docker/jenkins
103+
docker run -d -p 8080:8080 --name jenkins-rest codemc/jenkins
104+
105+
# Nexus
106+
docker build -t codemc/nexus src/test/docker/nexus
107+
docker run -d -p 8081:8081 --name nexus-rest codemc/nexus
94108
```
95109

96-
Before running, copy over the `admin.password` file into the `/tmp/` folder (yes, you will need to make it on Windows) so that the API can log in to the newly created Nexus instance.
110+
Before running, copy over the `admin.password` file into the `/tmp/` folder so that the API can log in to the newly created Nexus instance.
97111

98112
```bash
99113
docker cp nexus-rest:/nexus-data/admin.password /tmp/admin.password

0 commit comments

Comments
 (0)