Skip to content

Commit

Permalink
Merge pull request #127 from noleme/fix/github-flow
Browse files Browse the repository at this point in the history
fix: github workflow
  • Loading branch information
eledhwen authored Dec 26, 2024
2 parents 0d20f14 + 66e5ad9 commit 1a5f709
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 162 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@ on:
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'java' ]
os: [ ubuntu-latest ]
java: [ 21 ]
fail-fast: false

runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3

uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -43,7 +48,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -56,6 +61,6 @@ jobs:
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
9 changes: 5 additions & 4 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, macOS-latest ]
java: [ 11, 15 ]
java: [ 11, 17, 21 ]
fail-fast: false

runs-on: ${{ matrix.os }}
timeout-minutes: 120

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Upload surefire artifact
uses: actions/upload-artifact@v2-preview
uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ matrix.os }}-surefire
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/maven-checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Maven Checkstyle

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]

jobs:
build:
strategy:
matrix:
os: [ ubuntu-latest ]
java: [ 21 ]
fail-fast: false

runs-on: ${{ matrix.os }}
timeout-minutes: 30

steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: v0.17.2
- name: Checkstyle with Maven
run: mvn clean checkstyle:check --fail-never
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cat target/checkstyle-result.xml | reviewdog -f=checkstyle -reporter=github-pr-review -runners=golint,govet
15 changes: 9 additions & 6 deletions .github/workflows/maven-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
java: [ 15 ]
java: [ 21 ]
fail-fast: false

runs-on: ${{ matrix.os }}
timeout-minutes: 120
timeout-minutes: 30

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
- name: Test with Maven
run: mvn clean -B test --file pom.xml
- uses: codecov/codecov-action@v2
run: mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test jacoco:report
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
17 changes: 5 additions & 12 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name: Maven Publish

