Skip to content

Commit beec8b9

Browse files
committed
refactor: simplify github actions and workflows organisation
- split actions into utility and workflow-actions - combine previous workflows into 'staging' and 'production'
1 parent 168c4cb commit beec8b9

File tree

16 files changed

+288
-463
lines changed

16 files changed

+288
-463
lines changed

.github/actions/go-build/action.yaml

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

.github/actions/go-test/action.yaml

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

.github/actions/pnpm-install/action.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.
File renamed without changes.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: 🌐 Backend action
2+
description: This action builds, tests, and pushes the backend Docker image.
3+
4+
inputs:
5+
go-version:
6+
description: The version of Go to use.
7+
required: true
8+
build-path:
9+
description: The path to the build directory.
10+
required: true
11+
test-path:
12+
description: The path to the test directory.
13+
required: true
14+
output-name:
15+
description: The name of the output file.
16+
required: true
17+
tag:
18+
description: The tag to push to the Docker registry.
19+
required: true
20+
dockerhub_username:
21+
description: The username for my docker account.
22+
required: true
23+
dockerhub_token:
24+
description: The token for my docker account.
25+
required: true
26+
folder:
27+
description: The folder where resides the dockerfile.
28+
required: true
29+
30+
runs:
31+
using: composite
32+
steps:
33+
- name: Setup Go
34+
uses: actions/setup-go@v5
35+
with:
36+
go-version: ${{ inputs.go-version }}
37+
38+
- name: Setup test dependencies
39+
shell: bash
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y ca-certificates build-essential
43+
sudo update-ca-certificates
44+
45+
- name: ⬣ Build application
46+
shell: bash
47+
env:
48+
CGO_ENABLED: 1
49+
GOOS: linux
50+
run: |
51+
cd backend
52+
go build -ldflags="-s" -v -o ${{ inputs.output-name }} ${{ inputs.build-path }}
53+
- name: 🧪 Golang tests
54+
shell: bash
55+
env:
56+
CGO_ENABLED: 1
57+
GOOS: linux
58+
run: |
59+
cd backend
60+
go test ${{ inputs.test-path }}
61+
- name: Push backend docker application to container registry
62+
uses: ./.github/actions/utility-actions/push-docker-image
63+
with:
64+
tag: ${{ inputs.tag }}
65+
dockerhub_username: ${{ inputs.dockerhub_username }}
66+
dockerhub_token: ${{ inputs.dockerhub_token }}
67+
folder: ${{ inputs.folder }}

.github/actions/deploy/action.yaml renamed to .github/actions/workflow-actions/deploy-app/action.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: 🚀 Deploy application
2-
description: Build and push a docker image to docker hub.
2+
description: This action deploys the application by pulling the latest Docker images from the container registry, removing existing containers, and starting the services. It also includes health checks and cleanup of unused resources.
33

44
inputs:
55
filter:
@@ -11,9 +11,6 @@ inputs:
1111
dockerhub_token:
1212
description: Docker Hub access token for authentication
1313
required: true
14-
compose_file:
15-
description: Name of the Docker Compose file without the .compose.yaml extension
16-
required: true
1714
app_env:
1815
description: Application environment (e.g., 'staging' or 'production')
1916
required: true
@@ -50,6 +47,9 @@ inputs:
5047
google_client_secret:
5148
description: Google OAuth client secret for authentication
5249
required: true
50+
redis_password:
51+
description: Redis password for authentication
52+
required: true
5353

5454
runs:
5555
using: 'composite'
@@ -87,6 +87,7 @@ runs:
8787
GMAIL_PASSWORD: ${{ inputs.gmail_password }}
8888
GOOGLE_CLIENT_ID: ${{ inputs.google_client_id }}
8989
GOOGLE_CLIENT_SECRET: ${{ inputs.google_client_secret }}
90+
REDIS_PASSWORD: ${{ inputs.redis_password }}
9091
run: |
9192
{
9293
echo "=== Deployment started at $(date) ==="
@@ -96,7 +97,7 @@ runs:
9697
docker pull henga/leviosa:${{ inputs.app_env }}-backend
9798
9899
echo "Starting services..."
99-
docker compose -f ${{ inputs.compose_file }}.yaml up -d --force-recreate
100+
docker compose up -d --force-recreate
100101
101102
echo "Waiting for services to be healthy..."
102103
attempt_counter=0
@@ -105,7 +106,7 @@ runs:
105106
until curl --output /dev/null --silent --fail ${{ inputs.public_url }}/health; do
106107
if [ ${attempt_counter} -eq ${max_attempts} ]; then
107108
echo "ERROR: Application failed to become healthy after 2 minutes"
108-
docker compose -f ${{ inputs.compose_file }}.compose.yaml logs
109+
docker compose logs
109110
exit 1
110111
fi
111112
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 🌐 Frontend action
2+
description: This action builds, tests, and pushes the frontend Docker image.
3+
4+
inputs:
5+
tag:
6+
description: The tag to push to the Docker registry.
7+
required: true
8+
dockerhub_username:
9+
description: The username for my docker account.
10+
required: true
11+
dockerhub_token:
12+
description: The token for my docker account.
13+
required: true
14+
folder:
15+
description: The folder where resides the dockerfile.
16+
required: true
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: install pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
version: 9.0.5
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: 20.11.1
28+
cache: 'pnpm'
29+
cache-dependency-path: './frontend/pnpm-lock.yaml'
30+
- name: Install dependencies
31+
working-directory: ./frontend
32+
run: pnpm install
33+
shell: bash
34+
- name: Build SvelteKit project
35+
working-directory: ./frontend
36+
run: pnpm run build # or pnpm prepare
37+
shell: bash
38+
- name: Cache .svelte-kit and node_modules
39+
uses: actions/cache@v3
40+
with:
41+
path: |
42+
./frontend/.svelte-kit
43+
./frontend/node_modules
44+
key: ${{ runner.os }}-svelte-kit-${{ hashFiles('frontend/pnpm-lock.yaml') }}
45+
restore-keys: |
46+
${{ runner.os }}-svelte-kit-#
47+
# - name: 🔬 Lint
48+
# working-directory: ./frontend
49+
# run: pnpm run lint
50+
# - name: 🔎 Type check
51+
# working-directory: ./frontend
52+
# run: pnpm run check
53+
# - name: Update apt and install dependencies
54+
# working-directory: ./frontend
55+
# run: |
56+
# apt-get update
57+
# apt-get install -y libenchant-dev libicu-dev libjpeg-turbo-official32=2.2 libvpx-dev libevent-dev
58+
# - name: Install playwright browsers
59+
# working-directory: ./frontend
60+
# run: pnpm exec playwright install --with-deps
61+
# - name: 🔎 Integration test
62+
# working-directory: ./frontend
63+
# run: pnpm run test:integration
64+
- name: 🔎 Unit test
65+
working-directory: ./frontend
66+
run: pnpm run test:unit
67+
shell: bash
68+
- name: Push frontend docker application to container registry
69+
uses: ./.github/actions/utility-actions/push-docker-image
70+
with:
71+
tag: ${{ inputs.tag }}
72+
dockerhub_username: ${{ inputs.dockerhub_username }}
73+
dockerhub_token: ${{ inputs.dockerhub_token }}
74+
folder: ${{ inputs.folder }}

.github/workflows/back.yaml

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

.github/workflows/deploy-vps.yaml

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

0 commit comments

Comments
 (0)