Skip to content

Commit d8617b2

Browse files
committed
Initial draft of GHA
1 parent 87419a3 commit d8617b2

File tree

3 files changed

+179
-44
lines changed

3 files changed

+179
-44
lines changed

.github/workflows/main.yml

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,40 @@
1-
name: BuildEngine CI
1+
name: BuildEngine v2 Test and Deploy
22

33
on:
44
push:
5-
branches: [master, develop, github-builds]
6-
pull_request:
75
workflow_dispatch:
86
inputs:
9-
logLevel:
10-
description: "Log Level"
11-
required: true
12-
default: "warning"
137
tags:
148
description: "Tags"
15-
schedule:
16-
- cron: "0 0 * * 0" # weekly
179

1810
env:
19-
BUILD_TAG: "build-engine-api:${{ github.run_number }}"
11+
BUILD_ENGINE_BUILD_TAG: "build-engine-api:${{ github.run_number }}"
12+
OTEL_BUILD_TAG: "scriptoria-otel:${{ github.run_number }}"
2013
BUILD_NUMBER: ${{ github.run_number }}
2114

2215
jobs:
23-
build:
16+
check:
17+
uses: "./.github/workflows/setup.yml"
18+
secrets:
19+
AUTH0_SECRET: ${{ secrets.AUTH0_SECRET }}
20+
deploy-to-ecr:
2421
runs-on: ubuntu-latest
25-
22+
needs: check
23+
if: ${{ success() && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master') }}
2624
steps:
27-
- uses: actions/checkout@v3
28-
29-
- name: Get environment info
30-
run: |
31-
echo Docker version
32-
docker --version
33-
echo
34-
echo Env
35-
env
36-
37-
- name: Setup local.env
38-
run: |
39-
echo "COMPOSER_AUTH={\"github-oauth\":{\"github.com\":\""${{ secrets.GITHUB_TOKEN }}\""}}" > local.env
25+
- name: Checkout
26+
uses: actions/checkout@v5
4027

41-
- name: Install dependencies
42-
run: |
43-
echo "Installing ecs-deploy script..."
44-
mkdir -p $HOME/.local/bin
45-
curl -o $HOME/.local/bin/ecs-deploy https://raw.githubusercontent.com/silinternational/ecs-deploy/master/ecs-deploy
46-
chmod +x $HOME/.local/bin/ecs-deploy
47-
48-
- name: Tests
49-
run: |
50-
make test
28+
- name: Setup node
29+
uses: actions/setup-node@v5
30+
with:
31+
node-version: 24
5132

52-
- name: Build docker image
33+
- name: Build docker images
5334
uses: docker/build-push-action@v4
5435
with:
5536
push: false
56-
tags: ${{ env.BUILD_TAG }}
37+
tags: ${{ env.BUILD_ENGINE_BUILD_TAG }}
5738
context: .
5839
load: true
5940

@@ -75,7 +56,7 @@ jobs:
7556

7657
- name: Push to GHCR
7758
run: |
78-
docker tag ${{ env.BUILD_TAG }} ghcr.io/sillsdev/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}
59+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} ghcr.io/sillsdev/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}
7960
docker push ghcr.io/sillsdev/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}
8061
8162
- name: Configure AWS credentials (SIL)
@@ -94,8 +75,8 @@ jobs:
9475

9576
- name: Push to AWS ECR (SIL)
9677
run: |
97-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
98-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
78+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
79+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
9980
docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
10081
docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
10182
@@ -129,8 +110,8 @@ jobs:
129110
if: false # Temporarily disabled - remove this line to re-enable
130111
# if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-prd' }} # Restore this when re-enabling
131112
run: |
132-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
133-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
113+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
114+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
134115
docker push "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
135116
docker push "${{ steps.ecr_fcbh.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
136117
@@ -162,8 +143,8 @@ jobs:
162143
- name: Push to AWS ECR (LU)
163144
if: ${{ steps.branch.outputs.EcsCluster == 'scriptoria-stg' }}
164145
run: |
165-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
166-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
146+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
147+
docker tag ${{ env.BUILD_ENGINE_BUILD_TAG }} "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
167148
docker push "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
168149
docker push "${{ steps.ecr_lu.outputs.registry }}/appbuilder-buildengine-api:${{ env.BUILD_NUMBER }}"
169150

.github/workflows/pr.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Test and Lint
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- develop
8+
9+
jobs:
10+
checks:
11+
uses: ./.github/workflows/setup.yml

