diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7642fdf..2990f84a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,11 @@ --- name: Build -on: [ push, workflow_dispatch ] +on: + push: + branches: + - main + pull_request: {} + workflow_dispatch: {} jobs: build: @@ -8,7 +13,6 @@ jobs: matrix: version: [11, 17] runs-on: ubuntu-latest - concurrency: ci-${{ github.ref }} steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 754fb2b2..b62df623 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,11 +29,17 @@ jobs: passphrase: ${{ secrets.OSSRH_GPG_SECRET_PASS }} - name: Deploy package - run: mvn --batch-mode -Dmaven.test.skip=true -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_PASS }} clean deploy + run: mvn --batch-mode -Dmaven.test.skip=true -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_PASS }} clean package deploy env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + - name: Release to GitHub + uses: softprops/action-gh-release@v1 + with: + files: | + target/hetznercloud-api*.jar + pages: runs-on: ubuntu-latest steps: @@ -47,7 +53,7 @@ jobs: distribution: 'adopt' - name: Generate Javadocs - run: mvn javadoc:javadoc + run: mvn --batch-mode -Dgpg.skip=true javadoc:javadoc - name: Deploy to gh-pages uses: JamesIves/github-pages-deploy-action@v4.3.3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c722d405..b5536b64 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ --- name: Test -on: [ push, workflow_dispatch ] +on: + workflow_dispatch: {} jobs: test: @@ -8,7 +9,6 @@ jobs: matrix: version: [11, 17] runs-on: ubuntu-latest - concurrency: ci-${{ github.ref }} steps: - uses: actions/checkout@v3 diff --git a/src/test/java/me/tomsdevsn/hetznercloud/HetznerCloudAPITest.java b/src/test/java/me/tomsdevsn/hetznercloud/HetznerCloudAPITest.java index 663f2835..48076d7f 100644 --- a/src/test/java/me/tomsdevsn/hetznercloud/HetznerCloudAPITest.java +++ b/src/test/java/me/tomsdevsn/hetznercloud/HetznerCloudAPITest.java @@ -18,18 +18,23 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.web.client.HttpClientErrorException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = App.class) @TestInstance(TestInstance.Lifecycle.PER_CLASS) public class HetznerCloudAPITest { - private static final Logger logger = LoggerFactory.getLogger(HetznerCloudAPITest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(HetznerCloudAPITest.class); private final List cleanupObjects = new ArrayList<>(); + + private final String testIdentifier = new Random().ints(48, 122) + .filter(i -> (i < 57 || i > 65) && (i < 90 || i > 97)) + .mapToObj(i -> (char) i) + .limit(8) + .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append) + .toString(); + @Autowired private HetznerCloudAPI hetznerCloudAPI; @@ -37,7 +42,7 @@ public class HetznerCloudAPITest { public void cleanUp() { cleanupObjects.forEach(cleanupObject -> { Object response = cleanup(cleanupObject); - logger.info("Cleanup " + cleanupObject + " response: " + response); + LOGGER.info("Cleanup " + cleanupObject + " response: " + response); }); } @@ -64,7 +69,6 @@ private Object cleanup(CleanupObject cleanupObject) { @Test void getServers() { - hetznerCloudAPI.getServers(); } @Test @@ -196,9 +200,9 @@ void getISOs() { @Test void getISOById() { - ISOSResponse isos = hetznerCloudAPI.getISOS(); - Long firstIso = isos.getIsos().stream().findFirst().get().getId(); - ISOResponse iso = hetznerCloudAPI.getISOById(firstIso); + ISOResponse iso = hetznerCloudAPI.getISOById( + hetznerCloudAPI.getISOS().getIsos().stream().findFirst().get().getId() + ); Assertions.assertNotNull(iso); Assertions.assertNotNull(iso.getIso()); @@ -505,7 +509,7 @@ void createLoadBalancer() { LoadBalancerResponse loadBalancer = null; NetworkResponse networkResponse = null; try { - String networkName = "testNetwork" + System.currentTimeMillis(); + String networkName = testIdentifier + "-createLoadBalancer"; NetworkRequest.NetworkRequestBuilder networkRequest = NetworkRequest.builder() .ipRange("10.0.0.0/16") .subnets(Collections.singletonList(getDefaultSubnet())) @@ -516,15 +520,15 @@ void createLoadBalancer() { LoadBalancerType loadBalancerType = hetznerCloudAPI.getAllLoadBalancerTypes().getLoadBalancerTypes().get(0); Assertions.assertNotNull(loadBalancerType); - String name = "test" + System.currentTimeMillis(); + String loadBalancerName = testIdentifier + "-createLoadBalancer"; LoadBalancerRequest loadBalancerRequest = LoadBalancerRequest.builder() .networkZone("eu-central") .network(networkResponse.getNetwork().getId()) - .loadBalancerType(loadBalancerType.getId() + "") + .loadBalancerType(loadBalancerType.getId().toString()) .publicInterface(true) .services(Collections.singletonList(getHttpService())) - .targets(Collections.singletonList(getLabelSelector(name))) - .name(name) + .targets(Collections.singletonList(getLabelSelector(loadBalancerName))) + .name(loadBalancerName) .build(); loadBalancer = hetznerCloudAPI.createLoadBalancer(loadBalancerRequest); @@ -655,7 +659,7 @@ void changeProtectionOfLoadBalancer() { void createPlacementGroup() { PlacementGroupResponse placementGroup = null; try { - String name = "test-" + System.currentTimeMillis(); + String name = testIdentifier + "-createPlacementGroup"; PlacementGroupRequest placementGroupRequest = PlacementGroupRequest.builder() .name(name) .type(PlacementGroupType.spread) diff --git a/src/test/java/me/tomsdevsn/hetznercloud/init/App.java b/src/test/java/me/tomsdevsn/hetznercloud/init/App.java index 1a889093..24463a19 100644 --- a/src/test/java/me/tomsdevsn/hetznercloud/init/App.java +++ b/src/test/java/me/tomsdevsn/hetznercloud/init/App.java @@ -9,30 +9,24 @@ import org.springframework.context.annotation.Bean; import java.util.Arrays; +import java.util.stream.Stream; @SpringBootApplication(scanBasePackages = {"me.tomsdevsn.hetznercloud"}) - public class App { public static void main(String[] args) { SpringApplication app = new SpringApplication(App.class); app.addListeners(new ApplicationPidFileWriter()); - ConfigurableApplicationContext context=app.run(args); - + ConfigurableApplicationContext context = app.run(args); } @Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) { return args -> { - System.out.println("Let's inspect the beans provided by Spring Boot:"); - String[] beanNames = ctx.getBeanDefinitionNames(); Arrays.sort(beanNames); - for (String beanName : beanNames) { - System.out.println(beanName); - } - + Stream.of(beanNames).forEach(System.out::println); }; } }