-
Notifications
You must be signed in to change notification settings - Fork 8
128 lines (114 loc) · 3.97 KB
/
api-release.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: API Release
on:
push:
branches:
- main
paths:
- "apps/api/**"
release:
types: [published]
defaults:
run:
working-directory: apps/api
jobs:
test:
name: Test
runs-on: ubuntu-latest
services:
postgres:
image: ankane/pgvector:latest
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
env:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
steps:
- uses: erlef/setup-beam@v1
with:
otp-version: "26"
elixir-version: "1.16.1"
- uses: actions/checkout@v4
- name: 'Setup jq'
uses: dcarbone/install-jq-action@v2
- name: Cache deps
id: cache-deps
uses: actions/cache@v3
env:
cache-name: cache-elixir-deps
with:
path: apps/api/deps
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
- name: Cache compiled build
id: cache-build
uses: actions/cache@v3
env:
cache-name: cache-compiled-build
with:
path: apps/api/_build
key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.cache-name }}-
${{ runner.os }}-mix-
- run: mix deps.get
- name: Compiles without warnings
run: mix compile
- run: mix test
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
if: ${{ github.event_name == 'push' }}
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.BUILDEL_API__FLY_API_TOKEN }}
if: ${{ github.event_name == 'push' }}
docker:
name: Docker
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Set up tags
id: set-tags
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "tags=ghcr.io/${{ github.repository }}/api:${{ github.sha }},ghcr.io/${{ github.repository }}/api:alpha" >> $GITHUB_ENV
fi
if [ "${{ github.event_name }}" == "release" ]; then
is_latest=$(gh api repos/${{ github.repository }}/releases/latest | jq -r '.tag_name == "${{ github.event.release.tag_name }}"')
if [ "$is_latest" == "true" ]; then
echo "tags=ghcr.io/${{ github.repository }}/api:${{ github.sha }},ghcr.io/${{ github.repository }}/api:${{ github.event.release.tag_name }},ghcr.io/${{ github.repository }}/api:latest" >> $GITHUB_ENV
else
echo "tags=ghcr.io/${{ github.repository }}/api:${{ github.sha }},ghcr.io/${{ github.repository }}/api:${{ github.event.release.tag_name }}" >> $GITHUB_ENV
fi
fi
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: apps/api
tags: ${{ env.tags }}
push: ${{ github.event_name == 'push' || github.event_name == 'release' }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/api:alpha-cache
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/api:alpha-cache,mode=max