index-generate #228
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@V27 | |
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@V27 | |
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.indexName }}-index --system ${{matrix.indexName}} 2>&1 | grep -v '+ generating index:' | |
- name: upload artifact | |
uses: actions/upload-artifact@v4 | |
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@v4 | |
with: | |
name: x86_64-linux | |
path: x86_64-linux-index | |
- name: download aarch64-linux artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: aarch64-linux | |
path: aarch64-linux-index | |
- name: download x86_64-darwin artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: x86_64-darwin | |
path: x86_64-darwin-index | |
- name: download aarch64-darwin artifact | |
uses: actions/download-artifact@v4 | |
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@v2 | |
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@V27 | |
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 | |
let | |
fetchurl = import <nix/fetchurl.nix>; | |
in | |
{ | |
x86_64-linux.database = 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 = 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 = 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 = 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 |