Skip to content

index-generate

index-generate #113

Workflow file for this run

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