Skip to content

Commit a83685a

Browse files
authored
Feat: Workflows (#100)
1 parent d8f37e0 commit a83685a

File tree

15 files changed

+218
-211
lines changed

15 files changed

+218
-211
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: "CodeQL Analysis"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
# At 12:00pm on the 1st and 15th
12+
- cron: '0 12 1,15 * *'
13+
14+
jobs:
15+
analyze:
16+
if: github.event.pull_request.draft == false
17+
name: Analyze
18+
runs-on: ubuntu-latest
19+
permissions:
20+
actions: read
21+
contents: read
22+
security-events: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v3
27+
28+
- name: Initialize CodeQL
29+
uses: github/codeql-action/init@v2
30+
with:
31+
languages: java
32+
33+
- name: Autobuild
34+
uses: github/codeql-action/autobuild@v2
35+
36+
- name: Perform CodeQL Analysis
37+
uses: github/codeql-action/analyze@v2

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: "Build, Publish and Release"
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}
10+
11+
jobs:
12+
build-publish-and-release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
# Setup
16+
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up JDK 8
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: '8'
23+
distribution: 'corretto'
24+
cache: 'maven'
25+
26+
- name: Set up yarn (Node 18)
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: 18
30+
cache: 'yarn'
31+
32+
# Build
33+
34+
## Build website, docs, javadoc and the project (Without tests)
35+
- name: Build project
36+
run: make build-wot
37+
38+
## Push to GHCR (GitHub Container Registry)
39+
- name: Docker build
40+
run: docker build --rm=false -t ghcr.io/${{ github.action_repository }}:${{ github.ref_name }} .
41+
42+
# Publish
43+
44+
- name: GitHub (GHCR) login
45+
run: echo $GHCR_TOKEN | docker login ghcr.io -u LucJosin --password-stdin
46+
47+
- name: GitHub (GHCR) push
48+
run: docker push ghcr.io/${{ github.action_repository }}:${{ github.ref_name }}
49+
50+
- name: Install and configure the Koyeb CLI
51+
uses: koyeb-community/install-koyeb-cli@v2
52+
with:
53+
api_token: "${{ secrets.KOYEB_TOKEN }}"
54+
github_token: "${{ secrets.GITHUB_TOKEN }}"
55+
56+
# Release
57+
58+
- name: Deploy to Koyeb
59+
run: koyeb service redeploy hawapi/hawapi

.github/workflows/testing.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Workflow ref: https://github.com/wesleyegberto/gh-actions-java/blob/master/.github/workflows/build-test-deploy.yml
2+
# Docker ref: https://dev.to/saulsilver/docker-stop-all-processes-on-github-actions-533j
3+
name: "Java Unit/Integration testing"
4+
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
10+
paths:
11+
- 'src/**'
12+
- 'src/pom.xml'
13+
- '.github/**'
14+
branches:
15+
- main
16+
17+
jobs:
18+
testing:
19+
# Ignore drafts
20+
if: github.event.pull_request.draft == false
21+
name: Java Unit/Integration testing
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v3
25+
26+
- name: Set up JDK 8
27+
uses: actions/setup-java@v3
28+
with:
29+
java-version: '8'
30+
distribution: 'corretto'
31+
cache: 'maven'
32+
33+
- name: Maven Test
34+
run: mvn test
35+
36+
- name: Publish Test Report
37+
if: success() || failure()
38+
uses: scacap/action-surefire-report@v1

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ build/
3535
.vscode/
3636

