Skip to content

Commit 27f60d9

Browse files
committed
Add Github actions
1 parent 53ce636 commit 27f60d9

File tree

8 files changed

+328
-43
lines changed

8 files changed

+328
-43
lines changed

.github/workflows/main.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Continuous integration, including test and integration test
2+
name: CI
3+
4+
# Run in master and dev branches and in all pull requests to those branches
5+
on:
6+
push:
7+
branches: [ master, dev ]
8+
pull_request:
9+
branches: [ master, dev ]
10+
11+
env:
12+
DOCKER_IMAGE: radarbase/radar-output-restructure
13+
14+
jobs:
15+
# Build and test the code
16+
build:
17+
# The type of runner that the job will run on
18+
runs-on: ubuntu-latest
19+
20+
# Steps represent a sequence of tasks that will be executed as part of the job
21+
steps:
22+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
23+
- uses: actions/checkout@v2
24+
25+
- uses: actions/setup-java@v1
26+
with:
27+
java-version: 11
28+
29+
- name: Gradle cache
30+
uses: actions/cache@v2
31+
with:
32+
# Cache gradle directories
33+
path: |
34+
~/.gradle/caches
35+
~/.gradle/wrapper
36+
# An explicit key for restoring and saving the cache
37+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts', 'gradle.properties') }}
38+
restore-keys: |
39+
${{ runner.os }}-gradle-
40+
41+
# Compile the code
42+
- name: Compile code
43+
run: ./gradlew assemble
44+
45+
# Gradle check
46+
- name: Check
47+
run: ./gradlew check
48+
49+
- uses: actions/upload-artifact@v2
50+
if: always()
51+
with:
52+
name: integration-test-logs
53+
path: build/container-logs/
54+
retention-days: 7
55+
56+
# Check that the docker image builds correctly
57+
docker:
58+
# The type of runner that the job will run on
59+
runs-on: ubuntu-latest
60+
61+
# Steps represent a sequence of tasks that will be executed as part of the job
62+
steps:
63+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
64+
- uses: actions/checkout@v2
65+
66+
- name: Cache Docker layers
67+
uses: actions/cache@v2
68+
with:
69+
path: /tmp/.buildx-cache
70+
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '**/*.gradle.kts', 'gradle.properties', 'src/main/**') }}
71+
restore-keys: |
72+
${{ runner.os }}-buildx-
73+
74+
# Add Docker labels and tags
75+
- name: Docker meta
76+
id: docker_meta
77+
uses: crazy-max/ghaction-docker-meta@v2
78+
with:
79+
images: ${{ env.DOCKER_IMAGE }}
80+
81+
- name: Login to Docker Hub
82+
uses: docker/login-action@v1
83+
with:
84+
username: ${{ secrets.DOCKERHUB_USERNAME }}
85+
password: ${{ secrets.DOCKERHUB_TOKEN }}
86+
87+
# Setup docker build environment
88+
- name: Set up QEMU
89+
uses: docker/setup-qemu-action@v1
90+
91+
- name: Set up Docker Buildx
92+
uses: docker/setup-buildx-action@v1
93+
94+
- name: Build
95+
uses: docker/build-push-action@v2
96+
with:
97+
context: ./
98+
file: ./Dockerfile
99+
cache-from: type=local,src=/tmp/.buildx-cache
100+
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
101+
load: ${{ github.event_name == 'pull_request' }}
102+
push: ${{ github.event_name != 'pull_request' }}
103+
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
104+
tags: ${{ steps.docker_meta.outputs.tags }}
105+
# Use runtime labels from docker_meta as well as fixed labels
106+
labels: |
107+
${{ steps.docker_meta.outputs.labels }}
108+
maintainer=Joris Borgdorff <[email protected]>
109+
org.opencontainers.image.authors=Joris Borgdorff <[email protected]>
110+
org.opencontainers.image.vendor=RADAR-base
111+
org.opencontainers.image.licenses=Apache-2.0
112+
113+
# If the image was pushed, we need to pull it again to inspect it
114+
- name: Pull image
115+
if: ${{ github.event_name != 'pull_request' }}
116+
run: docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
117+
118+
- name: Inspect image
119+
run: |
120+
docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
121+
docker run --rm ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} curl --help
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Continuous integration, including test and integration test
2+
name: Publish snapshots
3+
4+
# Run in master and dev branches and in all pull requests to those branches
5+
on:
6+
push:
7+
branches: [ dev ]
8+
9+
jobs:
10+
# Build and test the code
11+
build:
12+
# The type of runner that the job will run on
13+
runs-on: ubuntu-latest
14+
15+
# Steps represent a sequence of tasks that will be executed as part of the job
16+
steps:
17+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
18+
- uses: actions/checkout@v2
19+
20+
- name: Has SNAPSHOT version
21+
id: is-snapshot
22+
run: grep 'version = ".*-SNAPSHOT"' build.gradle.kts
23+
24+
- uses: actions/setup-java@v1
25+
with:
26+
java-version: 11
27+
28+
- name: Cache
29+
uses: actions/cache@v2
30+
with:
31+
# Cache gradle directories
32+
path: |
33+
~/.gradle/caches
34+
~/.gradle/wrapper
35+
# Key for restoring and saving the cache
36+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts', 'gradle.properties') }}
37+
restore-keys: |
38+
${{ runner.os }}-gradle
39+
40+
- name: Install gpg secret key
41+
run: |
42+
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
43+
gpg --list-secret-keys --keyid-format LONG
44+
45+
- name: Publish
46+
env:
47+
OSSRH_USER: ${{ secrets.OSSRH_USER }}
48+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
49+
run: ./gradlew -Psigning.gnupg.keyName=${{ secrets.OSSRH_GPG_SECRET_KEY }} -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} publish

