-
Notifications
You must be signed in to change notification settings - Fork 0
199 lines (173 loc) · 6.6 KB
/
ocaml-general.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: OCaml-General
on:
push:
paths:
- 'ocaml-general/**'
- '!ocaml-general/README.md'
- '.github/workflows/ocaml-general.yml'
branches: [main]
workflow_dispatch:
inputs:
ref:
description: branch|tag|SHA to checkout
default: 'main'
required: true
schedule:
# 日本時間の月曜日午前2時に毎週実行される
- cron: '0 17 * * 0'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- 'ocaml-general/**'
- '!ocaml-general/README.md'
- '.github/workflows/ocaml-general.yml'
merge_group:
jobs:
validate-ocaml-general:
strategy:
matrix:
ocaml-version:
- 4.13.1
- 5.0.0
- 5.1.0
arch:
- amd64
# - arm64 # it's taking too long for the purpose of validation
node-version:
- iron # v18 Active LTS
os:
- ubuntu.22.04
env:
DOCKER_TAG: ${{ matrix.os }}-ocaml.${{ matrix.ocaml-version }}-node.${{ matrix.node-version }}-${{ matrix.arch }}
CACHE_DIR: /tmp/docker-cache
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up env var
run: echo "PACKAGE_INSTALL_SCRIPT_FILENAME=install_ocaml_$(eval cut -d'.' -f1-2 <<< ${{ matrix.ocaml-version }})_packages.sh" | tee -a $GITHUB_ENV
- name: Set up QEMU for arm64
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- run: mkdir -p ${{ env.CACHE_DIR }}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: ${{ env.CACHE_DIR }}
key: ${{ runner.os }}-buildx-${{ matrix.arch }}-${{ env.DOCKER_TAG }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.arch }}-${{ env.DOCKER_TAG }}
${{ runner.os }}-buildx-${{ matrix.arch }}-
- name: Validation Docker Build (${{ env.DOCKER_TAG }})
uses: docker/build-push-action@v4
with:
context: ocaml-general
push: false
platforms: linux/${{ matrix.arch }}
build-args: |
NODE_VERSION=${{ matrix.node-version }}
OCAML_VERSION=${{ matrix.ocaml-version }}
PACKAGE_INSTALL_SCRIPT_FILENAME=${{ env.PACKAGE_INSTALL_SCRIPT_FILENAME }}
cache-from: type=local,src=${{ env.CACHE_DIR }}/.buildx-cache
cache-to: type=local,dest=${{ env.CACHE_DIR }}/.buildx-cache-new,mode=max
- name: Move cache
run: |
cd ${{ env.CACHE_DIR }}
rm -rf .buildx-cache
mv .buildx-cache-new .buildx-cache
ocaml-general-validated:
needs: validate-ocaml-general
runs-on: ubuntu-latest
steps:
- run: echo "all clear"
build-deploy-ocaml-general:
needs: validate-ocaml-general
strategy:
matrix:
ocaml-version:
- 4.13.1
- 4.14.1
- 5.0.0
- 5.1.0
arch:
- amd64
- arm64
node-version:
- hydrogen # v18 Active LTS
- iron # v20 Active LTS
- latest
os:
- ubuntu.22.04
env:
DOCKER_TAG: ${{ matrix.os }}-ocaml.${{ matrix.ocaml-version }}-node.${{ matrix.node-version }}-${{ matrix.arch }}
CACHE_DIR: /tmp/docker-cache
PACKAGE_NAME: ghcr.io/kxcinc/ocaml-general
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up env var
run: |
echo "PACKAGE_INSTALL_SCRIPT_FILENAME=install_ocaml_$(eval cut -d'.' -f1-2 <<< ${{ matrix.ocaml-version }})_packages.sh" | tee -a $GITHUB_ENV
echo "DOCKER_TAG_LIST=${{ env.PACKAGE_NAME }}:${{ env.DOCKER_TAG }},${{ env.PACKAGE_NAME }}:${{ env.DOCKER_TAG }}-${{ github.sha }}" | tee -a $GITHUB_ENV | tr '=,' '\n' | sort
- name: Set up env var for alias (node iron && arch amd64)
if: ${{ matrix.node-version == 'iron' && matrix.arch == 'amd64' }}
run: echo "DOCKER_TAG_LIST=${{ env.DOCKER_TAG_LIST }},${{ env.PACKAGE_NAME }}:${{ matrix.ocaml-version }},${{ env.PACKAGE_NAME }}:${{ matrix.ocaml-version }}-${{ github.sha }}" | tee -a $GITHUB_ENV | tr '=,' '\n' | sort
- name: Set up QEMU for arm64
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# https://github.com/docker/build-push-action/issues/761#issuecomment-1575006515
# https://github.com/kxcinc/pubinfra.dockerfiles/issues/37
with:
driver-opts: |
image=moby/buildkit:v0.10.6
- run: mkdir -p ${{ env.CACHE_DIR }}
- name: Restore Docker Layers Cache
if: github.event.schedule == null
uses: actions/cache/restore@v3
with:
path: ${{ env.CACHE_DIR }}
key: ${{ runner.os }}-buildx-${{ matrix.arch }}-${{ env.DOCKER_TAG }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.arch }}-${{ env.DOCKER_TAG }}
${{ runner.os }}-buildx-${{ matrix.arch }}-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image (${{ env.DOCKER_TAG }})
uses: docker/build-push-action@v4
with:
context: ocaml-general
push: ${{ github.ref == 'refs/heads/main' }}
platforms: linux/${{ matrix.arch }}
build-args: |
NODE_VERSION=${{ matrix.node-version }}
OCAML_VERSION=${{ matrix.ocaml-version }}
PACKAGE_INSTALL_SCRIPT_FILENAME=${{ env.PACKAGE_INSTALL_SCRIPT_FILENAME }}
tags: ${{ env.DOCKER_TAG_LIST }}
cache-from: type=local,src=${{ env.CACHE_DIR }}/.buildx-cache
cache-to: type=local,dest=${{ env.CACHE_DIR }}/.buildx-cache-new,mode=max
- name: Move cache
run: |
cd ${{ env.CACHE_DIR }}
rm -rf .buildx-cache
mv .buildx-cache-new .buildx-cache
- name: Store Docker Layers Cache
if: ${{ matrix.ocaml-version == '5.1.0' && matrix.node-version == 'iron' }}
uses: actions/cache/save@v3
with:
path: ${{ env.CACHE_DIR }}
key: ${{ runner.os }}-buildx-${{ matrix.arch }}-${{ env.DOCKER_TAG }}-${{ github.sha }}
ocaml-general-matrix-checked:
needs: build-deploy-ocaml-general
runs-on: ubuntu-latest
steps:
- run: echo "all clear"