name: Build

on:
  push:
    branches: ['master']
  schedule:
    - cron: '20 2 * * *'

jobs:
  build-amd64-linux:
    runs-on: nix-amd64

    steps:
    - uses: actions/checkout@v4
      with:
        ref: master
    - name: Cache Login
      run: |
        echo "Logging in ..."
        attic login --set-default attic ${{ secrets.ATTIC_ENDPOINT }} ${{ secrets.ATTIC_TOKEN }}
    - name: Build anonymous-overflow
      run: |
        nix build '.#anonymous-overflow'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build bulk-downloader-for-reddit
      run: |
        nix build '.#bulk-downloader-for-reddit'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build controld
      run: |
        nix build '.#controld'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build discord-downloader-go
      run: |
        nix build '.#discord-downloader-go'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build fennel-ls
      run: |
        nix build '.#fennel-ls'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build headscale-ui
      run: |
        nix build '.#headscale-ui'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build q
      run: |
        nix build '.#q'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build tg-archive
      run: |
        nix build '.#tg-archive'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build vuetorrent
      run: |
        nix build '.#vuetorrent'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build weewx
      run: |
        nix build '.#weewx'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')

  build-arm64-linux:
    runs-on: nix-arm64

    steps:
    - uses: actions/checkout@v4
      with:
        ref: master
    - name: Cache Login
      run: |
        echo "Logging in ..."
        attic login --set-default attic ${{ secrets.ATTIC_ENDPOINT }} ${{ secrets.ATTIC_TOKEN }}
    - name: Build controld
      run: |
        nix build '.#controld'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build fennel-ls
      run: |
        nix build '.#fennel-ls'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build q
      run: |
        nix build '.#q'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')
    - name: Build weewx-proxy
      run: |
        nix build '.#weewx-proxy'
        attic push ${{ secrets.ATTIC_CACHE }} $(nix-store -qR --include-outputs $(nix-store -qd ./result) | grep -v '\.drv$')