index-generate #237
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 | |
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@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.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@V27 | |
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 |