Skip to content

Commit

Permalink
Merge pull request #34 from ral-facilities/33_gha_ci_tests
Browse files Browse the repository at this point in the history
33 gha ci tests
  • Loading branch information
patrick-austin authored Oct 8, 2024
2 parents ba06dec + f2f3234 commit ff347ae
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 9 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: CI Build
on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build_and_tests:
runs-on: ubuntu-22.04
strategy:
matrix:
java_version:
- 11
# Errors with `java.lang.IllegalArgumentException: ArquillianServletRunnerEE9 not found. Could not determine ContextRoot from ProtocolMetadata, please contact DeployableContainer developer.`
# Bumping various Arquillian dependencies does not fix, leave as just Java 11
# - 17

steps:
- name: Setup Java
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: 'temurin'
java-version: ${{ matrix.java_version }}

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Run apt-get update
run: sudo apt-get update

- name: Cache local Maven repository
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# ICAT Ansible clone and install dependencies
- name: Checkout icat-ansible
uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017 # v4.0.0
with:
repository: icatproject-contrib/icat-ansible
path: icat-ansible
ref: payara6
- name: Install Ansible
run: pip install -r icat-ansible/requirements.txt

# Prep for running the playbook
- name: Create Hosts File
run: echo -e "[hosts_all]\nlocalhost ansible_connection=local" > icat-ansible/hosts
- name: Prepare vault pass
run: echo -e "icattravispw" > icat-ansible/vault_pass.txt
- name: Move vault to directory it'll get detected by Ansible
run: mv icat-ansible/vault.yml icat-ansible/group_vars/all
- name: Replace default payara user with Actions user
run: |
sed -i -e "s/^payara_user: \"glassfish\"/payara_user: \"runner\"/" icat-ansible/group_vars/all/vars.yml
- name: Set ids.server version
run: |
echo "ids_server_version: 2.1.0" >> icat-ansible/group_vars/all/vars.yml
# Force hostname to localhost - bug fix for previous ICAT Ansible issues on Actions
- name: Change hostname to localhost
run: sudo hostname -b localhost

# Remove existing MySQL installation so it doesn't interfere with GitHub Actions
- name: Remove existing mysql
run: |
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
sudo apt-get remove --purge "mysql*"
sudo rm -rf /var/lib/mysql* /etc/mysql
# Create local instance of ICAT
- name: Run ICAT Ansible Playbook
run: |
ansible-playbook icat-ansible/hosts_all.yml -i icat-ansible/hosts --vault-password-file icat-ansible/vault_pass.txt -vv
- name: Checkout
uses: actions/checkout@cd7d8d697e10461458bc61a30d094dc601a8b017 # v4.0.0

- name: LILS Generator requirements
run: pip install -r tools/requirements.txt
- name: LILS Generator
run: python tools/lorum_facility_generator.py

# Payara must be sourced otherwise the Maven build command fails
- name: Run Build
run: |
grep payara ~/.bash_profile > payara_path_command
source payara_path_command
mvn install -B -DskipTests
- name: Run Unit Tests
run: mvn test -B

# Upload logs on failure
- name: Upload DataGatewayDownload API log
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: DataGatewayDownload API logs
path: /home/runner/logs/datagateway-download-api.log

- name: Upload IDS log
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: IDS logs
path: /home/runner/logs/ids.log

- name: Upload ICAT log
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: ICAT logs
path: /home/runner/logs/icat.log

- name: Payara logs
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: Payara logs
path: /home/runner/payara*/glassfish/domains/domain1/logs/server.log
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down Expand Up @@ -245,7 +250,7 @@
</excludes>
<!-- TODO remove next line -->
<!-- <skipTests>true</skipTests> -->
<argLine>-Xmx768m -XX:MaxPermSize=256m</argLine>
<argLine>-Xmx768m -XX:MaxMetaspaceSize=256m</argLine>
<systemPropertyVariables>
<java.util.logging.config.file>
${project.build.testOutputDirectory}/logging.properties
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/icatproject/topcat/AdminResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ public void setup() throws Exception {
// Log in as an admin user

String data = "json=" + URLEncoder.encode(
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"root\"}, {\"password\":\"root\"}]}", "UTF8");
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"root\"}, {\"password\":\"pw\"}]}", "UTF8");
String response = httpClient.post("session", new HashMap<String, String>(), data).toString();
adminSessionId = Utils.parseJsonObject(response).getString("sessionId");

// Also log in as a non-admin user

data = "json=" + URLEncoder.encode(
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"nonroot\"}, {\"password\":\"nonroot\"}]}",
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"icatuser\"}, {\"password\":\"icatuserpw\"}]}",
"UTF8");
response = httpClient.post("session", new HashMap<String, String>(), data).toString();
nonAdminSessionId = Utils.parseJsonObject(response).getString("sessionId");
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/icatproject/topcat/IcatClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static void beforeAll() {
public void setup() throws Exception {
HttpClient httpClient = new HttpClient("https://localhost:8181/icat");
String data = "json=" + URLEncoder.encode(
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"root\"}, {\"password\":\"root\"}]}", "UTF8");
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"root\"}, {\"password\":\"pw\"}]}", "UTF8");
String response = httpClient.post("session", new HashMap<String, String>(), data).toString();
sessionId = Utils.parseJsonObject(response).getString("sessionId");

connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/icat", "root", "secret");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/icatdb", "icatdbuser", "icatdbuserpw");
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/icatproject/topcat/UserResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public static void beforeAll() {
public void setup() throws Exception {
HttpClient httpClient = new HttpClient("https://localhost:8181/icat");
String data = "json=" + URLEncoder.encode(
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"root\"}, {\"password\":\"root\"}]}", "UTF8");
"{\"plugin\":\"simple\", \"credentials\":[{\"username\":\"root\"}, {\"password\":\"pw\"}]}", "UTF8");
String response = httpClient.post("session", new HashMap<String, String>(), data).toString();
sessionId = Utils.parseJsonObject(response).getString("sessionId");

connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/icat", "root", "secret");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/icatdb", "icatdbuser", "icatdbuserpw");
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/run.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dummy topcat.properties file for integration tests
facility.list = LILS
facility.LILS.icatUrl = http://localhost:8080
facility.LILS.idsUrl = http://localhost:8080
facility.LILS.icatUrl = https://localhost:8181
facility.LILS.idsUrl = https://localhost:8181
adminUserNames=simple/root
anonUserName=anon/anon

Expand Down
2 changes: 2 additions & 0 deletions tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
faker

0 comments on commit ff347ae

Please sign in to comment.