mirror of https://github.com/halo-dev/halo
Replace travis ci with github action (#1212)
* 1196 refactor/ci (#3) * Remove .travis.yml * Refactor github action partially * Fix yaml syntax error * Add run command for every step * Set current branch name into halo.yml temporarily * Test validation.yml * Add upload-release-asset step into release.yml * Perfect release.yml * Fix indent error * Refactor on condition in release.yml * Refactor on condition in validation.yml * Fix release.yml * Fix upload_url value set * Fix environment set error * Change artifact variable from output into global environment * Fix deprecated environment set method * Fix environment variable set error * Change assert_content_type with application/zip * Refactor upload release step * Fix release id set * Fix release id set again * Fix syntax error * Refactor upload process * Refactor halo ci * Make build step rely on check step * Inspect docker action * Inspect docker action again * Refine bootBuildImage config * Refactor bootBuildImage config and halo ci * Fix download artifact path error * Fix docker image name concat error * Remove downloaded files inspect tipspull/1220/head
parent
8ba115ffb6
commit
7cb4f3464a
|
@ -1,31 +0,0 @@
|
||||||
name: Halo CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- name: Set up JDK 11
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 11
|
|
||||||
- name: Cache Gradle
|
|
||||||
id: cache-gradle
|
|
||||||
uses: actions/cache@v1
|
|
||||||
with:
|
|
||||||
path: ~/.gradle/caches
|
|
||||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-gradle-
|
|
||||||
- name: Test with Gradle
|
|
||||||
run: ./gradlew test
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew build -x test
|
|
|
@ -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/cache@v2.1.3
|
||||||
|
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/cache@v2.1.3
|
||||||
|
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/cache@v2.1.3
|
||||||
|
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/cache@v2.1.3
|
||||||
|
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/cache@v2.1.3
|
||||||
|
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
.travis.yml
49
.travis.yml
|
@ -1,49 +0,0 @@
|
||||||
language: java
|
|
||||||
jdk:
|
|
||||||
- openjdk:11
|
|
||||||
before_cache:
|
|
||||||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
|
||||||
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.gradle/caches/
|
|
||||||
- $HOME/.gradle/wrapper/
|
|
||||||
- $TRAVIS_BUILD_DIR/build/libs/
|
|
||||||
dist: trusty
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
- stage: test
|
|
||||||
script: ./gradlew check
|
|
||||||
- stage: build
|
|
||||||
script: ./gradlew clean build -x test
|
|
||||||
- stage: Build Docker Image for Release
|
|
||||||
script: ./scripts/docker-build-release.sh
|
|
||||||
- stage: Build Docker Image for Dev
|
|
||||||
script: ./scripts/docker-build-dev.sh
|
|
||||||
- stage: GitHub Release
|
|
||||||
script: echo "Deploying to GitHub releases ..." && pwd
|
|
||||||
deploy:
|
|
||||||
provider: releases
|
|
||||||
api_key: $GITHUB_OAUTH_TOKEN
|
|
||||||
file_glob: true
|
|
||||||
file: $TRAVIS_BUILD_DIR/build/libs/*
|
|
||||||
skip_cleanup: true
|
|
||||||
on:
|
|
||||||
tags: true
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- build
|
|
||||||
- name: GitHub Release
|
|
||||||
if: tag =~ /^v\d+\.\d+(\.\d+)?(-\S*)?$/
|
|
||||||
- name: Build Docker Image for Release
|
|
||||||
if: tag =~ /^v\d+\.\d+(\.\d+)?(-release)?$/
|
|
||||||
- name: Build Docker Image for Dev
|
|
||||||
if: tag =~ /^v\d+\.\d+(\.\d+)?-(beta|alpha)+(\.\d+)?$/
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- dev
|
|
||||||
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
|
|
||||||
notifications:
|
|
||||||
webhooks:
|
|
||||||
- https://fathomless-fjord-24024.herokuapp.com/notify
|
|
15
Dockerfile
15
Dockerfile
|
@ -1,16 +1,17 @@
|
||||||
FROM adoptopenjdk/openjdk11-openj9
|
FROM adoptopenjdk/openjdk11-openj9
|
||||||
VOLUME /tmp
|
VOLUME /tmp
|
||||||
|
|
||||||
ARG JAR_FILE=build/libs/halo.jar
|
ARG JAR_FILE=build/libs/*.jar
|
||||||
ARG PORT=8090
|
|
||||||
ARG TIME_ZONE=Asia/Shanghai
|
ARG TIME_ZONE=Asia/Shanghai
|
||||||
|
|
||||||
ENV TZ=${TIME_ZONE}
|
ENV JVM_XMS="256m" \
|
||||||
ENV JVM_XMS="256m"
|
JVM_XMX="256m" \
|
||||||
ENV JVM_XMX="256m"
|
JVM_OPTS="" \
|
||||||
|
TZ=${TIME_ZONE}
|
||||||
|
|
||||||
|
|
||||||
COPY ${JAR_FILE} halo.jar
|
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
build.gradle
35
build.gradle
|
@ -37,8 +37,39 @@ configurations {
|
||||||
|
|
||||||
bootJar {
|
bootJar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes("Implementation-Title": "Halo Application",
|
attributes "Implementation-Title": "Halo Application",
|
||||||
"Implementation-Version": version)
|
"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 = "hi@halo.run"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue