-
Notifications
You must be signed in to change notification settings - Fork 11
173 lines (154 loc) · 5.07 KB
/
build-application.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build and publish application binaries
on: [push]
jobs:
# ########################################################################## #
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ghc: ['8.10.7', '9.0.2', '9.2', '9.4']
cabal: ['3.8']
os: ['ubuntu-20.04', 'ubuntu-22.04', 'macOS-latest']
steps:
- name: Set Variables
id: vars
shell: bash
run: |
cat >> $GITHUB_ENV <<EOF
SHORT_SHA=${GITHUB_SHA::7}
ARTIFACTS_DIR=./artifacts/chainweb-mining-client
ARTIFACTS_NAME=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}
ARTIFACTS_ARCHIVE=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}.${GITHUB_SHA::7}.tar.gz
EOF
# Setup
- name: Checkout repository
uses: actions/checkout@v3
- name: Install GHC and Cabal
uses: haskell/actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- name: Confirm GHC and Cabal installation
run: |
ghc --version
cabal --version
- uses: actions/cache@v3
name: Cache dist-newstyle
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: ${{ matrix.os }}-${{ matrix.ghc }}-1-cabal
# Build
- name: Update package database
run: cabal update
- name: Configure build
run: |
rm -rf dist-newstyle/build/*/ghc-*/chainweb-mining-client-*/build/chainweb-mining-client/chainweb-mining-client
cabal build all --dry-run --enable-tests
cabal freeze --enable-tests
- name: Install build dependencies
run: cabal build --only-dependencies --enable-tests
- name: Build
run: cabal build
# Tests
- name: Run Tests
run: cabal test
# Artifacts
- name: Prepare artifacts
run: |
echo "ARTIFACTS_ARCHIVE: $ARTIFACTS_ARCHIVE"
mkdir -p $ARTIFACTS_DIR
cp $(cabal list-bin chainweb-mining-client) $ARTIFACTS_DIR
cp README.md $ARTIFACTS_DIR
cp CHANGELOG.md $ARTIFACTS_DIR
cp LICENSE $ARTIFACTS_DIR
cp chainweb-mining-client.cabal $ARTIFACTS_DIR
cp cabal.project $ARTIFACTS_DIR
cp cabal.project.freeze $ARTIFACTS_DIR
tar -C ./artifacts/ -czf "$ARTIFACTS_ARCHIVE" chainweb-mining-client
- name: Safe artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACTS_NAME }}
path: ${{ env.ARTIFACTS_ARCHIVE }}
if-no-files-found: error
# ########################################################################## #
docker-image:
name: Build and publish docker image
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ghc: ["9.2"]
os: ["ubuntu-22.04"]
env:
GHC_VERSION: ${{ matrix.ghc }}
OS: ${{ matrix.os }}
COMPILER: ghc-${{ matrix.ghc }}
steps:
- name: Set Variables
id: vars
shell: bash
run: |
cat >> $GITHUB_ENV <<EOF
SHORT_SHA=${GITHUB_SHA::7}
ARTIFACTS_NAME=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}
ARTIFACTS_ARCHIVE=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}.${GITHUB_SHA::7}.tar.gz
EOF
- name: Get build artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACTS_NAME }}
path: .
- name: Extract artifacts
run: |
tar -xzf "$ARTIFACTS_ARCHIVE"
- name: Create Dockerfile
run: |
cat > Dockerfile <<EOF
FROM ubuntu:${OS#ubuntu-}
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /chainweb-mining-client
COPY chainweb-mining-client/chainweb-mining-client .
COPY chainweb-mining-client/LICENSE .
COPY chainweb-mining-client/README.md .
COPY chainweb-mining-client/CHANGELOG.md .
COPY chainweb-mining-client/chainweb-mining-client.cabal .
COPY chainweb-mining-client/cabal.project .
COPY chainweb-mining-client/cabal.project.freeze .
ENTRYPOINT [ "/chainweb-mining-client/chainweb-mining-client" ]
EOF
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/kadena-io/chainweb-mining-client
tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
push: true
context: .
file: ./Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}