twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.85k stars 477 forks source link

Can't use a github action to verify script because prompt requires `TTY` #2595

Closed arran4 closed 1 year ago

arran4 commented 1 year ago

Describe the bug

I am trying to use this github action:

name: CI

on: 
  push:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - run: |
          yes "" | sh -c "$(curl -fsLS get.chezmoi.io)" -- init --debug --force --apply arran4

To verify the script as I often put changes directly in github

However I get this error:

chezmoi: template: chezmoi.toml:7:17: executing "chezmoi.toml" at <promptBool "headless" $headlessGuess>: error calling promptBool: open /dev/tty: no such device or address

https://github.com/arran4/dotfiles/actions/runs/3528532579/jobs/5918736477

However I believe that my defaults are sane and I just want it to accept my defaults, hence the:

          yes "" | 

At the start of the script.

I am not sure what flags - if there is one - would allow me tell it to "accept all defaults"

To reproduce

Run:

name: CI

on: 
  push:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - run: |
          yes "" | sh -c "$(curl -fsLS get.chezmoi.io)" -- init --debug --force --apply arran4

In a github action

Expected behavior

Errors that actually relate to errors in my script. Hence why I have avoided:

  -k, --keep-going                     Keep going as far as possible after an error

As by the sounds of it, it might ignore errors I want to pick up on

Output of command with the --verbose flag

n/a

Output of chezmoi doctor

n/a

Additional context

n/a

twpayne commented 1 year ago

You have at least two options:

  1. Use the --no-tty flag to specify that stdin is not a TTY and should be treated as a normal file instead.

  2. Use the stdinIsATTY template function in your config file template to determine whether stdin is a TTY and use defaults if it is not.

arran4 commented 1 year ago
      --no-tty                         Do not attempt to get a TTY for reading passwords

Ah thanks. You're right. On mine I ignored it as it says passwords.