-
-
Notifications
You must be signed in to change notification settings - Fork 34
192 lines (189 loc) · 7.55 KB
/
update.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
name: "index-generate"
on:
workflow_dispatch:
schedule:
# every sunday at 2:51
- cron: '51 2 * * 0'
jobs:
update-lock:
runs-on: ubuntu-latest
name: Update flake.lock
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz
extra_nix_config: |
access-tokens = github.com=${{ github.token }}
system-features = nixos-test benchmark big-parallel kvm
- name: Update the flake lock
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
nix flake update --commit-lock-file
git push origin HEAD:main
index:
runs-on: ubuntu-latest
needs: update-lock
strategy:
matrix:
include:
- indexName: x86_64-linux
- indexName: aarch64-linux
# breaks often and no one fixes it
- indexName: x86_64-darwin
- indexName: aarch64-darwin
name: Build database
steps:
- uses: actions/checkout@v4
- name: Swap space report before modification
shell: bash
run: |
echo "Memory and swap:"
free -h
echo
swapon --show
echo
- name: Set Swap
shell: bash
run: |
export SWAP_FILE=$(swapon --show=NAME | tail -n 1)
sudo swapoff $SWAP_FILE
sudo rm $SWAP_FILE
sudo fallocate -l 10G $SWAP_FILE
sudo chmod 600 $SWAP_FILE
sudo mkswap $SWAP_FILE
sudo swapon $SWAP_FILE
- name: Swap space report after modification
shell: bash
run: |
echo "Memory and swap:"
free -h
echo
swapon --show
echo
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixpkgs-unstable.tar.gz
extra_nix_config: |
access-tokens = github.com=${{ github.token }}
system-features = nixos-test benchmark big-parallel kvm
# for nix-index
- name: Setup cachix
uses: cachix/cachix-action@v12
with:
name: mic92
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- name: run nix-index
run: nix shell --inputs-from .# nixpkgs#nix-index -c nix-index --db ./${{ matrix.indexName }}-index --system ${{matrix.indexName}} 2>&1 | grep -v '+ generating index:'
- name: upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.indexName }}
path: ./${{ matrix.indexName }}-index
upload-index:
runs-on: ubuntu-latest
needs: index
outputs:
release_name: ${{ steps.date.outputs.date }}
steps:
- name: download x86_64-linux artifact
uses: actions/download-artifact@v3
with:
name: x86_64-linux
path: x86_64-linux-index
- name: download aarch64-linux artifact
uses: actions/download-artifact@v3
with:
name: aarch64-linux
path: aarch64-linux-index
- name: download x86_64-darwin artifact
uses: actions/download-artifact@v3
with:
name: x86_64-darwin
path: x86_64-darwin-index
- name: download aarch64-darwin artifact
uses: actions/download-artifact@v3
with:
name: aarch64-darwin
path: aarch64-darwin-index
- run: |
mv x86_64-linux-index/files index-x86_64-linux
mv aarch64-linux-index/files index-aarch64-linux
mv x86_64-darwin-index/files index-x86_64-darwin
mv aarch64-darwin-index/files index-aarch64-darwin
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d-%H%M%S')" >> ${GITHUB_OUTPUT}
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Release ${{ steps.date.outputs.date }}
tag_name: ${{ steps.date.outputs.date }}
files: |
index-x86_64-linux
index-aarch64-linux
index-x86_64-darwin
index-aarch64-darwin
update-flake:
runs-on: ubuntu-latest
needs: upload-index
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.ref_name }}"
- uses: cachix/install-nix-action@v23
with:
extra_nix_config: 'access-tokens = github.com=${{ github.token }}'
- name: prefetch x86_64-linux index
id: prefetch-x86_64-linux
run: echo "hash=$(nix shell nixpkgs#nix-prefetch -c nix-prefetch-url https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-x86_64-linux)" >> ${GITHUB_OUTPUT}
- name: prefetch aarch64-linux index
id: prefetch-aarch64-linux
run: echo "hash=$(nix shell nixpkgs#nix-prefetch -c nix-prefetch-url https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-aarch64-linux)" >> ${GITHUB_OUTPUT}
- name: prefetch x86_64-darwin index
id: prefetch-x86_64-darwin
run: echo "hash=$(nix shell nixpkgs#nix-prefetch -c nix-prefetch-url https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-x86_64-darwin)" >> ${GITHUB_OUTPUT}
- name: prefetch aarch64-darwin index
id: prefetch-aarch64-darwin
run: echo "hash=$(nix shell nixpkgs#nix-prefetch -c nix-prefetch-url https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-aarch64-darwin)" >> ${GITHUB_OUTPUT}
- name: overwrite flake.nix
run: |
cat > packages.nix << EOF
# this file is autogenerated by .github/workflows/update.yml
{
x86_64-linux.database = builtins.fetchurl {
url = "https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-x86_64-linux";
sha256 = "${{ steps.prefetch-x86_64-linux.outputs.hash }}";
};
aarch64-linux.database = builtins.fetchurl {
url = "https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-aarch64-linux";
sha256 = "${{ steps.prefetch-aarch64-linux.outputs.hash }}";
};
x86_64-darwin.database = builtins.fetchurl {
url = "https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-x86_64-darwin";
sha256 = "${{ steps.prefetch-x86_64-darwin.outputs.hash }}";
};
aarch64-darwin.database = builtins.fetchurl {
url = "https://github.com/${{ github.repository }}/releases/download/${{ needs.upload-index.outputs.release_name }}/index-aarch64-darwin";
sha256 = "${{ steps.prefetch-aarch64-darwin.outputs.hash }}";
};
}
EOF
- name: test if flake works
run: |
nix flake show --all-systems
# We don't want to build the checks since we don't have virtualisation support on github runners
nix flake check -L --all-systems --no-build
- name: commit and push packages.nix, if it changed
run: |
if [[ "$(git status --porcelain)" != "" ]]; then
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add packages.nix
git commit -m "update packages.nix to release ${{ needs.upload-index.outputs.release_name }}"
git push origin HEAD:main
fi