Skip to content

Commit

Permalink
chore:💚 Github actions (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
heliannuuthus authored Mar 11, 2024
1 parent e34b555 commit 67c50d4
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 121 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/gradle-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- master

jobs:
lint:
if: github.event.pull_request.merged == false
uses: heliannuuthus/integration-deploy/.github/workflows/call-gradle-lint.yml@master

build:
needs: lint
uses: heliannuuthus/integration-deploy/.github/workflows/call-gradle-build.yml@master

publish:
if: github.event.pull_request.merged == true
needs: build
permissions:
contents: read
packages: write
uses: heliannuuthus/integration-deploy/.github/workflows/call-gradle-publish.yml@master
with:
user: ${{ github.actor }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
27 changes: 10 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ plugins {
id "io.spring.dependency-management" version "1.1.4"
id "org.springdoc.openapi-gradle-plugin" version "1.8.0"
id "io.freefair.lombok" version "8.6"
id 'me.qoomon.git-versioning' version '6.4.2'
id "com.diffplug.spotless" version "6.25.0"
}

apply from: "https://cdn.jsdelivr.net/gh/heliannuuthus/integration-deploy/gradle/multi-library.gradle"


ext {
openapiVersion = "2.3.0"
apolloClientVersion = "2.2.0"
}

allprojects {

allprojects {
repositories {
maven { url "https://maven.aliyun.com/repository/public" }
maven { url "https://maven.aliyun.com/repository/spring/" }
Expand All @@ -22,27 +26,16 @@ allprojects {

}

subprojects {
apply plugin: "java-library"
allprojects {
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"
apply plugin: "io.freefair.lombok"


jar {
enabled = true
bootJar {
enabled = false
}

configurations {
all*.exclude module: "spring-boot-starter-logging"
jar {
enabled = true
}
}

dependencies {
testImplementation platform("org.junit:junit-bom:5.9.1")
testImplementation "org.junit.jupiter:junit-jupiter"
}

test {
useJUnitPlatform()
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
groups=ghrc.io
version=0.1.0
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
package io.ghcr.heliannuuthus;

import com.ctrip.framework.apollo.core.ApolloClientSystemConsts;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;

import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Optional;

@Slf4j
public class ApolloMetaServerInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {
public static final int ORDER = -1;
private static final String SCHEMA = "config";
private static final String SPRING_APPLICATION_NAME_KEY = "spring.application.name";
private static final String SPRING_PROFILES_ACTIVE_KEY = "spring.profiles.active";
private static final String DEFAULT_META_SERVER = "http://{0}.heliannuuthus.com";
private static final String DEFAULT_ENV = "dev";
private static final String PROD_ENV = "prod";
public class ApolloMetaServerInitializer
implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {
public static final int ORDER = -1;
private static final String SCHEMA = "config";
private static final String SPRING_APPLICATION_NAME_KEY = "spring.application.name";
private static final String SPRING_PROFILES_ACTIVE_KEY = "spring.profiles.active";
private static final String DEFAULT_META_SERVER = "http://{0}.heliannuuthus.com";
private static final String DEFAULT_ENV = "dev";
private static final String PROD_ENV = "prod";

private static final String MIDDLE_LINE = "-";
private static final String MIDDLE_LINE = "-";

@Override
public int getOrder() {
return ORDER;
}
@Override
public int getOrder() {
return ORDER;
}

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
Optional.ofNullable(environment.getProperty(SPRING_APPLICATION_NAME_KEY)).ifPresent(applicationName -> System.setProperty(ApolloClientSystemConsts.APP_ID, applicationName));
String env = Optional.of(environment.getActiveProfiles()).flatMap(profiles -> Arrays.stream(profiles).findFirst()).orElse(DEFAULT_ENV);
System.setProperty("env", env);
System.setProperty(ApolloClientSystemConsts.APOLLO_META, MessageFormat.format(DEFAULT_META_SERVER, PROD_ENV.equals(env) ? SCHEMA : SCHEMA + MIDDLE_LINE + env));
}
}
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
Optional.ofNullable(environment.getProperty(SPRING_APPLICATION_NAME_KEY))
.ifPresent(
applicationName ->
System.setProperty(ApolloClientSystemConsts.APP_ID, applicationName));
String env =
Optional.of(environment.getActiveProfiles())
.flatMap(profiles -> Arrays.stream(profiles).findFirst())
.orElse(DEFAULT_ENV);
System.setProperty("env", env);
System.setProperty(
ApolloClientSystemConsts.APOLLO_META,
MessageFormat.format(
DEFAULT_META_SERVER, PROD_ENV.equals(env) ? SCHEMA : SCHEMA + MIDDLE_LINE + env));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,53 +1,44 @@
package io.ghcr.heliannuuthus;


import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Slf4j
@Configuration
public class OpenapiConfiguration {

@Value("${spring.application.name}")
private String application;

@Value("${server.port}")
private String port;

@Value("${server.address:localhost}")
private String serverAddress;

private License license() {
return new License()
.name("MIT")
.url("https://opensource.org/licenses/MIT");
}

private Info info() {
return new Info()
.title(application)
.version("v1.0.0")
.license(license());
}

private ExternalDocumentation externalDocumentation() {
return new ExternalDocumentation()
.description("heliannuuthus")
.url("https://heliannuuthus.github.io/");
}

@Bean
public OpenAPI springShopOpenAPI() {
log.info("openapi: http://{}:{}/redoc.html", serverAddress, port);
return new OpenAPI()
.info(info())
.externalDocs(externalDocumentation());
}
}
package io.ghcr.heliannuuthus;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class OpenapiConfiguration {

@Value("${spring.application.name}")
private String application;

@Value("${server.port}")
private String port;

@Value("${server.address:localhost}")
private String serverAddress;

private License license() {
return new License().name("MIT").url("https://opensource.org/licenses/MIT");
}

private Info info() {
return new Info().title(application).version("v1.0.0").license(license());
}

private ExternalDocumentation externalDocumentation() {
return new ExternalDocumentation()
.description("heliannuuthus")
.url("https://heliannuuthus.github.io/");
}

@Bean
public OpenAPI springShopOpenAPI() {
log.info("openapi: http://{}:{}/redoc.html", serverAddress, port);
return new OpenAPI().info(info()).externalDocs(externalDocumentation());
}
}

0 comments on commit 67c50d4

Please sign in to comment.