actions/.github/workflows/format-nix.yml

52 lines
1.4 KiB
YAML

name: format
on:
workflow_call:
inputs:
ci_mode:
description: "Run treefmt with --ci (fail if changes needed)"
type: string
required: false
default: "true"
commit_changes:
description: "Commit changes if formatting is needed (only if ci_mode is false)"
type: string
required: false
default: "false"
jobs:
treefmt:
timeout-minutes: 15
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: checkout code
uses: actions/checkout@v4
- name: install nix
uses: cachix/install-nix-action@v31.6.1
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v16
with:
name: nix-community
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- name: debug inputs
run: |
echo "ci_mode: ${{ inputs.ci_mode }}"
echo "commit_changes: ${{ inputs.commit_changes }}"
- name: treefmt
run: |
if [ "${{ inputs.ci_mode }}" = "true" ]; then
nix fmt -- --ci
else
nix fmt
fi
- name: commit changes
if: ${{ inputs.ci_mode == 'false' && inputs.commit_changes == 'true' }}
uses: stefanzweifel/git-auto-commit-action@v6.0.1
with:
commit_message: |
style: autoformatting all ${{ inputs.language }} files
[skip ci]