forked from cygwin/cygwin-install-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
159 lines (141 loc) · 5.42 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
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')) {
echo "unknown platform $platform"
exit 1
}
$vol = '${{ inputs.work-vol }}'
# If temporary drive D: doesn't exist in the VM, fallback to C:
if ("$vol" -eq '') {
$vol = (Test-Path -LiteralPath 'D:\') ? 'D:' : 'C:'
}
$setupExe = "$vol\setup.exe"
$setupFileName = "setup-$platform.exe"
Invoke-WebRequest "https://cygwin.com/$setupFileName" -OutFile $setupExe
if ((Get-Item -LiteralPath $setupExe).Length -eq 0) {
throw "The downloaded setup has a zero length!"
}
if ('${{ inputs.check-hash }}' -eq 'true') {
$expectedHashLines = $(Invoke-WebRequest -Uri https://cygwin.com/sha512.sum).ToString() -split "`n"
$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 = '${{ inputs.install-dir }}' -ne '' ? '${{ inputs.install-dir }}' : "$vol\cygwin"
$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 '[\s,]+',0,"RegexMatch,Singleline" | Where { $_ -ne '' }
foreach ($site in $site_list) {
$args += '-s'
$args += $site
}
$pkg_list = '${{ inputs.packages }}' -split '[\s,]+',0,"RegexMatch,Singleline" | Where { $_ -ne '' }
if ($pkg_list.Count -gt 0) {
$args += '-P'
$args += $pkg_list -Join(',')
}
if ('${{ inputs.check-sig }}' -eq $false) {
$args += '-X'
}
$pubkey_list = '${{inputs.pubkeys}}' -split '[\s,]+',0,"RegexMatch,Singleline" | Where { $_ -ne '' }
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: pwsh
branding:
color: green
icon: terminal