55 lines (53 loc) · 1.72 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Test and build
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
jobs:
build_and_test:
name: Build and test
runs-on: ubuntu-latest
permissions:
security-events: write
env:
SPRING_PROFILES_ACTIVE: githubaction
DB_DATABASE: test
DB_USER: root
DB_PASSWORD: root
GRADLE_OPTS: "-Xmx4096m -XX:MaxPermSize=4096m -XX:+HeapDumpOnOutOfMemoryError -XX:-UseGCOverheadLimit"
steps:
- name: Mysql Setup
run : |
sudo systemctl start mysql.service
mysql -e 'DROP DATABASE IF EXISTS ${{ env.DB_DATABASE }}; CREATE DATABASE ${{ env.DB_DATABASE }};' -u${{ env.DB_USER }} -p${{ env.DB_PASSWORD }}
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
- name: Run tests
run: ./gradlew test
build_and_push_docker_to_registry:
name: Push Docker image to Registry
runs-on: ubuntu-latest
needs: [build_and_test]
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Set branch name
run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: breakout
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ secrets.DOCKER_REGISTRY }}/breakout-backend:${{ env.BRANCH }}