Skip to content

Commit f71c515

Browse files
committed
Adding GHA pipelines
1 parent d936f90 commit f71c515

File tree

7 files changed

+106
-20
lines changed

7 files changed

+106
-20
lines changed

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags-ignore:
7+
- '*'
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
concurrency:
14+
# On main, we don't want any jobs cancelled so the sha is used to name the group
15+
# On PR branches, we cancel the job if new commits are pushed
16+
# More info: https://stackoverflow.com/a/68422069/253468
17+
group: ${{ (github.ref == 'refs/heads/main') && format('{0}-{1}', github.workflow_ref, github.sha) || format('{0}-{1}', github.workflow_ref, github.head_ref) }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build:
22+
permissions:
23+
contents: read
24+
checks: write # for publishing test results and annotations
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v5
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Set up JDK 21
32+
uses: actions/setup-java@v4
33+
with:
34+
distribution: 'temurin'
35+
java-version: '21'
36+
cache: 'gradle'
37+
38+
- name: Build
39+
run: ./gradlew build
40+
41+
- name: Publish Test Report
42+
uses: mikepenz/action-junit-report@v5
43+
if: ${{ !cancelled() }} # always run even if the previous step fails
44+
with:
45+
report_paths: '**/build/test-results/test/TEST-*.xml'
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Tag & Release Workflow
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to release (must start with "v")'
10+
required: true
11+
12+
jobs:
13+
build-image:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
20+
outputs:
21+
digest: ${{ steps.push.outputs.digest }}
22+
tags: ${{ steps.meta.outputs.tags }}
23+
steps:
24+
- uses: actions/checkout@v5
25+
26+
- name: Set up JDK 21
27+
uses: actions/setup-java@v4
28+
with:
29+
distribution: 'temurin'
30+
java-version: '21'
31+
cache: 'gradle'
32+
33+
- uses: docker/setup-buildx-action@v3
34+
with:
35+
platforms: linux/amd64
36+
37+
- uses: docker/login-action@v3
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Build
44+
env:
45+
DOCKER_PUSH: true
46+
run: ./gradlew \
47+
-Pversion=${GITHUB_REF_NAME#v:-"${{ github.event.inputs.version }}"} \
48+
bootBuildImage

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ After the image is built, you can run it using a special Docker Compose profile
6565
```bash
6666
docker compose --profile include-course-hub up
6767
```
68+
69+
### Cleanup
70+
71+
Keep in mind that containers will keep running in the background even after you stop the application. To stop and remove the containers, run:
72+
```bash
73+
docker compose --profile include-course-hub down -v

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ test {
4444
}
4545
jvmArgs.add("-javaagent:${configurations.mockitoAgent.asPath}")
4646
}
47+
48+
tasks.named("bootBuildImage") {
49+
imageName.set("ghcr.io/hackyourfuture/course-hub-backend")
50+
tags.set(["ghcr.io/hackyourfuture/course-hub-backend:" + version])
51+
publish.set(System.getenv("DOCKER_PUSH")?.toBoolean() ?: false)
52+
}

docker-compose.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,8 @@ services:
1010
POSTGRES_DB: coursehub
1111
ports:
1212
- "5432:5432"
13-
course-hub-ui:
14-
image: node:alpine
15-
container_name: course-hub-ui
16-
entrypoint: /bin/sh
17-
ports:
18-
- 8000:8000
19-
working_dir: /srv/app
20-
volumes:
21-
- type: bind
22-
source: ./ui
23-
target: /srv/app
24-
tty: true
2513
course-hub:
26-
image: course-hub:0.0.1-SNAPSHOT
14+
image: ghcr.io/hackyourfuture/course-hub-backend:latest
2715
container_name: course-hub
2816
profiles:
2917
- include-course-hub

src/main/java/net/hackyourfuture/coursehub/web/CourseController.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package net.hackyourfuture.coursehub.web;
22

33
import net.hackyourfuture.coursehub.service.CourseService;
4-
import net.hackyourfuture.coursehub.web.model.CourseDto;
54
import net.hackyourfuture.coursehub.web.model.CourseListResponse;
65
import org.springframework.web.bind.annotation.GetMapping;
76
import org.springframework.web.bind.annotation.RestController;
87

9-
import java.util.List;
10-
118
@RestController
129
public class CourseController {
1310

ui/README.md

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

0 commit comments

Comments
 (0)