From dc6de91b0eecbf70c0e7d031707079838f502c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C5=BEe=20Jen=C5=A1terle?= Date: Fri, 21 Feb 2025 17:29:22 +0100 Subject: [PATCH] Implement GitHub Actions CI --- .github/workflows/maven-publish.yml | 34 +++++ .github/workflows/maven.yml | 39 +++++ pom.xml | 137 ++++++++++-------- .../barcode/test/DynamicContentCoderTest.java | 39 +++-- 4 files changed, 165 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/maven-publish.yml create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 0000000..0fe7dc2 --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,34 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + +name: Maven Package + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 18 + uses: actions/setup-java@v4 + with: + java-version: '18' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..5b618c9 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,39 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 18 + uses: actions/setup-java@v4 + with: + java-version: '18' + distribution: 'temurin' + cache: maven + - name: Build and test with Maven + run: mvn -B package --file pom.xml + - run: mkdir staging && cp target/*.jar staging + - uses: actions/upload-artifact@v4 + with: + name: Package + path: staging + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + # - name: Update dependency graph + # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 diff --git a/pom.xml b/pom.xml index 3d6b3a7..9acfe18 100644 --- a/pom.xml +++ b/pom.xml @@ -1,31 +1,33 @@ - + 4.0.0 - org.uic.barcode - org.uic.barcode - 1.4.12 + org.uic + barcode + 1.4.13 jar - UIC barcode + UIC Barcode Encoding and decoding of Aztec barcode content according to UIC IRS 90918-9 - - UTF-8 - + + UTF-8 + - - - - junit - junit - 4.13.2 - test - - - org.bouncycastle - bcprov-jdk18on - 1.80 - test - - + + + + junit + junit + 4.13.2 + test + + + org.bouncycastle + bcprov-jdk18on + 1.80 + test + + src/main/java @@ -43,50 +45,57 @@ org.apache.maven.plugins maven-compiler-plugin 2.3.2 - - 1.8 - 1.8 - + + 1.8 + 1.8 + - org.apache.maven.plugins - maven-source-plugin - 3.2.0 - - - attach-sources - - jar - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - en_gb - ${project.build.directory}/site - false - - + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-site-plugin + 3.7.1 + + en_gb + ${project.build.directory}/site + false + + - + - - + + + + github + GitHub UIC Apache Maven Packages + https://maven.pkg.github.com/UnionInternationalCheminsdeFer/UIC-barcode + + + - - The Apache Software License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - repo - + + The Apache Software License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + repo + - + \ No newline at end of file diff --git a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java index 1fb8bb9..6fdaf2a 100644 --- a/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java +++ b/src/test/java/org/uic/barcode/test/DynamicContentCoderTest.java @@ -2,6 +2,8 @@ import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Date; + import org.junit.Before; import org.junit.Test; import org.uic.barcode.asn1.uper.UperEncoder; @@ -47,13 +49,10 @@ public class DynamicContentCoderTest { g.setLongitude( 12345L); g.setLatitude( 56789L); content.setGeoCoordinate(g); - - try { - //needs to be before 28.2. to keep the test stable in year with febuary 29. - content.setTimeStamp(new SimpleDateFormat( "yyyy.MM.dd-HH:mm" ).parse( "2021.02.04-12:30" )); - } catch (ParseException e2) { - // - } + + //needs to be before 28.2. to keep the test stable in year with febuary 29. + Date date = new Date(1612438200000L); + content.setTimeStamp(date); } @@ -79,39 +78,39 @@ public class DynamicContentCoderTest { String encoding = "7C170F0E1262089437000230390300DDD504017A20C6D0C2D8D8CADCCECA40E6E8E4D2DCCE2F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA05E1A37EECA0507B409C30F3E60509B42F8F461D9B32EECF96FE5F1D32EEE7A77EEBFA72310282DA"; - IUicDynamicContent content = DynamicContentCoder.decode(UperEncoder.bytesFromHexString(encoding)); + IUicDynamicContent testContent = DynamicContentCoder.decode(UperEncoder.bytesFromHexString(encoding)); - assert("appID".equals(content.getAppId())); + assert("appID".equals(testContent.getAppId())); - assert("challenge string".equals(content.getChallengeString())); + assert("challenge string".equals(testContent.getChallengeString())); - IExtension e1 = content.getExtension(); + IExtension e1 = testContent.getExtension(); assert(UperEncoder.hexStringFromBytes(e1.getBinarydata()).equals("82DA")); assert(e1.getId().equals("challenge_extension_id1")); - assert(content.getChallengeString().equals("challenge string")); + assert(testContent.getChallengeString().equals("challenge string")); byte[] ce = null; - for (IExtension e : content.getDynamicContentResponseList()) { + for (IExtension e : testContent.getDynamicContentResponseList()) { if (e.getId().equals("challenge_extension_id1")) { ce = e.getBinarydata(); } } assert(UperEncoder.hexStringFromBytes(ce).equals("82DA")); - assert(UperEncoder.hexStringFromBytes(content.getPhoneIdHash()).equals("83DA")); + assert(UperEncoder.hexStringFromBytes(testContent.getPhoneIdHash()).equals("83DA")); - assert(UperEncoder.hexStringFromBytes(content.getPassIdHash()).equals("84DA")); + assert(UperEncoder.hexStringFromBytes(testContent.getPassIdHash()).equals("84DA")); - assert(content.getGeoCoordinate() != null); - assert(content.getGeoCoordinate().getLongitude() == 12345L); - assert(content.getGeoCoordinate().getLatitude() == 56789L); + assert(testContent.getGeoCoordinate() != null); + assert(testContent.getGeoCoordinate().getLongitude() == 12345L); + assert(testContent.getGeoCoordinate().getLatitude() == 56789L); - assert(content.getTimeStamp() != null); + assert(testContent.getTimeStamp() != null); - assert(content.getTimeStamp().toString().contains("04 12:30:00 CET")); + assert(testContent.getTimeStamp().getTime() == 1738668600000L); }