Skip to content

Commit

Permalink
Create CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Jul 19, 2023
1 parent e049cb4 commit 110afbe
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Java CI with Gradle

on:
push:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
strategy:
matrix:
java-version: [ '17', '18', '19', '20', '21' ]

runs-on: ubuntu-latest

steps:
- name: Checkout project
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

# Gradle java toolchain cannot find early release images, need to preload until GA is available
- name: Preload JDK 21
if: ${{ matrix.java-version == '21' }}
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
java-version: '21-ea'
distribution: 'temurin'

- name: Set up JDK 11
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
java-version: '11'
distribution: 'temurin'
cache: gradle

- name: Build application
run: |
./gradlew io.openliberty.java.internal_fat_${{ matrix.java-version }}:build
- name: Verify application
run: |
./.github/workflows/scripts/verifyArtifact.sh ${{ matrix.java-version }}
- name: Upload application
uses: actions/upload-artifact@013d2b89baa2f354c5ffec54c68bec4ab39a2534 #v3.1.2
with:
name: Applications
path: io.openliberty.java.internal_fat_${{ matrix.java-version }}/build/libs/io.openliberty.java.internal_fat_${{ matrix.java-version }}.war
if-no-files-found: error
63 changes: 63 additions & 0 deletions .github/workflows/scripts/ClassVersionChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.io.*;
import java.util.*;

public class ClassVersionChecker {

private static final HashMap<String, Integer> majorCodeMap = new HashMap<>();

public static void main(String[] args) throws IOException {
if (args.length != 2) {
throw new RuntimeException("Expected exactly 2 arguments");
}

//Adapted from https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.1
majorCodeMap.put("1.0.2", 45);
majorCodeMap.put("1.1", 45);
majorCodeMap.put("1.2", 46);
majorCodeMap.put("1.3", 47);
majorCodeMap.put("1.4", 48);
majorCodeMap.put("5.0", 49);
majorCodeMap.put("6", 50);
majorCodeMap.put("7", 51);
majorCodeMap.put("8", 52);
majorCodeMap.put("9", 53);
majorCodeMap.put("10", 54);
majorCodeMap.put("11", 55);
majorCodeMap.put("12", 56);
majorCodeMap.put("13", 57);
majorCodeMap.put("14", 58);
majorCodeMap.put("15", 59);
majorCodeMap.put("16", 60);
majorCodeMap.put("17", 61);
majorCodeMap.put("18", 62);
majorCodeMap.put("19", 63);
majorCodeMap.put("20", 64);
majorCodeMap.put("21", 65);

String filename = args[0];
int expected = majorCodeMap.get(args[1]);

checkClassVersion(filename, expected);
}

private static void checkClassVersion(String filename, int expected) throws IOException {
try ( DataInputStream in = new DataInputStream(new FileInputStream(filename)) ) {
int magic = in.readInt();

if(magic != 0xcafebabe) {
System.out.println(filename + " is not a valid class!");
}

int minor = in.readUnsignedShort();
int major = in.readUnsignedShort();

System.out.println("Major version: " + major);
System.out.println("Minor version: " + minor);

if(expected != major) {
System.out.println("Expected major version of " + expected + " but got " + major);
System.exit(1); //Failing execution
}
}
}
}
18 changes: 18 additions & 0 deletions .github/workflows/scripts/verifyArtifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ $# -ne 1 ]; then
echo "Exactly one argument is required"
exit 0
fi

JAVA_VERSION=$1
SUB_PROJECT=$PWD/io.openliberty.java.internal_fat_$JAVA_VERSION
TEST_CLASS=$SUB_PROJECT/build/classes/java/main/io/openliberty/java/internal/TestApp.class


echo "Checking class"
SCRIPTS=$PWD/.github/workflows/scripts/
pushd $SCRIPTS &> /dev/null
java ClassVersionChecker.java $TEST_CLASS $JAVA_VERSION
popd &> /dev/null
echo "--------------------"
Empty file modified gradlew
100644 → 100755
Empty file.

0 comments on commit 110afbe

Please sign in to comment.