Skip to content

feat: fix github action for java sdk in centos7 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM centos:7

RUN yum -y update && \
yum install gcc gcc-c++ glibc-static -y

RUN yum -y install wget

RUN yum -y install git

RUN yum -y install python3

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH="/root/.cargo/bin:${PATH}"

RUN yum -y install java-1.8.0-openjdk-devel

RUN wget https://repo.huaweicloud.com/apache/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz && \
tar -xzf apache-maven-*.tar.gz && \
mkdir -p /opt/maven && \
mv apache-maven-* /opt/maven && \
ln -s /opt/maven/apache-maven-3.9.6/bin/mvn /usr/bin/mvn

CMD ["tail", "-f", "/dev/null"]
8 changes: 8 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "kcl",
"dockerFile": "./Dockerfile",
"forwardPorts": [3000, 5000],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},
}
139 changes: 51 additions & 88 deletions .github/workflows/java-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
workflow_dispatch:

jobs:
test:
test-and-build:
permissions:
actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
contents: read # for actions/checkout to fetch code
Expand Down Expand Up @@ -87,104 +87,26 @@ jobs:
name: kcl-lib-${{ matrix.classifier }}
path: |
java/target/classes/native

build-on-centos:
name: Build on CentOS 7

add-centos7-jni:
runs-on: ubuntu-latest
container:
image: "centos:7"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Prepare build environment
run: |
yum makecache
yum install -y wget
yum install -y make
yum install -y epel-release
yum install -y llvm clang llvm-devel
yum install gcc gcc-c++ glibc-static -y
cat /etc/os-release

- name: Install Python 3
run: |
yum install -y python3 python3-devel python3-pip

- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
mv $HOME/.cargo/bin/* /usr/bin/
rustc --version
cargo --version

- name: Install Java and Maven
run: |
yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
wget https://repo.huaweicloud.com/apache/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz
tar -xzf apache-maven-*.tar.gz
mkdir p /opt/maven
mv apache-maven-* /opt/maven
ln -s /opt/maven/apache-maven-3.9.6/bin/mvn /usr/bin/mvn
mvn --version

- name: Verify installed versions
run: |
gcc --version
llvm-config --version
python3 --version
rustc --version
mvn --version
cat /etc/os-release

- name: 'Test'
shell: bash
working-directory: java
run: make test

- name: 'Build and Deploy'
shell: bash
working-directory: java
run: mvn clean package -DskipTests=true -Djni.classifier=linux-x86_64 -Dcargo-build.profile=release

- name: 'Upload artifact'
uses: actions/upload-artifact@v3
with:
name: kcl-lib-linux-x86_64
path: java/target/classes/native


deploy:
runs-on: ubuntu-latest
image: "kcllang/kcl-java-builder-centos7:0.1.0"

permissions:
contents: read
packages: write
if: "startsWith(github.ref, 'refs/tags/')"
needs: [ test, build-on-centos ]
needs: [ test-and-build ]
steps:
- uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
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: Checkout
uses: actions/checkout@v3

- name: Download windows x86_64 lib
uses: actions/download-artifact@v3
with:
name: kcl-lib-windows-x86_64
path: java/native

- name: Download linux x86_64 lib
uses: actions/download-artifact@v3
with:
name: kcl-lib-linux-x86_64
path: java/native

- name: Download linux aarch_64 lib
uses: actions/download-artifact@v3
with:
Expand All @@ -206,19 +128,60 @@ jobs:
- name: Package Java artifact
working-directory: java
run: |
mvn clean package -DskipTests=true
rustup default stable && mvn package -DskipTests=true

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: kcl-lib
path: java/target/*.jar

deploy:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
if: "startsWith(github.ref, 'refs/tags/')"
needs: [ add-centos7-jni ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '8'
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: Download Artifact
uses: actions/download-artifact@v3
with:
name: kcl-lib
path: java/target/

- name: Deploy to Github Packages
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
working-directory: java
run: |
mvn package deploy \
-DskipTests=true \
-DskipCompile=true \
-Dcargo-build.profile=release \
-DserverId=github \
-s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Release to Github Packages
if: "startsWith(github.ref, 'refs/tags/')"
working-directory: java
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an if filter to do the mvn deploy task.

run: |
mvn clean package deploy \
mvn package deploy \
-DskipTests=true \
-DskipCompile=true \
-Dcargo-build.profile=release \
-DserverId=github \
-s $GITHUB_WORKSPACE/settings.xml
Expand Down
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.kcl</groupId>
<artifactId>kcl-lib</artifactId>
<version>0.8.7</version>
<version>0.9.0-SNAPSHOT</version>
<name>KCL Arifact Library for Java</name>
<description>
KCL is an open-source constraint-based record and functional language mainly
Expand Down
Loading