forked from halo-dev/halo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace travis ci with github action (halo-dev#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 tips
- Loading branch information
Showing
5 changed files
with
223 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]" | ||
} | ||
} | ||
} | ||
|
||
|