.github/workflows/setup.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
on:
2+
workflow_call:
3+
secrets:
4+
AUTH0_SECRET:
5+
required: false
6+
7+
env:
8+
APP_ENV: ci
9+
10+
jobs:
11+
# Install dependencies once and cache for other jobs
12+
setup:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
BACKUP_AUTH0_SECRET: ${{ steps.set-vars.outputs.BACKUP_AUTH0_SECRET }}
16+
steps:
17+
- uses: actions/checkout@v5
18+
- uses: actions/setup-node@v5
19+
with:
20+
node-version: 24
21+
cache: 'npm'
22+
cache-dependency-path: package-lock.json
23+
24+
- name: Get environment info
25+
id: set-vars
26+
run: |
27+
echo Node version
28+
node --version
29+
npm --version
30+
echo
31+
echo Docker version
32+
docker --version
33+
echo
34+
echo Environment variables
35+
env
36+
BACKUP_AUTH0_SECRET=$(hexdump -vn32 -e'8/4 "%08x" 1 "\n"' /dev/urandom)
37+
echo "BACKUP_AUTH0_SECRET=${BACKUP_AUTH0_SECRET}" >> $GITHUB_OUTPUT
38+
39+
- name: Restore node_modules cache
40+
id: restore-cache
41+
uses: actions/cache@v4
42+
with:
43+
path: node_modules
44+
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json', 'src/lib/prisma/schema.prisma') }}
45+
46+
- name: Install dependencies
47+
if: steps.restore-cache.outputs.cache-hit != 'true'
48+
run: |
49+
echo "Installing dependencies..."
50+
npm ci
51+
52+
- name: Cache node_modules
53+
if: steps.restore-cache.outputs.cache-hit != 'true'
54+
uses: actions/cache@v4
55+
with:
56+
path: node_modules
57+
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json', 'src/lib/prisma/schema.prisma') }}
58+
59+
# Type checking and linting
60+
typecheck-lint:
61+
runs-on: ubuntu-latest
62+
needs: setup
63+
steps:
64+
- uses: actions/checkout@v5
65+
- uses: actions/setup-node@v5
66+
with:
67+
node-version: 24
68+
69+
- name: Restore node_modules cache
70+
uses: actions/cache@v4
71+
with:
72+
path: node_modules
73+
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json', 'src/lib/prisma/schema.prisma') }}
74+
75+
- name: Run svelte-check
76+
run: |
77+
echo "Running svelte-check..."
78+
npm run check
79+
80+
- name: Run lint
81+
run: |
82+
echo "Running lint..."
83+
npm run lint
84+
85+
# Build and run a smoke test
86+
build-and-test:
87+
runs-on: ubuntu-latest
88+
needs: setup
89+
env:
90+
CI: true
91+
AUTH0_SECRET: ${{ secrets.AUTH0_SECRET || needs.setup.outputs.BACKUP_AUTH0_SECRET }}
92+
steps:
93+
- uses: actions/checkout@v5
94+
- uses: actions/setup-node@v5
95+
with:
96+
node-version: 24
97+
98+
- name: Restore node_modules cache
99+
uses: actions/cache@v4
100+
with:
101+
path: node_modules
102+
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json', 'src/lib/prisma/schema.prisma') }}
103+
104+
- name: Build, Install Playwright dependencies, and seed database
105+
run: |
106+
echo "Building .env file..."
107+
echo "AUTH0_SECRET=" >> .env
108+
echo "Building the docker project..."
109+
mkdir -p command-output
110+
(./run ci build > command-output/build-output.txt 2>&1) &
111+
echo "Beginning pull of images"
112+
./run ci pull valkey > /dev/null &
113+
echo "Starting database..."
114+
./run ci up -d db
115+
sleep 1
116+
echo "Resetting the database..."
117+
npx prisma migrate reset -f --skip-seed --skip-generate
118+
echo "Waiting for build and Playwright installation to finish..."
119+
wait
120+
if [ -f command-output/build-exit-code.txt ]; then
121+
BUILD_EXIT_CODE=$(cat command-output/build-exit-code.txt)
122+
echo "Build failed with exit code $BUILD_EXIT_CODE"
123+
cat command-output/build-output.txt
124+
exit $BUILD_EXIT_CODE
125+
fi
126+
echo "Build and Playwright installation completed."
127+
env:
128+
DATABASE_URL: 'postgresql://db-user:1234@localhost:5432/dev-buildengine?schema=public'
129+
130+
- name: Start docker-compose services
131+
run: |
132+
echo "Starting docker-compose services..."
133+
./run ci up -d
134+
135+
- name: Run tests
136+
run: |
137+
# Is the port open
138+
sleep 1
139+
nc -zv localhost 8443 || {
140+
echo "Port 8443 is not open"
141+
./run ci logs build-engine
142+
exit 1
143+
}

0 commit comments

Comments
 (0)