-
Notifications
You must be signed in to change notification settings - Fork 7
102 lines (96 loc) · 3.28 KB
/
test.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
name: Build and Test
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
env:
MATERIAL_REPO: 'UNIVERSE-HPC/course-material'
MANAGER: 'yarn'
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
MATERIAL_DIR: ".material"
NEXT_PUBLIC_BASEPATH: ""
NEXTAUTH_URL: http://localhost:3002/gutenberg/api/auth
NEXTAUTH_SECRET: "secret here"
GITHUB_SECRET: "github_secret"
GITHUB_ID: "github_id"
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/gutenberg
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout material repo
uses: actions/checkout@v3
with:
repository: ${{ env.MATERIAL_REPO }}
path: .material
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "20"
cache: ${{ env.MANAGER }}
- name: Restore cache
uses: actions/cache@v3
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
- name: Install dependencies
run: ${{ env.MANAGER }} install
- name: Migrate database
run: ${{ env.MANAGER }} prisma migrate deploy
- name: Seed database with test data
run: ${{ env.MANAGER }} prisma db seed
- name: Build with Next.js
run: ${{ env.MANAGER }} build
# Enable tmate debugging of manually-triggered workflows if the input option was provided
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }}
- name: Run e2e tests
run: ${{ env.MANAGER }} ci:e2e
- name: Run component tests
run: ${{ env.MANAGER }} component
deploy:
name: Deploy to staging
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-and-test
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: ${{ secrets.MATERIAL_REPOSITORY }}
path: .material
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy -a gutenberg-staging --remote-only --build-arg DATABASE_URL=${{secrets.DATABASE_URL_TEST}} --wait-timeout 240
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}