name: Publish package to the Maven Central Repository
on:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
server-id: ossrh
distribution: 'temurin'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- id: install-secret-key
Expand All @@ -23,12 +21,7 @@ jobs:
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
gpg --list-secret-keys --keyid-format LONG
- name: Publish package
run: |
mvn \
--no-transfer-progress \
--batch-mode \
-Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} \
clean deploy
run: mvn --batch-mode clean deploy
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<maven-gpg.version>3.2.4</maven-gpg.version>
<slf4j.version>1.7.36</slf4j.version>
<junit.version>5.10.3</junit.version>
<junit.system-stubs.version>2.1.7</junit.system-stubs.version>
<jacoco.version>0.8.12</jacoco.version>
<noleme-commons.version>0.17.1</noleme-commons.version>
<noleme-json.version>0.10</noleme-json.version>
Expand Down Expand Up @@ -88,6 +89,13 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>uk.org.webcompere</groupId>
<artifactId>system-stubs-jupiter</artifactId>
<version>${junit.system-stubs.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<issueManagement>
Expand Down
106 changes: 26 additions & 80 deletions src/test/java/com/noleme/vault/factory/EnvTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.noleme.vault.factory;

import com.noleme.vault.container.Cellar;
import com.noleme.vault.exception.VaultException;
import com.noleme.vault.exception.VaultInjectionException;
import com.noleme.vault.service.BooleanProvider;
import com.noleme.vault.service.DoubleProvider;
import com.noleme.vault.service.IntegerProvider;
import com.noleme.vault.service.StringProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.Map;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;

/**
* @author Pierre Lecerf (plecerf@lumiomedical.com)
Expand All @@ -22,19 +18,12 @@ public class EnvTest
{
private static final VaultFactory factory = new VaultFactory();

@BeforeEach
void setup()
{
clearEnv();
}

@Test
void envVariables_shouldBeInterpreted() throws VaultException
void envVariables_shouldBeInterpreted() throws Exception
{
setEnv("MY_VAR", "some interesting value");
setEnv("MY_OTHER_VAR", "some uninteresting value");

var cellar = factory.populate(new Cellar(), "com/noleme/vault/parser/simple_variable.yml");
var cellar = new EnvironmentVariables("MY_VAR", "some interesting value")
.and("MY_OTHER_VAR", "some uninteresting value")
.execute(() -> factory.populate(new Cellar(), "com/noleme/vault/parser/simple_variable.yml"));

Assertions.assertEquals("MY_VAR", cellar.getVariable("my_varname"));
Assertions.assertEquals("some interesting value", cellar.getVariable("my_ref"));
Expand All @@ -47,25 +36,23 @@ void envVariables_shouldBeInterpreted() throws VaultException
}

@Test
void envVariables_absentShouldBeNull() throws VaultException
void envVariables_absentShouldBeNull() throws Exception
{
setEnv("MY_VAR", "some interesting value");

var cellar = factory.populate(new Cellar(), "com/noleme/vault/parser/simple_variable.yml");
var cellar = new EnvironmentVariables("MY_VAR", "some interesting value")
.execute(() -> factory.populate(new Cellar(), "com/noleme/vault/parser/simple_variable.yml"));

Assertions.assertEquals("some interesting value", ((StringProvider)cellar.getService("provider.string.1")).provide());
Assertions.assertNull(((StringProvider)cellar.getService("provider.string.2")).provide());
}

@Test
void envVariables_shouldBeConvertible() throws VaultException
void envVariables_shouldBeConvertible() throws Exception
{
setEnv("MY_STRING", "custom_value");
setEnv("MY_INTEGER", "2345");
setEnv("MY_DOUBLE", "23.45");
setEnv("MY_BOOLEAN", "true");

var cellar = factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml");
var cellar = new EnvironmentVariables("MY_STRING", "custom_value")
.and("MY_INTEGER", "2345")
.and("MY_DOUBLE", "23.45")
.and("MY_BOOLEAN", "true")
.execute(() -> factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml"));

Assertions.assertEquals("custom_value", cellar.getVariable("my_string_env"));
Assertions.assertEquals(2345, cellar.getVariable("my_integer_env", int.class));
Expand All @@ -74,7 +61,7 @@ void envVariables_shouldBeConvertible() throws VaultException
}

@Test
void envVariablesWithDefaultValues_shouldBeInterpreted() throws VaultException
void envVariablesWithDefaultValues_shouldBeInterpreted() throws Exception
{
var noEnvCellar = factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml");

Expand All @@ -87,12 +74,11 @@ void envVariablesWithDefaultValues_shouldBeInterpreted() throws VaultException
Assertions.assertEquals("12.34", noEnvCellar.getVariable("my_double_defval_alt_env"));
Assertions.assertEquals("false", noEnvCellar.getVariable("my_boolean_defval_alt_env"));

setEnv("MY_STRING", "custom_value");
setEnv("MY_INTEGER", "2345");
setEnv("MY_DOUBLE", "23.45");
setEnv("MY_BOOLEAN", "true");

var cellar = factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml");
var cellar = new EnvironmentVariables("MY_STRING", "custom_value")
.and("MY_INTEGER", "2345")
.and("MY_DOUBLE", "23.45")
.and("MY_BOOLEAN", "true")
.execute(() -> factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml"));

Assertions.assertEquals("custom_value", cellar.getVariable("my_string_defval_env"));
Assertions.assertEquals("2345", cellar.getVariable("my_integer_defval_env"));
Expand All @@ -105,7 +91,7 @@ void envVariablesWithDefaultValues_shouldBeInterpreted() throws VaultException
}

@Test
void envVariablesWithDefaultValues_shouldBeConvertible() throws VaultException
void envVariablesWithDefaultValues_shouldBeConvertible() throws Exception
{
var noEnvCellar = factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml");

Expand All @@ -118,12 +104,11 @@ void envVariablesWithDefaultValues_shouldBeConvertible() throws VaultException
Assertions.assertEquals(12.34, noEnvCellar.getVariable("my_double_defval_alt_env", double.class));
Assertions.assertEquals(false, noEnvCellar.getVariable("my_boolean_defval_alt_env", boolean.class));

setEnv("MY_STRING", "custom_value");
setEnv("MY_INTEGER", "2345");
setEnv("MY_DOUBLE", "23.45");
setEnv("MY_BOOLEAN", "true");

var cellar = factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml");
var cellar = new EnvironmentVariables("MY_STRING", "custom_value")
.and("MY_INTEGER", "2345")
.and("MY_DOUBLE", "23.45")
.and("MY_BOOLEAN", "true")
.execute(() -> factory.populate(new Cellar(), "com/noleme/vault/parser/variable/env_variable.yml"));

Assertions.assertEquals("custom_value", cellar.getVariable("my_string_defval_env"));
Assertions.assertEquals(2345, cellar.getVariable("my_integer_defval_env", int.class));
Expand All @@ -145,43 +130,4 @@ void servicesInstantiation_shouldLeverageConvertion() throws VaultInjectionExcep
Assertions.assertEquals(12.34, cellar.getService("my_provider.double", DoubleProvider.class).provide());
Assertions.assertEquals(false, cellar.getService("my_provider.boolean", BooleanProvider.class).provide());
}

/**
* Nasty hack for altering the env variable snapshot ; does not impact the actual env environment, only its in-memory representation.
* This produces a warning for illegal reflective access, should not be an issue in this context.
*
* @param name
* @param value
*/
@SuppressWarnings("unchecked")
public static void setEnv(String name, String value)
{
try {
Map<String, String> env = System.getenv();
Field field = env.getClass().getDeclaredField("m");
field.setAccessible(true);
((Map<String, String>) field.get(env)).put(name, value);
}
catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e.getMessage(), e);
}
}

/**
* Nasty hack for altering the env variable snapshot ; does not impact the actual env environment, only its in-memory representation.
* This produces a warning for illegal reflective access, should not be an issue in this context.
*/
@SuppressWarnings("unchecked")
public static void clearEnv()
{
try {
Map<String, String> env = System.getenv();
Field field = env.getClass().getDeclaredField("m");
field.setAccessible(true);
((Map<String, String>) field.get(env)).clear();
}
catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
Loading

0 comments on commit 1a5f709

Please sign in to comment.