3737
### RSA Keys ###
38-
*.pem
38+
src/main/resources/keys/**
39+
## Fake keys
40+
!src/main/resources/keys/privateRSAKey.pem
41+
!src/main/resources/keys/publicRSAKey.pem
3942

4043
### Project
4144
.hawapi/

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM amazoncorretto:8
2+
3+
LABEL maintainer="Lucas Josino <contact@lucasjosino.com>"
4+
LABEL git="https://github/HawAPI/HawAPI"
5+
LABEL website="https://hawapi.theproject.id"
6+
7+
WORKDIR /app
8+
9+
COPY target/hawapi-*.jar hawapi.jar
10+
11+
EXPOSE 8080:8080
12+
ENTRYPOINT ["java","-jar","hawapi.jar", "-Dspring.profiles.active=prod"]

Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ verify: clean ## Verify the spring application
6161
clean: ## Clear the spring application
6262
@./mvnw clean
6363

64-
## Build
65-
66-
jar-run: ## Run the compiled application (target/hawapi-*.jar)
67-
@./scripts/run-jar.sh
68-
6964
## Website
7065

7166
website-build: ## Build the website

docs/GETTING_STARTED.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ To use the values on a production mode set these arguments before running the ja
205205
- [...] -DSPRING_DATASOURCE_URL=<...>
206206
207207
> **Note** \
208-
> Alternatively, set both values on the system environment
208+
> Alternatively, set all values on the system environment
209209
210210
### Website/Docs
211211
@@ -277,16 +277,13 @@ Different set up methods are required
277277
278278
#### Dev/Test Profiles
279279
280-
After generating the keys, copy the content to a file on:
281-
282-
> /src/main/resources/keys/
280+
By default, two RSA keys (public/private) are located at:
283281
284-
E.g:
282+
- /src/main/resources/keys/privateRSAKey.pem
283+
- /src/main/resources/keys/publicRSAKey.pem
285284
286-
- privateRSAKey.pem
287-
- [privateRSAKey.pem.example](../src/main/resources/keys/privateRSAKey.pem.example)
288-
- publicRSAKey.pem
289-
- [publicRSAKey.pem.example](../src/main/resources/keys/publicRSAKey.pem.example)
285+
> **Warning** \
286+
> Don't se this keys on production mode. **See below**
290287
291288
#### Prod (Production) Profile
292289

scripts/build-website.sh

Lines changed: 20 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -62,40 +62,13 @@ echo "${cyan}[$0] ${green}See all requisites: https://github.com/HawAPI/HawAPI/b
6262
echo "${cyan}[$0] ${green}Checking prerequisites for building website..."
6363
echo
6464

65-
## Check all requisites
66-
if ! type npm; then
67-
echo "${cyan}[$0] ${red}<npm> command not found!"
68-
exit 1
69-
else
70-
if ! type yarn; then
71-
## Yarn is required. Ask to install (GLOBALLY)
72-
echo "${cyan}[$0] ${red}<Yarn> command not found!"
73-
echo "${cyan}[$0] ${green}Install yarn? (GLOBALLY) (Y/n)"
74-
read -n1 -s -r yarn_response
75-
76-
if ! echo "$yarn_response" | grep '^[Yy]\?$'; then
77-
echo 'No'
78-
exit 1
79-
fi
80-
81-
echo "${cyan}[$0] ${green}Installing yarn..."
82-
npm install --global yarn
83-
fi
84-
fi
65+
# Check all requisites
8566

86-
if ! type retype; then
87-
## Retype is required. Ask to install
88-
echo "${cyan}[$0] ${red}<Retype> command not found!"
89-
echo "${cyan}[$0] ${green}Install retype? (GLOBALLY) (Y/n)"
90-
read -n1 -s -r retype_response
91-
92-
if ! echo "$retype_response" | grep '^[Yy]\?$'; then
93-
echo 'No'
94-
exit 1
95-
fi
96-
97-
echo "${cyan}[$0] ${green}Installing retype..."
98-
yarn global add retypeapp
67+
if ! type yarn; then
68+
## Yarn is required. Ask to install (LOCALLY)
69+
echo "${cyan}[$0] ${red}<Yarn> command not found!"
70+
echo "${cyan}[$0] ${green}Install yarn to build the website"
71+
exit 1
9972
fi
10073

10174
echo
@@ -128,61 +101,32 @@ fi
128101
echo "${cyan}[$0] ${green}Building the website..."
129102
cd .hawapi/website/ || exit 1
130103

131-
if ! [ -d "./node_modules" ]; then
132-
echo "${cyan}[$0] ${green}Directory './node_modules' not found! Running 'yarn'!"
133-
echo
134-
yarn
135-
echo
136-
fi
104+
## Yarn install into website and docs
105+
cd ./docs && yarn install
106+
cd ../ && yarn install
137107

108+
## Build website and docs
138109
echo
139-
yarn build-all
110+
yarn build:all
140111
echo
141112

142-
# Website and Docs adaptation
143-
144-
echo "${cyan}[$0] ${green}Starting website/docs adaptation..."
145-
echo
146-
147-
echo "${cyan}[$0] ${green}Removing '.nojekyll' file"
148-
rm -rf ./build/docs/.nojekyll
149-
150-
## Try to unzip and modify the 'sitemap.xml.gz' file.
151-
if ! type gunzip; then
152-
## If command 'gunzip' don't exist. Just remove the file.
153-
echo "${cyan}[$0] ${green}<gunzip> command not found! Removing 'sitemap.xml.gz' file"
154-
rm -rf ./build/docs/sitemap.xml.gz
155-
else
156-
echo "${cyan}[$0] ${green}Unzipping 'sitemap.xml.gz' file"
157-
gunzip ./build/docs/sitemap.xml.gz
158-
echo "${cyan}[$0] ${green}Replacing '.id/' with '.id/docs/'"
159-
echo "${cyan}[$0] ${green}Moving 'sitemap.xml.gz' file to './build/sitemap-1.xml'"
160-
sed 's#.id/#.id/docs/#' ./build/docs/sitemap.xml > ./build/sitemap-1.xml
161-
162-
echo "${cyan}[$0] ${green}Adding 'https://hawapi.theproject.id/sitemap-1.xml' to './build/docs/robots.txt'"
163-
echo 'Sitemap: https://hawapi.theproject.id/sitemap-1.xml' >> ./build/docs/robots.txt
164-
fi
165-
166-
echo "${cyan}[$0] ${green}Moving 'robots.txt' to './build/robots.txt'"
167-
sed 's/sitemap.xml.gz/sitemap-0.xml/' ./build/docs/robots.txt > ./build/robots.txt
168-
rm -rf ./build/docs/robots.txt
169-
rm -rf ./build/sitemap-index.xml
170-
171113
# Finalization
172114

173-
if [ -d "../../src/main/resources/static/" ]; then
115+
## Spring root
116+
cd ../../
117+
118+
if [ -d "./src/main/resources/static/" ]; then
174119
echo "${cyan}[$0] ${green}Found files inside 'resources/static/'! Deleting all..."
175-
rm -rf ../../src/main/resources/static/*
120+
rm -rf ./src/main/resources/static/*
176121
fi
177122

178-
if ! [ -d "../../src/main/resources/static/" ]; then
179-
mkdir -p ../../src/main/resources/static/
123+
if ! [ -d "./src/main/resources/static/" ]; then
124+
mkdir -p ./src/main/resources/static/
180125
fi
181126

182-
echo "${cyan}[$0] ${green}Moving files from './build/' to 'resources/static/'"
183-
mv ./build/* ../../src/main/resources/static/
127+
echo "${cyan}[$0] ${green}Moving files from '.hawapi/website/build/' to 'resources/static/'"
128+
mv .hawapi/website/build/* ./src/main/resources/static/
184129

185130
# Clean
186131

187-
cd ../..
188132
./scripts/clean-website.sh "$@"

0 commit comments

Comments
 (0)