Skip to content
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

Replace travis ci with github action #1212

Merged
merged 24 commits into from
Jan 3, 2021
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
31 changes: 0 additions & 31 deletions .github/workflows/gradle.yml

This file was deleted.

182 changes: 182 additions & 0 deletions .github/workflows/halo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: Halo CI

on:
pull_request:
paths:
- '**'
- '!**.md'
push:
branches:
- '**'
paths:
- '**'
- '!**.md'
release:
types: # This configuration does not affect the page_build event above
- created

jobs:
check:
runs-on: ubuntu-latest
# Default steps
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Cache Gradle wrapper
id: cache-gradle-wrapper
uses: actions/[email protected]
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-dependencies-

- name: Cache Dependencies
id: cache-dependencies
uses: actions/[email protected]
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-dependencies-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-dependencies-

- name: Check And Test
run: ./gradlew check
build:
runs-on: ubuntu-latest
needs: check
if: github.event_name == 'release'
# Default steps
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache Gradle wrapper
id: cache-gradle-wrapper
uses: actions/[email protected]
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-dependencies-
- name: Cache Dependencies
id: cache-dependencies
uses: actions/[email protected]
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-dependencies-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-dependencies-

- name: Build with Gradle
run: ./gradlew clean build -x test

- name: Archive halo jar
uses: actions/upload-artifact@v2
with:
name: halo-jar
path: build/libs
retention-days: 1
github-release:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release'
steps:
- name: Download halo jar
uses: actions/download-artifact@v2
with:
name: halo-jar
path: build/libs
- name: Get Name of Artifact
id: get_artifact
run: |
ARTIFACT_PATHNAME=$(ls build/libs/*.jar | head -n 1)
ARTIFACT_NAME=$(basename ${ARTIFACT_PATHNAME})
echo "Artifact pathname: ${ARTIFACT_PATHNAME}"
echo "Artifact name: ${ARTIFACT_NAME}"
echo "ARTIFACT_PATHNAME=${ARTIFACT_PATHNAME}" >> $GITHUB_ENV
echo "ARTIFACT_NAME=${ARTIFACT_NAME}" >> $GITHUB_ENV
echo "RELEASE_ID=${{ github.event.release.id }}" >> $GITHUB_ENV
- name: Upload a Release Asset
uses: actions/github-script@v2
if: github.event_name == 'release'
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log('environment', process.versions);

const fs = require('fs').promises;

const { repo: { owner, repo }, sha } = context;
console.log({ owner, repo, sha });

const releaseId = process.env.RELEASE_ID
const artifactPathName = process.env.ARTIFACT_PATHNAME
const artifactName = process.env.ARTIFACT_NAME
console.log('Releasing', releaseId, artifactPathName, artifactName)

await github.repos.uploadReleaseAsset({
owner, repo,
release_id: releaseId,
name: artifactName,
data: await fs.readFile(artifactPathName)
});
docker-release:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Download halo jar
uses: actions/download-artifact@v2
with:
name: halo-jar
path: build/libs
- name: Cache Gradle wrapper
id: cache-gradle-wrapper
uses: actions/[email protected]
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-dependencies-
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build docker image
run: |
docker info
docker images
export DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}
export DOCKER_TOKEN=${{ secrets.DOCKER_TOKEN }}
export DOCKER_IMAGE_NAME=${{ secrets.DOCKER_IMAGE_NAME }}
export TAG_LATEST=false
echo "Building and pushing with version tag."
./gradlew bootBuildImage -x bootJar --publishImage
PRE_RELEASE=${{ github.event.release.prerelease }}
if ! $PRE_RELEASE
then
echo "Building and pushing with latest tag."
export TAG_LATEST=true
./gradlew bootBuildImage -x bootJar --publishImage
else
echo "Skipped building and pushing with latest tag due to pre-release."
fi
docker images
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
FROM adoptopenjdk/openjdk11-openj9
VOLUME /tmp

ARG JAR_FILE=build/libs/halo.jar
ARG PORT=8090
ARG JAR_FILE=build/libs/*.jar
ARG TIME_ZONE=Asia/Shanghai

ENV TZ=${TIME_ZONE}
ENV JVM_XMS="256m"
ENV JVM_XMX="256m"
ENV JVM_XMS="256m" \
JVM_XMX="256m" \
JVM_OPTS="" \
TZ=${TIME_ZONE}


COPY ${JAR_FILE} halo.jar

EXPOSE ${PORT}
EXPOSE 8090

ENTRYPOINT java -Xms${JVM_XMS} -Xmx${JVM_XMX} -Djava.security.egd=file:/dev/./urandom -server -jar halo.jar
ENTRYPOINT java -Xms${JVM_XMS} -Xmx${JVM_XMX} ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -server -jar halo.jar
35 changes: 33 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,39 @@ configurations {

bootJar {
manifest {
attributes("Implementation-Title": "Halo Application",
"Implementation-Version": version)
attributes "Implementation-Title": "Halo Application",
"Implementation-Version": archiveVersion
}
}

bootBuildImage.doFirst {
// check data
assert System.getenv("DOCKER_USERNAME") != null
assert System.getenv("DOCKER_TOKEN") != null
}

bootBuildImage {
// prepare data
def tagLatest = Boolean.valueOf(System.getenv("TAG_LATEST"))
def dockerImageName = System.getenv("DOCKER_IMAGE_NAME")
def dockerUsername = System.getenv("DOCKER_USERNAME")
def dockerToken = System.getenv("DOCKER_TOKEN")

if (dockerImageName == null) {
dockerImageName = "${dockerUsername}/halo"
}
if (!tagLatest) {
dockerImageName = "${dockerImageName}:${project.version}"
}

// config plugin
imageName = "${dockerImageName}"
docker {
publishRegistry {
username = "${dockerUsername}"
password = "${dockerToken}"
email = "[email protected]"
}
}
}

Expand Down