-
Notifications
You must be signed in to change notification settings - Fork 89
88 lines (78 loc) · 2.76 KB
/
ci.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
name: ci
on:
push:
branches:
- "master"
pull_request:
branches:
- "master"
jobs:
docker:
runs-on: ubuntu-latest
environment: Tests
services:
redis:
image: redis:6
ports:
- 6379:6379
steps:
- name: Checkout
uses: actions/checkout@v4
# if we don't fetch the history
# the news page will not be generated properly (it uses git)
with:
fetch-depth: 300
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get Redis network name
id: redis_network
run: echo "::set-output name=network_name::$(docker network ls --filter name=_default -q)"
- name: Build and export to Docker
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ghcr.io/${{ github.repository_owner }}/blot:test-${{ github.sha }}
target: test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test
env:
BLOT_STRIPE_KEY: ${{ secrets.BLOT_STRIPE_KEY }}
BLOT_STRIPE_SECRET: ${{ secrets.BLOT_STRIPE_SECRET }}
BLOT_STRIPE_PRODUCT: ${{ secrets.BLOT_STRIPE_PRODUCT }}
# the docker run environment is different from the docker-compose environment
# so we need to pass in these variables explicitly
run: |
docker run --rm \
--network name=${{ job.services.redis.network }} \
-e BLOT_REDIS_HOST=redis \
-e BLOT_STRIPE_KEY=$BLOT_STRIPE_KEY \
-e BLOT_STRIPE_SECRET=$BLOT_STRIPE_SECRET \
-e BLOT_STRIPE_PRODUCT=$BLOT_STRIPE_PRODUCT \
ghcr.io/${{ github.repository_owner }}/blot:test-${{ github.sha }} sh -c "node tests && npx depcheck --ignores=depcheck,nodemon,blessed-contrib,twit,fontkit,text-to-svg --skip-missing"
# this step should only run on pushes to master
# otherwise, pull requests will produce a production image
- name: Build production image
uses: docker/build-push-action@v5
if: github.ref == 'refs/heads/master'
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ghcr.io/${{ github.repository_owner }}/blot:latest
target: prod
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy
if: github.ref == 'refs/heads/master'
run: |
echo "Deploying to production"