Skip to content

Commit

Permalink
Merge Flyfly & EdgeChain (#164)
Browse files Browse the repository at this point in the history
* Merge FlyFly & EdgeChains

* Update BuildAndRun.yml
  • Loading branch information
EmadHanif01 authored Jul 27, 2023
1 parent 8b581b0 commit dd8ff59
Show file tree
Hide file tree
Showing 23 changed files with 1,027 additions and 126 deletions.
79 changes: 38 additions & 41 deletions .github/workflows/BuildAndRun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set SHORT_HASH
run: |
echo "::set-output name=VALUE::${LONG_HASH:0:8}"
echo "RELEASE_TAG=${LONG_HASH:0:8}-$(TZ=UTC-8 date +"%Y.%m.%d")" >> $GITHUB_ENV
echo "::set-output name=VALUE::${LONG_HASH:0:8}"
echo "RELEASE_TAG=${LONG_HASH:0:8}-$(TZ=UTC-8 date +"%Y.%m.%d")" >> $GITHUB_ENV
id: short_hash
env:
LONG_HASH: ${{ github.sha }}
LONG_HASH: ${{ github.sha }}

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'

- name: Set up Maven
uses: stCarolas/[email protected]
with:
Expand All @@ -33,34 +33,31 @@ jobs:
- name: Create output folder
run: mkdir BuildOutput

# - name: Build flyfly project
# working-directory: ./FlySpring/flyfly
# run: mvn clean package

- name: Build flyfly project
working-directory: ./FlySpring/flyfly
run: mvn clean package



- name: Copy flyfly JAR to Examples folder and rename
run: cp ./FlySpring/flyfly/target/flyfly-0.0.1-SNAPSHOT.jar ././BuildOutput/flyfly.jar
# - name: Copy flyfly JAR to Examples folder and rename
# run: cp ./FlySpring/flyfly/target/flyfly-0.0.1-SNAPSHOT.jar ././BuildOutput/flyfly.jar

- name: Build edgechain-app project
working-directory: ./FlySpring/edgechain-app
# run: mvn -Djavacpp.platform=linux-x86_64 clean package -DskipTests
# run: mvn -Djavacpp.platform=linux-x86_64 clean package -DskipTests
run: mvn clean package -DskipTests

- name: Run edgechain testcases
working-directory: ./FlySpring/edgechain-app
run: mvn test

- name: Copy edgechain-app JAR to Examples folder
run: cp ./FlySpring/edgechain-app/target/edgechain-app-1.0.0.jar ./BuildOutput/
run: cp ./FlySpring/edgechain-app/target/edgechain.jar ./BuildOutput/

- name: Upload Examples folder as artifact
uses: actions/upload-artifact@v3
with:
name: Output
path: ./BuildOutput/

release:
name: Release jar
needs: build_and_run
Expand All @@ -75,35 +72,35 @@ jobs:
- name: Display structure of downloaded files
run: ls -R

# - name: Create Release
# id: create_release
# uses: actions/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ github.ref }}
# release_name: ${{ github.ref }}
# - name: Upload Release jar
# id: upload_release_asset
# uses: actions/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: Examples/
# asset_name: Examples
# asset_content_type: application/zip
# - name: Create Release
# id: create_release
# uses: actions/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ github.ref }}
# release_name: ${{ github.ref }}
# - name: Upload Release jar
# id: upload_release_asset
# uses: actions/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: Examples/
# asset_name: Examples
# asset_content_type: application/zip
- name: 'Get variables'
id: vars
run: |
echo "tag_name= ${{needs.build_and_run.outputs.VALUE}}" >> $GITHUB_OUTPUT
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.RELEASE_TAG }}
# body: 🚀 Automated build
files: |
./Output/**/*.*
# tag_name: ${{needs.build_and_run.steps.short_hash.outputs.VALUE}}
tag_name: ${{ env.RELEASE_TAG }}
# body: 🚀 Automated build
files: |
./Output/**/*.*
# tag_name: ${{needs.build_and_run.steps.short_hash.outputs.VALUE}}
1 change: 1 addition & 0 deletions FlySpring/edgechain-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ build/

### VS Code ###
.vscode/
/src/main/resources/jbang.jar
104 changes: 81 additions & 23 deletions FlySpring/edgechain-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<packaging>jar</packaging>
<properties>
<java.version>17</java.version>
<spring-cloud.version>2022.0.3</spring-cloud.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
Expand All @@ -36,6 +35,12 @@
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
Expand Down Expand Up @@ -78,18 +83,6 @@
<version>2.3.1</version>
</dependency>

<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>5.0.1</version>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>


<dependency>
<groupId>com.squareup.retrofit2</groupId>
Expand Down Expand Up @@ -241,6 +234,35 @@
<version>0.4.2</version>
</dependency>

<!-- flyfly -->
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli-spring-boot-starter</artifactId>
<version>4.7.0</version>
</dependency>

<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>2.11.3</version>
</dependency>

<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
<version>1.12</version>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.17.6</version>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -263,13 +285,6 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>

</dependencyManagement>
Expand Down Expand Up @@ -314,6 +329,7 @@
<goal>shade</goal>
</goals>
<configuration>
<finalName>edgechain</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
Expand All @@ -326,14 +342,56 @@
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
<!-- <mainClass></mainClass>-->
<!-- </transformer>-->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.edgechain.EdgeChainApplication</mainClass>
</transformer>
</transformers>

</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>download-and-unpack-jbang</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Download Jbang archive -->
<get src="https://github.com/jbangdev/jbang/releases/download/v0.109.0/jbang.zip"
dest="${project.build.directory}/jbang.zip"
skipexisting="true" />

<!-- Unpack Jbang archive -->
<unzip src="${project.build.directory}/jbang.zip"
dest="${project.build.directory}/jbang" />

<!-- Copy only the 'jbang.jar' file to the 'src/main/resources' directory -->
<copy
file="${project.build.directory}/jbang/jbang/bin/jbang.jar"
tofile="${project.basedir}/src/main/resources/jbang.jar" />

<!-- Remove the temporary Jbang folder -->
<delete includeemptydirs="true">
<fileset dir="${project.build.directory}">
<include name="jbang/**" />
</fileset>
</delete>
</target>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.edgechain;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;

import java.net.URL;
import java.nio.file.Paths;

@SpringBootApplication
public class EdgeChainApplication {

private static final Logger logger = LoggerFactory.getLogger(EdgeChainApplication.class);

public static void main(String[] args) {

System.setProperty("jar.name", getJarFileName(EdgeChainApplication.class));

logger.info("Executed jar file: "+System.getProperty("jar.name"));

SpringApplication springApplication =
new SpringApplicationBuilder()
.sources(EdgeChainApplication.class).web(WebApplicationType.NONE)
.build();

springApplication.run(args);
}

@Bean(name = "mvcHandlerMappingIntrospector")
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
return new HandlerMappingIntrospector();
}

private static String getJarFileName(Class<?> clazz) {
URL classResource = clazz.getResource(clazz.getSimpleName() + ".class");
if (classResource == null) {
throw new RuntimeException("class resource is null");
}
String url = classResource.toString();
if (url.startsWith("jar:file:")) {
String path = url.replaceAll("^jar:(file:.*[.]jar)!/.*", "$1");
try {
return Paths.get(new URL(path).toURI()).toString();
} catch (Exception e) {
throw new RuntimeException("Invalid jar file");
}
}
throw new RuntimeException("Invalid jar file");
}
}
Loading

0 comments on commit dd8ff59

Please sign in to comment.