Skip to content

Commit 751a733

Browse files
committed
Add actions workflow
1 parent 7936eb7 commit 751a733

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

.github/workflows/build.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths-ignore:
7+
- '.github/workflows/pullrequest.yml'
8+
- '.idea/copyright/*.xml'
9+
- '.gitignore'
10+
- 'LICENSE'
11+
- 'README.md'
12+
13+
env:
14+
DOCKER_OWNER: ${{ github.repository_owner }}
15+
DOCKER_CONTAINER: server-ping-api
16+
DOCKER_TAG: ${{ github.ref_name }}
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Set up JDK 17
24+
uses: actions/setup-java@v3
25+
with:
26+
java-version: 17
27+
distribution: temurin
28+
29+
- name: Checkout repository
30+
uses: actions/checkout@v3
31+
32+
- name: Build ServerPingApi
33+
uses: gradle/gradle-build-action@v2
34+
with:
35+
arguments: build
36+
37+
- name: Archive artifacts
38+
uses: actions/upload-artifact@v3
39+
if: success()
40+
with:
41+
name: ServerPingApi
42+
path: build/libs/ServerPingApi.jar
43+
44+
# Docker image build
45+
- name: Fix Docker environment variables
46+
run: |
47+
# Make lowercase
48+
echo "DOCKER_OWNER=$(echo $DOCKER_OWNER | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
49+
echo "DOCKER_CONTAINER=$(echo $DOCKER_CONTAINER | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
50+
echo "DOCKER_TAG=$(echo $DOCKER_TAG | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
51+
52+
# Replace / with _
53+
echo "DOCKER_TAG=$(echo $DOCKER_TAG | sed -e 's/\//_/g')" >> $GITHUB_ENV
54+
55+
- name: Build the Docker image
56+
run: |
57+
docker build . --file Dockerfile --tag $DOCKER_CONTAINER:$DOCKER_TAG
58+
[[ "${{ github.ref }}" == "refs/heads/master" ]] && docker tag $DOCKER_CONTAINER:$DOCKER_TAG ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:latest
59+
docker tag $DOCKER_CONTAINER:$DOCKER_TAG ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:$DOCKER_TAG
60+
61+
- name: Log in to registry
62+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
63+
64+
- name: Push to GHCR
65+
run: |
66+
[[ "${{ github.ref }}" == "refs/heads/master" ]] && docker push ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:latest
67+
docker push ghcr.io/$DOCKER_OWNER/$DOCKER_CONTAINER:$DOCKER_TAG

.github/workflows/pullrequest.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build Pull Request
2+
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
paths-ignore:
8+
- '.github/workflows/build.yml'
9+
- '.idea/copyright/*.xml'
10+
- '.gitignore'
11+
- 'LICENSE'
12+
- 'README.md'
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: 17
23+
distribution: temurin
24+
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
28+
- name: Build ServerPingApi
29+
uses: gradle/gradle-build-action@v2
30+
with:
31+
arguments: build
32+
33+
- name: Archive artifacts
34+
uses: actions/upload-artifact@v3
35+
if: success()
36+
with:
37+
name: ServerPingApi
38+
path: build/libs/ServerPingApi.jar

0 commit comments

Comments
 (0)