-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathaction.yml
150 lines (135 loc) · 5.01 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
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:
# by default, install to C:\cygwin rather than the platform dependent
# default to make everything simpler
description: Installation directory
required: false
default: C:\cygwin
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'
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
}
$setupFileName = "setup-$platform.exe"
Invoke-WebRequest "https://cygwin.com/$setupFileName" -OutFile C:\setup.exe
if ((Get-Item -LiteralPath 'C:\setup.exe').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 C:\setup.exe -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)"
}
}
}
$packages = '${{ inputs.packages }}'
$pkg_list = $packages.Split('', [System.StringSplitOptions]::RemoveEmptyEntries)
$pkg_list = $pkg_list | % { $_.Trim() }
$pkg_list = $pkg_list | % { $_.Trim(',') }
$args = @(
'-qnO',
'-l', 'C:\cygwin-packages',
'-R', '${{ inputs.install-dir }}'
)
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
& C:\setup.exe $args | Out-Default
shell: powershell
- if: ${{ inputs.add-to-path == 'true' }}
run: echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
shell: powershell
- run: |
# run login shell to copy skeleton profile files
${{ inputs.install-dir }}\bin\bash.exe --login
shell: powershell
branding:
color: green
icon: terminal