name: 'Nix Flake Outputs Size Report'
author: Jalil David Salamé Messina
description: |
  Use `nix path-info` to query the size of flake outputs and produce a markdown
  report.

  You can post this report as a comment to the PR associated with the current
  branch and/or export the report as a JSON artifact.

  Requires `nix`, `jq`, `curl`, `sed`, `gunzip`, `tar` and `coreutils` to be in
  the runner's path.

  Usage:

  ```yaml
  - name: Generate size report
    uses: https://git.salame.cl/jalil/nix-flake-outputs-size@main
    with: # Default values
      comment-on-pr: 'true'
      generate-artifact: 'false'
      artifact-name: 'size-report.md'
      # If you want to enable comparisons set this to true
      do-comparison: 'false'
      job-name: '' # required if do-comparison is true
      # This is the branch that will be compared against
      base-branch: ${{ github.base_ref }} # or default branch if missing
  ```
inputs:
  comment-on-pr:
    description: |
      Comment the report on the PR associated with the current branch.

      This is a no-op in case no PR is associated with the current branch.
    default: 'true'
  system:
    description: |
      The nix system name to query the packages of (e.g. x86_64-linux)
  # Generate workflow artifact
  generate-artifact:
    description: Export the generated markdown document as a workflow artifact.
    default: 'false'
  artifact-name:
    description: The name of the generated artifact.
    default: report.json
  # Comparison Report (comment only)
  do-comparison:
    description: |
      When commenting on the PR compare the results with those in the base branch.

      This is a no-op when `comment-on-pr: false`.

      It requires `job-name` to be set.
    default: 'false'
  job-name:
    description: |
      The name of the job running this action. If not set, no comparisons can
      be made.
    default: ''
  base-branch:
    description: |
      The name of the base branch, defaults to `github.base_ref` if present
      (when triggered by a `pull_request`). Otherwise defaults to the repo's
      default branch. Set in case you want to override this behaviour.

      It will try to download the generated artifact from this branch so make
      sure `generate-artifacte: true` when the workflow is running on that
      branch.
    default: ${{ github.base_ref }}
outputs:
runs:
  using: 'nodejs20'
  main: dist/index.js
