-
Notifications
You must be signed in to change notification settings - Fork 7
183 lines (155 loc) · 5.7 KB
/
workflow.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
name: Main workflow
on: [push, pull_request]
jobs:
create_draft_release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_draft_release.outputs.upload_url }}
steps:
- name: Create draft release on tags
id: create_draft_release
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: true
prerelease: false
build:
needs: create_draft_release
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
ocaml-version:
- 4.12.x
include:
- os: macos-latest
suffix: x86_64-apple-darwin
- if: ${{ !startsWith(github.ref, 'refs/tags/') }}
os: ubuntu-latest
suffix: x86_64-unknown-linux-gnu
- os: windows-latest
suffix: x86_64-pc-windows-gnu
env:
OCAML_VERSION: ${{ matrix.ocaml-version }}
OS: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use OCaml ${{ matrix.ocaml-version }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-version }}
dune-cache: true
- name: Set git user
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
- name: Define env (unix)
if: ${{ runner.os != 'Windows' }}
run: |
echo "GITHUB_TAG=$(git describe --always --tags)" >> $GITHUB_ENV
echo "OPAMJOBS=1" >> $GITHUB_ENV
- name: Define env (windows)
if: ${{ runner.os == 'Windows' }}
run: |
echo "GITHUB_TAG=$(git describe --always --tags)" >> $GITHUB_ENV
echo "OPAMJOBS=1" >> $GITHUB_ENV
- name: Install dependencies
if: ${{ !startsWith(runner.os, 'Mac') }}
run: |
opam depext tls decompress
opam install tls decompress
- name: Build project
run: |
opam install --deps-only .
opam exec -- dune build -p doi2bib
- name: Check code formatting
if: ${{ success() && startsWith(runner.os, 'Linux') }}
run: |
opam install ocamlformat
opam exec -- dune build @fmt
- name: Run tests
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: opam exec -- dune runtest
- name: Build
run: opam exec -- dune build -p doi2bib
- name: Create release archive
if: ${{ startsWith(github.ref, 'refs/tags/') && !startsWith(runner.os, 'Win') }}
run: opam exec -- tar czf release.tar.gz -C _build/default/bin/ doi2bib.exe
- name: Create release archive (Windows)
if: ${{ startsWith(github.ref, 'refs/tags/') && startsWith(runner.os, 'Win') }}
run: |
opam exec -- dos2unix .github/scripts/win.sh
opam exec -- bash .github/scripts/win.sh
opam exec -- tar czf release.tar.gz out/
- name: Upload build artifact
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: actions/upload-artifact@v2
with:
path: release.tar.gz
name: doi2bib-${{ env.GITHUB_TAG }}-${{ matrix.suffix }}.tar.gz
if-no-files-found: error
- name: Upload release tarball
if: ${{ startsWith(github.ref, 'refs/tags/') }}
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_draft_release.outputs.upload_url }}
asset_path: release.tar.gz
asset_name: doi2bib-${{ env.GITHUB_TAG }}-${{ matrix.suffix }}.tar.gz
asset_content_type: application/zip
nix-build:
needs: create_draft_release
runs-on: ubuntu-latest
strategy:
matrix:
platform: [musl, arm64-musl]
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v18
with:
extra_nix_config: |
extra-substituters = https://anmonteiro.nix-cache.workers.dev
extra-trusted-public-keys = ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY=
- name: "Run nix-build"
run: nix build -L .#${{ matrix.platform }}
- name: Prepare env
if: ${{ success() }}
run: |
echo "GITHUB_TAG=$(git describe --always --tags)" >> $GITHUB_ENV
if [[ ${{ matrix.platform }} == "musl" ]]; then
echo "ARCH=x86_64" >> $GITHUB_ENV
else
echo "ARCH=arm64" >> $GITHUB_ENV
fi
- name: Create release archive
if: ${{ success() }}
run: tar czf release.tar.gz -C ./result/bin doi2bib
- name: Upload build artifact
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
uses: actions/upload-artifact@v2
with:
path: release.tar.gz
name: doi2bib-${{ env.GITHUB_TAG }}-${{ env.ARCH }}-unknown-linux-musl.tar.gz
if-no-files-found: error
- name: Upload release tarball
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }}
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_draft_release.outputs.upload_url }}
asset_path: release.tar.gz
asset_name: doi2bib-${{ env.GITHUB_TAG }}-${{ env.ARCH }}-unknown-linux-musl.tar.gz
asset_content_type: application/zip