-
-
Notifications
You must be signed in to change notification settings - Fork 34
150 lines (145 loc) · 5.23 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
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@v30
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
create-release:
runs-on: ubuntu-latest
name: Create Release
needs: update-lock
outputs:
release_name: ${{ steps.date.outputs.date }}
steps:
- 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@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Release ${{ steps.date.outputs.date }}
tag_name: ${{ steps.date.outputs.date }}
index:
runs-on: ubuntu-latest
needs: create-release
strategy:
matrix:
system: ['x86_64-linux', 'aarch64-linux', 'x86_64-darwin', 'aarch64-darwin']
name: Build database
outputs:
x86_64-linux-hash: ${{ steps.hashes.outputs.x86_64-linux }}
x86_64-darwin-hash: ${{ steps.hashes.outputs.x86_64-darwin }}
aarch64-linux-hash: ${{ steps.hashes.outputs.aarch64-linux }}
aarch64-darwin-hash: ${{ steps.hashes.outputs.aarch64-darwin }}
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@v30
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@v15
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.system }}-index --system ${{matrix.system}} 2>&1 | grep -v '+ generating index:'
mv ./${{ matrix.system }}-index/files ./index-${{ matrix.system }}
- name: hash index
id: hashes
run: |
echo "${{ matrix.system }}=$(nix store prefetch-file "file://$PWD/index-${{ matrix.system }}" --json | jq -r .hash)" >> "$GITHUB_OUTPUT"
- name: Add to release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.create-release.outputs.release_name }}
files: index-${{ matrix.system }}
update-generated:
runs-on: ubuntu-latest
needs: [ 'create-release', 'index']
steps:
- uses: actions/checkout@v4
with:
ref: "${{ github.ref_name }}"
- uses: cachix/install-nix-action@v30
with:
extra_nix_config: 'access-tokens = github.com=${{ github.token }}'
- name: update database.nix
run: |
cat > generated.nix << EOF
# this file is autogenerated by .github/workflows/update.yml
{
url = "https://github.com/${{ github.repository }}/releases/download/${{ needs.create-release.outputs.release_name }}/index-";
hashes = {
x86_64-linux = "${{ needs.index.outputs.x86_64-linux-hash }}";
aarch64-linux = "${{ needs.index.outputs.aarch64-linux-hash }}";
x86_64-darwin = "${{ needs.index.outputs.x86_64-darwin-hash }}";
aarch64-darwin = "${{ needs.index.outputs.aarch64-darwin-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 generated.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 generated.nix
git commit -m "update generated.nix to release ${{ needs.create-release.outputs.release_name }}"
git push origin HEAD:main
fi