forked from cygwin/cygwin-install-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
206 lines (181 loc) · 6.65 KB
/
action.yml
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Install Cygwin Action
description: GitHub Action to install Cygwin
inputs:
platform:
description: Platform [x86, x86_64]
required: false
default: x86_64
packages:
description: Packages to install
required: false
install-dir:
# For consistency and simplicity, install to <work-dir>:\cygwin rather
# than to the platform dependent default (e.g. <work-dir>:\cygwin64)
description: Installation directory (overrides work-vol)
required: false
default: ''
check-sig:
description: Should the setup.ini file signature be checked?
required: false
default: 'true'
pubkeys:
description: Absolute paths of extra public key files (RFC4880 format), separated by whitespace
required: false
site:
description: Download site URLs separated by whitespace
required: false
add-to-path:
description: Should Cygwin's bin directory be added to the system PATH?
required: false
default: 'true'
allow-test-packages:
description: Consider package versions marked test
required: false
default: 'false'
check-hash:
description: Check the hash of the installer
required: false
default: 'true'
work-vol:
description: Volume on which to store setup and packages, and install Cygwin
required: false
default: ''
runs:
using: "composite"
steps:
- run: |
$ErrorActionPreference = 'Stop'
$platform = '${{ inputs.platform }}'
$platform = $platform -replace '^(x64|amd64)$', 'x86_64'
$platform = $platform -replace '^i686$', 'x86'
# validate that platform is one of the expected values
if (($platform -ne 'x86') -and ($platform -ne 'x86_64')) {
throw "Unknown platform $platform."
}
$vol = '${{ inputs.work-vol }}'
# If temporary drive D: doesn't exist in the VM, fallback to C:
if ("$vol" -eq '') {
if (Test-Path -LiteralPath 'D:\') {
$vol = 'D:'
} else {
$vol = 'C:'
}
}
$setupExe = "$vol\setup.exe"
$setupFileName = "setup-$platform.exe"
function Invoke-WebRequest-With-Retry {
param (
$Uri,
$OutFile
)
$maxRetries = 5
$retryCount = 0
$success = $false
$delay = 2
while (-not $success -and $retryCount -lt $maxRetries) {
try {
Invoke-WebRequest -Uri $Uri -OutFile $OutFile
$success = $true
} catch [System.Net.WebException] {
Write-Output "Attempt $($retryCount + 1) failed. Retrying..."
Start-Sleep -Seconds $delay
$retryCount++
$delay += $delay
}
}
if (-not $success) {
throw "Failed to download $setupFileName after $maxRetries attempts."
}
}
Invoke-WebRequest-With-Retry "https://cygwin.com/$setupFileName" $setupExe
if ((Get-Item -LiteralPath $setupExe).Length -eq 0) {
throw "The downloaded setup has a zero length!"
}
if ('${{ inputs.check-hash }}' -eq 'true') {
$hashFile = "$vol\sha512.sum"
Invoke-WebRequest-With-Retry https://cygwin.com/sha512.sum $hashFile
$expectedHashLines = Get-Content $hashFile
$expectedHash = ''
foreach ($expectedHashLine in $expectedHashLines) {
if ($expectedHashLine.EndsWith(" $setupFileName")) {
$expectedHash = $($expectedHashLine -split '\s+')[0]
break
}
}
if ($expectedHash -eq '') {
Write-Output -InputObject "::warning::Unable to find the hash for the file $setupFileName in https://cygwin.com/sha512.sum"
} else {
$actualHash = $(Get-FileHash -LiteralPath $setupExe -Algorithm SHA512).Hash
if ($actualHash -ine $expectedHash) {
throw "Invalid hash of the downloaded setup!`nExpected: $expectedHash`nActual : $actualHash"
} else {
Write-Output -InputObject "The downloaded file has the expected hash ($expectedHash)"
}
}
}
$installDir = "$vol\cygwin"
if ('${{ inputs.install-dir }}' -ne '') {
$installDir = '${{ inputs.install-dir }}'
}
$packages = '${{ inputs.packages }}'
$pkg_list = $packages.Split('', [System.StringSplitOptions]::RemoveEmptyEntries)
$pkg_list = $pkg_list | % { $_.Trim() }
$pkg_list = $pkg_list | % { $_.Trim(',') }
$args = @(
'-qnO',
'-l', "$vol\cygwin-packages",
'-R', "$installDir"
)
if ( '${{ inputs.allow-test-packages }}' -eq 'true' ) {
$args += '-t' # --allow-test-packages
}
# default site if not specified
if ( '${{ inputs.site }}' ) {
$sites = '${{ inputs.site }}'
} elseif ($platform -eq 'x86') {
$sites = 'http://mirrors.kernel.org/sourceware/cygwin-archive/20221123'
} else {
$sites = 'http://mirrors.kernel.org/sourceware/cygwin/'
}
$site_list = $sites.Split('', [System.StringSplitOptions]::RemoveEmptyEntries)
$site_list = $site_list | % { $_.Trim() }
foreach ($site in $site_list) {
$args += '-s'
$args += $site
}
if ($pkg_list.Count -gt 0) {
$args += '-P'
$args += $pkg_list -Join(',')
}
if ('${{ inputs.check-sig }}' -eq $false) {
$args += '-X'
}
if ( '${{ inputs.pubkeys }}' ) {
$pubkeys = '${{ inputs.pubkeys }}'
$pubkey_list = $pubkeys.Split('', [System.StringSplitOptions]::RemoveEmptyEntries)
$pubkey_list = $pubkey_list | % { $_.Trim() }
foreach ($pubkey in $pubkey_list) {
$args += '-K'
$args += $pubkey
}
}
if ($platform -eq 'x86') {
$args += '--allow-unsupported-windows'
}
# because setup is a Windows GUI app, make it part of a pipeline to make
# PowerShell wait for it to exit
& $setupExe $args | Out-Default
if ('${{ inputs.work-vol }}' -eq '' -and '${{ inputs.install-dir }}' -eq '') {
# Create a symlink for compatibility with previous versions of this
# action, just in case something relies upon C:\cygwin existing
cmd /c mklink /d C:\cygwin $installDir
}
if ('${{ inputs.add-to-path }}' -eq 'true') {
echo "$installDir\bin" >> $env:GITHUB_PATH
}
# run login shell to copy skeleton profile files
& "$installDir\bin\bash.exe" --login
shell: powershell
branding:
color: green
icon: terminal