.github/workflows/release.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Create release files
2+
name: Release
3+
4+
on:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
upload:
10+
# The type of runner that the job will run on
11+
runs-on: ubuntu-latest
12+
13+
# Steps represent a sequence of tasks that will be executed as part of the job
14+
steps:
15+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
16+
- uses: actions/checkout@v2
17+
- uses: actions/setup-java@v1
18+
with:
19+
java-version: 11
20+
21+
- name: Gradle cache
22+
uses: actions/cache@v2
23+
with:
24+
# Cache gradle directories
25+
path: |
26+
~/.gradle/caches
27+
~/.gradle/wrapper
28+
# An explicit key for restoring and saving the cache
29+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts', 'gradle.properties') }}
30+
restore-keys: |
31+
${{ runner.os }}-gradle-
32+
33+
# Compile code
34+
- name: Compile code
35+
run: ./gradlew assemble
36+
37+
# Upload it to GitHub
38+
- name: Upload to GitHub
39+
uses: AButler/[email protected]
40+
with:
41+
files: 'build/libs/*;build/distributions/*'
42+
repo-token: ${{ secrets.GITHUB_TOKEN }}
43+
44+
- name: Install gpg secret key
45+
run: |
46+
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import
47+
gpg --list-secret-keys --keyid-format LONG
48+
49+
- name: Publish
50+
env:
51+
OSSRH_USER: ${{ secrets.OSSRH_USER }}
52+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
53+
run: ./gradlew -Psigning.gnupg.keyName=${{ secrets.OSSRH_GPG_SECRET_KEY }} -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} publish closeAndReleaseSonatypeStagingRepository
54+
55+
# Build and push tagged release docker image
56+
docker:
57+
# The type of runner that the job will run on
58+
runs-on: ubuntu-latest
59+
60+
# Steps represent a sequence of tasks that will be executed as part of the job
61+
steps:
62+
- uses: actions/checkout@v2
63+
64+
# Add Docker labels and tags
65+
- name: Docker meta
66+
id: docker_meta
67+
uses: crazy-max/ghaction-docker-meta@v2
68+
with:
69+
images: ${{ env.DOCKER_IMAGE }}
70+
tags: |
71+
type=match,pattern=v(.*),group=1
72+
73+
# Setup docker build environment
74+
- name: Set up QEMU
75+
uses: docker/setup-qemu-action@v1
76+
- name: Set up Docker Buildx
77+
uses: docker/setup-buildx-action@v1
78+
79+
- name: Login to DockerHub
80+
uses: docker/login-action@v1
81+
with:
82+
username: ${{ secrets.DOCKERHUB_USERNAME }}
83+
password: ${{ secrets.DOCKERHUB_TOKEN }}
84+
85+
- name: Build and push
86+
id: docker_build
87+
uses: docker/build-push-action@v2
88+
with:
89+
context: ./
90+
file: ./Dockerfile
91+
# Allow running the image on the architectures supported by openjdk:11-jre-slim
92+
platforms: linux/amd64,linux/arm64
93+
push: true
94+
tags: ${{ steps.docker_meta.outputs.tags }}
95+
# Use runtime labels from docker_meta as well as fixed labels
96+
labels: |
97+
${{ steps.docker_meta.outputs.labels }}
98+
maintainer=Joris Borgdorff <[email protected]>
99+
org.opencontainers.image.authors=Joris Borgdorff <[email protected]>
100+
org.opencontainers.image.vendor=RADAR-base
101+
org.opencontainers.image.licenses=Apache-2.0
102+
103+
- name: Inspect image
104+
run: |
105+
docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
106+
docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Snyk scheduled test
2+
on:
3+
schedule:
4+
- cron: '0 2 * * 1'
5+
jobs:
6+
security:
7+
runs-on: ubuntu-latest
8+
env:
9+
REPORT_FILE: test.json
10+
steps:
11+
- uses: actions/checkout@master
12+
13+
- name: Run Snyk to check for vulnerabilities
14+
uses: snyk/actions/gradle-jdk11@master
15+
env:
16+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
17+
with:
18+
command: test
19+
args: --json-file-output=${{ env.REPORT_FILE }}
20+
21+
- name: Report new vulnerabilities
22+
uses: thehyve/report-vulnerability@master
23+
with:
24+
report-file: ${{ env.REPORT_FILE }}
25+
env:
26+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
if: ${{ failure() }}

.github/workflows/snyk.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Snyk test
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
jobs:
7+
security:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@master
11+
- name: Run Snyk to check for vulnerabilities
12+
uses: snyk/actions/gradle-jdk11@master
13+
env:
14+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
15+
with:
16+
args: --severity-threshold=high

.travis.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
22
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
33
import org.jetbrains.dokka.gradle.DokkaTask
44
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5+
import java.time.Duration
56

67
plugins {
78
kotlin("jvm")
@@ -147,9 +148,15 @@ tasks.withType<Test> {
147148
}
148149
}
149150

151+
dockerCompose {
152+
waitForTcpPortsTimeout = Duration.ofSeconds(30)
153+
environment["SERVICES_HOST"] = "localhost"
154+
captureContainersOutputToFiles = project.file("build/container-logs")
155+
isRequiredBy(integrationTest)
156+
}
157+
150158
val check by tasks
151159
check.dependsOn(integrationTest)
152-
project.dockerCompose.isRequiredBy(integrationTest)
153160

154161
tasks.withType<Tar> {
155162
compression = Compression.GZIP

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
- /data
1111

1212
redis:
13-
image: bitnami/redis:6.0
13+
image: bitnami/redis
1414
ports:
1515
- "6379:6379"
1616
environment:

0 commit comments

Comments
 (0)