name: "Update Flake Packages"

permissions:
  contents: write
  pull-requests: write

on:
  pull_request:
    branches: [main]
    types: [labeled]
  schedule:
    - cron: "0 10 * * 0" # https://crontab.guru/#0_10_*_*_0

jobs:
  build:
    if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'rebuild nix')
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install Nix
        uses: DeterminateSystems/nix-installer-action@main
        with:
          trust-runner-user: true

      - name: Set up cache
        uses: cachix/cachix-action@v15
        with:
          name: winapps
          authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"

      - name: Update flake packages
        uses: winapps-org/nix-update-action@v1.4.0
        with:
          extra-args: --version=branch
          skip-pr: "${{ github.event_name == 'pull_request' }}"

      - name: Build packages
        run: nix build .#winapps .#winapps-launcher
