-
Notifications
You must be signed in to change notification settings - Fork 15
187 lines (168 loc) · 6.49 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
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
name: Formal Ledger Specs
on: [push]
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: |
sudo apt-get update
- name: Free disk space
uses: jlumbroso/free-disk-space@main
with:
android: true
dotnet: true
haskell: false
large-packages: false
docker-images: true
swap-storage: true
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
substituters = https://cache.nixos.org/
- name: Restore store
id: cache-store-restore
uses: actions/cache/restore@v3
with:
path: |
store
derivations
key: cache-store-${{ runner.os }}-${{github.run_id}}
restore-keys: |
cache-store-${{ runner.os }}
- name: Import cached nix store
continue-on-error: true
run: |
if [[ -f store ]]; then
du -sh store || true
nix-store --import < store
else
echo "No cached store found"
fi
# We have to build this explicitly, in order to cache it,
# since it's not part of the static binary formalLedger closure
- name: Build agda
id: agda
run: |
d=$(nix-build -A agdaWithStdLibMeta)
dRet=$(echo "$d" | tr '\n' ' ')
closure=$(nix-store --query --requisites --include-outputs $dRet)
cRet=$(echo "$closure" | tr '\n' ' ')
echo "derivation=$dRet" >> $GITHUB_OUTPUT
echo "closure=$cRet" >> $GITHUB_OUTPUT
- name: Build formalLedger
id: formalLedger
run: |
d=$(nix-build -A formalLedger)
dRet=$(echo "$d" | tr '\n' ' ')
closure=$(nix-store --query --requisites --include-outputs $dRet)
cRet=$(echo "$closure" | tr '\n' ' ')
echo "derivation=$dRet" >> $GITHUB_OUTPUT
echo "closure=$cRet" >> $GITHUB_OUTPUT
- name: Build ledger
id: ledger
run: |
mkdir -p outputs
d=$(nix-build -A ledger -j1 -o outputs/ledger)
dRet=$(echo "$d" | tr '\n' ' ')
closure=$(nix-store --query --requisites --include-outputs $dRet)
cRet=$(echo "$closure" | tr '\n' ' ')
echo "derivation=$dRet" >> $GITHUB_OUTPUT
echo "closure=$cRet" >> $GITHUB_OUTPUT
- name: Build midnight
id: midnight
run: |
d=$(nix-build -A midnight -j1 -o outputs/midnight)
dRet=$(echo "$d"| tr '\n' ' ')
closure=$(nix-store --query --requisites --include-outputs $dRet)
cRet=$(echo "$closure" | tr '\n' ' ')
echo "derivation=$dRet" >> $GITHUB_OUTPUT
echo "closure=$cRet" >> $GITHUB_OUTPUT
- name: Export all derivations
id: export-derivations
run: |
hashes="${{steps.agda.outputs.derivation}}-${{steps.formalLedger.outputs.derivation}}-${{steps.ledger.outputs.derivation}}-${{steps.midnight.outputs.derivation}}"
closures="${{steps.agda.outputs.closure}} ${{steps.formalLedger.outputs.closure}} ${{ steps.ledger.outputs.closure}} ${{steps.midnight.outputs.closure}}"
touch derivations
updated=false
# export only if the hashes changed or the store does not exist for some reason
if grep -qe "^$hashes" derivations && [[ -f store ]]
then
echo "No need to re-export the store"
else
nix-store --export $closures > store
echo "Exported store of size: $(du -sh store)"
echo "$hashes" > derivations
echo "Wrote new derivations hashes: $(cat derivations)"
updated=true
fi
echo "updated=$updated" >> $GITHUB_OUTPUT
- name: Upload nix store
id: cache-derivations-save
uses: actions/cache/save@v3
if: steps.export-derivations.outputs.updated == 'true'
with:
path: |
store
derivations
key: cache-store-${{ runner.os }}-${{github.run_id}}
- name: Prepare pdf files to be deployed to site
if: github.ref == 'refs/heads/master'
run: |
mkdir -p pdfs
for f in $(find -L outputs -name '*.pdf'); do
cp -L --force $f pdfs
done
- name: Prepare html docs to be deployed to site
if: github.ref =='refs/heads/master'
id: html
run: |
mkdir -p html
cp -L -r outputs/ledger/html html/ledger
cp -L -r outputs/midnight/html html/midnight
ledger=$(nix eval -f default.nix "ledger.name")
midnight=$(nix eval -f default.nix "midnight.name")
echo "ledger=$ledger" >> $GITHUB_OUTPUT
echo "midnight=$midnight" >> $GITHUB_OUTPUT
- name: Build static file
if: github.ref == 'refs/heads/master'
run: |
ledger="${{steps.html.outputs.ledger}}.PDF.html"
midnight="${{steps.html.outputs.midnight}}.PDF.html"
touch index.html
cat > index.html << EOF
<!DOCTYPE html>
<html>
<body>
<h3>Formal ledger specs</h3>
<ul>
EOF
for f in pdfs/*.pdf; do
echo "<li><a href="$f">$(basename $f)</a></li>" >> index.html
done
echo "<li><a href="html/ledger/${ledger}">${ledger}</a></li>" >> index.html
echo "<li><a href="html/midnight/${midnight}">${midnight}</a></li>" >> index.html
cat >> index.html << EOF
</ul>
</body>
</html>
EOF
- name: Add files
if: github.ref == 'refs/heads/master'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add -f index.html pdfs/ html/
git commit -m "Updated for ${{ github.sha }}"
- name: Push to gh-pages
if: github.ref == 'refs/heads/master'
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
force: true
directory: .