-
Notifications
You must be signed in to change notification settings - Fork 294
148 lines (141 loc) · 4.54 KB
/
build.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Build
on:
pull_request:
paths-ignore:
- 'README.md'
- 'CODE_OF_CONDUCT.md'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'SECURITY.md'
- 'docs/**'
- '.github/**'
- '!.github/workflows/build.yml'
- '!.github/workflows/testserver.yml'
push:
branches:
- develop
- main
- release/*
tags: '[0-9]+.[0-9]+.[0-9]+'
paths-ignore:
- 'README.md'
- 'CODE_OF_CONDUCT.md'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'SECURITY.md'
- 'docs/**'
- '.github/**'
- '!.github/workflows/build.yml'
release:
types:
- created
# Keep in sync with codeql-analysis.yml and test.yml and analysis-of-endpoint-connections.yml
env:
CI: true
node: 20
java: 21
RAW_URL: https://raw.githubusercontent.com/${{ github.repository }}/${{ github.sha }}
jobs:
build:
name: Build .war artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '${{ env.node }}'
cache: 'npm'
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '${{ env.java }}'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Production Build
run: ./gradlew -Pprod -Pwar clean bootWar
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: Artemis.war
path: build/libs/Artemis-*.war
- name: Upload Release Artifact
if: github.event_name == 'release' && github.event.action == 'created'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: build/libs/Artemis-${{ github.event.release.tag_name }}.war
asset_name: Artemis.war
asset_content_type: application/x-webarchive
docker:
name: Build and Push Docker Image
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'ls1intum/Artemis' }}
runs-on: ubuntu-latest
steps:
- name: Compute Tag
uses: actions/github-script@v7
id: compute-tag
with:
result-encoding: string
script: |
if (context.eventName === "pull_request") {
return "pr-" + context.issue.number;
}
if (context.eventName === "release") {
return "latest";
}
if (context.eventName === "push") {
if (context.ref.startsWith("refs/tags/")) {
return context.ref.slice(10);
}
if (context.ref === "refs/heads/develop") {
return "develop";
}
}
return "FALSE";
- name: Git Checkout for PRs
if: ${{ github.event_name == 'pull_request' }}
# Checkout pull request HEAD commit instead of merge commit
# this is done to include the correct branch and git information inside the build
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Git Checkout for push actions
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
- name: Git Checkout for push actions
if: ${{ github.event_name == 'release' }}
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Build and Push to GitHub Container Registry
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: ${{ steps.compute-tag.outputs.result != 'FALSE' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push to GitHub Container Registry
uses: docker/build-push-action@v5
if: ${{ steps.compute-tag.outputs.result != 'FALSE' }}
with:
# beware that the linux/arm64 build from the registry is using an amd64 compiled .war file as
# the GitHub runners don't support arm64 and QEMU takes too long for emulating the build
platforms: linux/amd64,linux/arm64
file: ./docker/artemis/Dockerfile
context: .
tags: ghcr.io/ls1intum/artemis:${{ steps.compute-tag.outputs.result }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=min
# TODO: Push to Docker Hub (develop + tag)
# TODO: Push to Chair Harbour (??)