forked from nix-community/nix-index-database
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (118 loc) · 4.43 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
name: "index-generate"
on:
workflow_dispatch:
schedule:
# every sunday at 2:51
- cron: '51 2 * * 0'
jobs:
index:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
indexName: x86_64-linux
# - os: macos-latest
# indexName: x86_64-darwin
name: Build database
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v21
with:
nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/release-23.11.tar.gz
- name: run nix-index
run: nix-shell -p nix-index --command "nix-index --db ./${{ matrix.indexName }}-index 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
steps:
- name: download linux artifact
uses: actions/download-artifact@v3
with:
name: x86_64-linux
path: linux-index
- run: mv linux-index/files index-x86_64-linux
# - name: download darwin artifact
# uses: actions/download-artifact@v3
# with:
# name: x86_64-darwin
# path: darwin-index
# - run: mv darwin-index/files index-x86_64-darwin
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- 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-x86_64-darwin
files: |
index-x86_64-linux
update-flake:
runs-on: ubuntu-latest
needs: upload-index
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v21
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: prefetch linux index
id: prefetch-linux
run: echo "::set-output name=hash::$(nix shell nixpkgs#nix-prefetch -c nix-prefetch-url https://github.com/${{ github.repository }}/releases/download/${{ steps.date.outputs.date }}/index-x86_64-linux)"
# - name: prefetch darwin index
# id: prefetch-darwin
# run: echo "::set-output name=hash::$(nix shell nixpkgs#nix-prefetch -c nix-prefetch-url https://github.com/${{ github.repository }}/releases/download/${{ steps.date.outputs.date }}/index-x86_64-darwin)"
- name: overwrite flake.nix
# run: |
# cat > flake.nix << EOF
# # this file is autogenerated by .github/workflows/update.yml
# {
# description = "nix-index database";
# outputs = _:
# {
# legacyPackages.x86_64-linux.database = builtins.fetchurl {
# url = "https://github.com/${{ github.repository }}/releases/download/${{ steps.date.outputs.date }}/index-x86_64-linux";
# sha256 = "${{ steps.prefetch-linux.outputs.hash }}";
# };
# legacyPackages.x86_64-darwin.database = builtins.fetchurl {
# url = "https://github.com/${{ github.repository }}/releases/download/${{ steps.date.outputs.date }}/index-x86_64-darwin";
# sha256 = "${{ steps.prefetch-darwin.outputs.hash }}";
# };
# };
# }
# EOF
run: |
cat > flake.nix << EOF
# this file is autogenerated by .github/workflows/update.yml
{
description = "nix-index database for NixOS stable";
outputs = _:
{
legacyPackages.x86_64-linux.database = builtins.fetchurl {
url = "https://github.com/${{ github.repository }}/releases/download/${{ steps.date.outputs.date }}/index-x86_64-linux";
sha256 = "${{ steps.prefetch-linux.outputs.hash }}";
};
};
}
EOF
- name: commit and push flake.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 flake.nix
git commit -m "update flake.nix to release ${{ steps.date.outputs.date }}"
git push origin HEAD:main
fi