-
Notifications
You must be signed in to change notification settings - Fork 1
136 lines (113 loc) · 3.72 KB
/
build.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
129
130
131
132
133
134
135
136
name: Build
on:
push:
branches:
- main
pull_request:
types:
- opened
# "synchronize" means new commits pushed to the HEAD of the pull request branch
- synchronize
env:
REGISTRY: ghcr.io
# What tags does:
# - always tag with sha
# - always tag with branch name
# - if a release tag is 'v1.0.0', then tag 'latest' and '1.0.0'
# More info: https://github.com/docker/metadata-action#tags-input
TAGS: |
type=sha
type=ref,event=branch
type=semver,pattern={{major}}.{{minor}}.{{patch}}
jobs:
cancel-previous:
runs-on: ubuntu-22.04
steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.11.0
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up NODE
uses: actions/setup-node@v3
# Note: set up node early for caching elm-format
with:
node-version: 20.13
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Backend Build and test
uses: freckle/stack-action@v5
id: stack
with:
working-directory: backend
test: true
cache-prefix: lts-22.20
stack-arguments: --copy-bins
stack-build-arguments: --pedantic --copy-bins
- uses: haskell/actions/hlint-setup@v2
- uses: haskell/actions/hlint-run@v2
- name: Install elm-format (for codegen)
run: npm install -g elm-format
- name: Codegen
run: ${{ steps.stack.outputs.local-bin-path }}/codegen
- name: Setup Elm
uses: jorelali/setup-elm@v5
with:
elm-version: 0.19.1
- name: Frontend Install dependencies
working-directory: frontend
run: npm ci
- name: Frontend Validate Formatting
working-directory: frontend
run: npm run format-validate
- name: Frontend Test
working-directory: frontend
run: npm test
- name: Frontend Review
working-directory: frontend
run: npm run review
- name: Frontend build
working-directory: frontend
run: npm run build
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Prepare tags and labels (backend)
id: meta-backend
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/haskell-to-elm/servant-to-elm-example-backend
tags: ${{ env.TAGS }}
- name: Build and push Docker image (backend)
uses: docker/build-push-action@v4
with:
context: backend
file: backend/Dockerfile
build-contexts: bin_path_context=${{ steps.stack.outputs.local-bin-path }}
push: true
tags: ${{ steps.meta-backend.outputs.tags}}
labels: ${{ steps.meta-backend.outputs.labels}}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Prepare tags and labels (frontend)
id: meta-frontend
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/haskell-to-elm/servant-to-elm-example-frontend
tags: ${{ env.TAGS }}
- name: Build and push Docker image (frontend)
uses: docker/build-push-action@v4
with:
context: frontend
file: frontend/Dockerfile
push: true
tags: ${{ steps.meta-frontend.outputs.tags }}
labels: ${{ steps.meta-frontend.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max