aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/action.yml
blob: eae186102d24dd38eee3d224bf5de7d27c1b9e81 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Install Cygwin
description: Install Cygwin & packages

inputs:
  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
  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

        if (!$windows_host) {
            throw "Sorry, installing Cygwin is unsupported on $os"
        }
      shell: pwsh

    - run: |
        echo 'CYGWIN=${{ inputs.env }}' >> $env:GITHUB_ENV
      shell: pwsh

    - run: |
        New-Variable install_dir -Value '${{ inputs.install-dir }}' -Option Constant
        New-Variable packages -Value '${{ inputs.packages }}' -Option Constant

        function Locate-Choco {
            $path = Get-Command 'choco' -ErrorAction SilentlyContinue
            if ($path) {
                $path.Path
            } else {
                Join-Path ${env:ProgramData} 'chocolatey' 'bin' 'choco'
            }
        }

        $choco = Locate-Choco

        # WTF? Chocolatey versions past 1.1.0 don't work with --source=cygwin,
        # they simply don't install anything.
        # TODO: file a bug upstream.
        & $choco install chocolatey --version 1.1.0 --allow-downgrade -y --no-progress

        $choco_params = @(
            'upgrade',
            'cygwin',
            '-y',
            '--no-progress',
            "--package-parameters='/InstallDir:$install_dir'"
        )
        # 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 $pkg_list -y --no-progress --source=cygwin
        }
      shell: pwsh

    - run: |
        New-Variable install_dir -Value '${{ inputs.install-dir }}' -Option Constant
        New-Variable hardlinks -Value ('${{ inputs.hardlinks }}' -eq '1') -Option Constant

        if ($hardlinks) {
            New-Variable bash -Value (Join-Path $install_dir bin bash.exe) -Option Constant
            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
        }
      shell: pwsh

branding:
  icon: star
  color: green