name: Install Cygwin description: Install Cygwin & packages inputs: platform: description: Target platform required: false default: x64 install-dir: description: Installation directory required: false default: C:\tools\cygwin packages: description: Packages to install, separated by a space required: false env: description: Value to set as the CYGWIN environment variable required: false symlinks-to-hardlinks: description: Convert symlinks in /usr/bin to hardlinks required: false default: 0 runs: using: composite steps: - run: | New-Variable os -Value ('${{ runner.os }}') -Option Constant New-Variable windows_host -Value ($os -eq 'Windows') -Option Constant New-Variable x64 -Value ('${{ inputs.platform }}' -eq 'x64') -Option Constant New-Variable install_dir -Value '${{ inputs.install-dir }}' -Option Constant New-Variable packages -Value '${{ inputs.packages }}' -Option Constant New-Variable symlinks_to_hardlinks -Value ('${{ inputs.symlinks-to-hardlinks }}' -eq '1') -Option Constant New-Variable bash -Value (Join-Path $install_dir bin bash.exe) -Option Constant function Locate-Choco { $path = Get-Command 'choco' -ErrorAction SilentlyContinue if ($path) { $path.Path } else { Join-Path ${env:ProgramData} 'chocolatey' 'bin' 'choco' } } if ($windows_host) { echo 'CYGWIN=${{ inputs.env }}' >> $env:GITHUB_ENV $choco = Locate-Choco $choco_params = @( 'install', '-y', '--no-progress', '--params', "/InstallDir:$install_dir" ) if (!$x64) { $choco_params += '--x86' } $choco_params += 'cygwin' # Assuming that Cygwin is not installed when this is run. & $choco $choco_params # /usr/bin is really just /bin on Cygwin. echo (Join-Path $install_dir bin) >> $env:GITHUB_PATH echo (Join-Path $install_dir usr local bin) >> $env:GITHUB_PATH $pkg_list = $packages.Split(' ', [System.StringSplitOptions]::RemoveEmptyEntries) if ($pkg_list.Count -gt 0) { & $choco install -y --no-progress --source=cygwin $pkg_list } if ($symlinks_to_hardlinks) { echo @' while IFS= read -d '' -r link_path; do dest_path="$( readlink --canonicalize-existing -- "$link_path" )" dest_ext=".${dest_path##*.}" [ "$dest_ext" == ".$dest_path" ] && dest_ext= link_ext=".${link_path##*.}" [ "$link_ext" == ".$link_path" ] && link_ext= echo "Removing symlink $link_path" && rm -f -- "$link_path" [ "$link_ext" != "$dest_ext" ] && echo "${PATHEXT//\;/ }" | grep -q --ignore-case --line-regexp -F -- "$dest_ext" && link_path="$link_path$dest_ext" echo "Creating hardlink $link_path -> $dest_path" && ln -- "$dest_path" "$link_path" done < <( find /usr/bin -type l -print0 ) '@ | & $bash --login -o errexit -o nounset -o pipefail -o igncr } } else { throw "Sorry, installing Cygwin is unsupported on $os" } shell: pwsh branding: icon: star color: green