Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
388 stars 177 forks source link

[Issue/enhancement] Cross-platform shell commands behavior #3613

Open sinedied opened 3 months ago

sinedied commented 3 months ago

Output from azd version Run azd version and copy and paste the output here: azd version 1.7.0 (commit 49d6adc2efb178083f61822e6b4715258560803d)

Describe the bug When defining scripts, we currently use yaml like this:

hooks:
  predeploy:
    windows:
      shell: pwsh
      run: Export-ModuleMember -Variable API_URL && npm run build
    posix:
      shell: sh
      run: export API_URL && npm run build

This separate the commands to run into two categories: execution for posix-systems (Linux/Mac), and Windows.

The issue is that the distinction is not clear at all, and even misleading:

These issues could be cleared by using a simpler script definition based on the shell name, similar to how it works in GitHub Actions:

hooks:
  predeploy:
    pwsh:
      run: Export-ModuleMember -Variable API_URL && npm run build
    bash:
      run: export API_URL && npm run build

Instead of discriminating the system (which makes no sense when using WSL or Git Bash), we could just specify which shell to use. The logic could be:

  1. Try to run the first specified shell in the list (in this example, pwsh). Test could be simply running <shell> --version and see if it fails.
  2. If the shell is available run the script, otherwise continue testing with the next shell option.

You could even make the shell specification optional, and use whatever default shell is available on the system for simple commands, for example:

hooks:
  predeploy:
    run: npm run build

It would even be possible to support the new syntax and keep the old deprecated syntax for backward compatibility with existing azure.yaml configurations.

What do you think about this proposal?

seesharprun commented 2 weeks ago

I support this suggestion. There are situations where specifying the shell makes sense, but it creates a hidden prerequisite.

For example, I had a colleague who could not deploy an AZD template, and we spent some time debugging before we figured out that they did not have PowerShell 7 installed on their Windows machine. From their perspective, there was nothing in the code sample or AZD documentation that said you must have PowerShell 7 installed (pwsh) to use the AZD template.