Skip to content

Commit 7156ef9

Browse files
committed
(#51) CI: download the PSES automatically
1 parent 80abc19 commit 7156ef9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+89
-7601
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/language_host/current/LanguageHost/modules/PSScriptAnalyzer
2+
/language_host/current/LanguageHost/modules/PowerShellEditorServices
23
/src/main/gen-parser
34
/src/main/gen-lexer
45

build.gradle.kts

Lines changed: 85 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import de.undercouch.gradle.tasks.download.Download
2+
import org.intellij.markdown.html.URI
23
import org.jetbrains.intellij.tasks.PrepareSandboxTask
34
import java.security.MessageDigest
45
import java.util.zip.ZipFile
@@ -99,62 +100,107 @@ tasks {
99100
kotlinOptions.jvmTarget = "17"
100101
}
101102

102-
val downloads = layout.buildDirectory.get().dir("download")
103-
104-
val psScriptAnalyzerVersion: String by project
105-
val psScriptAnalyzerSha256Hash: String by project
106-
107-
val psScriptAnalyzerFileName = "PSScriptAnalyzer.$psScriptAnalyzerVersion.nupkg"
108-
val psScriptAnalyzerOutFile = downloads.file(psScriptAnalyzerFileName)
109-
110-
val downloadPsScriptAnalyzer by register<Download>("downloadPsScriptAnalyzer") {
111-
group = "dependencies"
112-
113-
inputs.property("version", psScriptAnalyzerVersion)
114-
inputs.property("hash", psScriptAnalyzerSha256Hash)
115-
116-
// NOTE: Do not overwrite: the verification step should delete an incorrect file.
117-
// NOTE: Notably, this property allows us to skip the task completely if no inputs change.
118-
overwrite(false)
103+
fun getDependencyTask(
104+
dependencyName: String,
105+
version: String,
106+
expectedHash: String,
107+
uri: URI,
108+
destination: RegularFile,
109+
customizeZip: Action<CopySpec>
110+
): TaskProvider<Copy> {
111+
val download by register<Download>("download$dependencyName") {
112+
group = "dependencies"
113+
114+
inputs.property("version", version)
115+
inputs.property("hash", expectedHash)
116+
117+
// NOTE: Do not overwrite: the verification step should delete an incorrect file.
118+
// NOTE: Notably, this property allows us to skip the task completely if no inputs change.
119+
overwrite(false)
120+
121+
src(uri)
122+
dest(destination)
123+
124+
doLast {
125+
val data = destination.asFile.readBytes()
126+
val hash = MessageDigest.getInstance("SHA-256").let { sha256 ->
127+
sha256.update(data)
128+
sha256.digest().joinToString("") { "%02x".format(it) }
129+
}
130+
if (!hash.equals(expectedHash, ignoreCase = true)) {
131+
destination.asFile.toPath().deleteExisting()
132+
error("$dependencyName hash check failed. Expected $expectedHash, but got $hash\n" +
133+
"The downloaded file has been deleted.\n" +
134+
"Please try running the task again, or update the expected hash in the gradle.properties file.")
135+
}
136+
}
137+
}
119138

120-
src("https://github.com/PowerShell/PSScriptAnalyzer/releases/download/" +
121-
"$psScriptAnalyzerVersion/$psScriptAnalyzerFileName")
122-
dest(psScriptAnalyzerOutFile)
139+
return register<Copy>("get$dependencyName") {
140+
group = "dependencies"
123141

124-
doLast {
125-
val data = psScriptAnalyzerOutFile.asFile.readBytes()
126-
val hash = MessageDigest.getInstance("SHA-256").let { sha256 ->
127-
sha256.update(data)
128-
sha256.digest().joinToString("") { "%02x".format(it) }
142+
val outDir = projectDir.resolve("language_host/current/LanguageHost/modules/$dependencyName")
143+
doFirst {
144+
if (!outDir.deleteRecursively()) error("Cannot delete \"$outDir\".")
129145
}
130-
if (!hash.equals(psScriptAnalyzerSha256Hash, ignoreCase = true)) {
131-
psScriptAnalyzerOutFile.asFile.toPath().deleteExisting()
132-
error("PSScriptAnalyzer hash check failed. Expected ${psScriptAnalyzerSha256Hash}, but got $hash\n" +
133-
"Please try running the task again, or update the expected hash in the gradle.properties file.")
146+
147+
dependsOn(download)
148+
from(zipTree(destination)) {
149+
customizeZip(this)
134150
}
151+
into(outDir)
135152
}
136153
}
137154

138-
val getPsScriptAnalyzer by registering(Copy::class) {
139-
group = "dependencies"
155+
val downloads = layout.buildDirectory.get().dir("download")
140156

141-
val outDir = projectDir.resolve("language_host/current/LanguageHost/modules/PSScriptAnalyzer")
142-
doFirst {
143-
if (!outDir.deleteRecursively()) error("Cannot delete \"$outDir\".")
144-
}
157+
val psScriptAnalyzerVersion: String by project
158+
val psScriptAnalyzerSha256Hash: String by project
159+
val psScriptAnalyzerFileName = "PSScriptAnalyzer.$psScriptAnalyzerVersion.nupkg"
160+
val psScriptAnalyzerOutFile = downloads.file(psScriptAnalyzerFileName)
145161

146-
dependsOn(downloadPsScriptAnalyzer)
147-
from(zipTree(psScriptAnalyzerOutFile))
162+
val psesVersion: String by project
163+
val psesSha256Hash: String by project
164+
165+
val getPsScriptAnalyzer = getDependencyTask(
166+
"PSScriptAnalyzer",
167+
psScriptAnalyzerVersion,
168+
psScriptAnalyzerSha256Hash,
169+
URI(
170+
"https://github.com/PowerShell/PSScriptAnalyzer/releases/download/" +
171+
"$psScriptAnalyzerVersion/$psScriptAnalyzerFileName"
172+
),
173+
psScriptAnalyzerOutFile
174+
) {
148175
// NuGet stuff:
149176
exclude("_manifest/**", "_rels/**", "package/**", "[Content_Types].xml", "*.nuspec")
150177

151178
// Compatibility profiles, see https://github.com/PowerShell/PSScriptAnalyzer/issues/1148
152179
exclude("compatibility_profiles/**")
153-
into(outDir)
180+
}
181+
182+
val getPowerShellEditorServices = getDependencyTask(
183+
"PowerShellEditorServices",
184+
psesVersion,
185+
psesSha256Hash,
186+
URI(
187+
"https://github.com/PowerShell/PowerShellEditorServices/releases/download/" +
188+
"v$psesVersion/PowerShellEditorServices.zip"
189+
),
190+
downloads.file("PowerShellEditorServices.zip")
191+
) {
192+
include("PowerShellEditorServices/PowerShellEditorServices/**")
193+
eachFile {
194+
relativePath = RelativePath(true, *relativePath.segments.drop(2).toTypedArray())
195+
}
196+
}
197+
198+
val getAllDependencies by registering {
199+
dependsOn(getPsScriptAnalyzer, getPowerShellEditorServices)
154200
}
155201

156202
withType<PrepareSandboxTask> {
157-
dependsOn(getPsScriptAnalyzer)
203+
dependsOn(getAllDependencies)
158204
from("${project.rootDir}/language_host/current") {
159205
into("${intellij.pluginName.get()}/lib/")
160206
}

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ maxUnpackedPluginBytes=20971520
55

66
psScriptAnalyzerVersion=1.21.0
77
psScriptAnalyzerSha256Hash=66353f139f4f1ffaa532fdeed965e70afbb8400b4810b6b2b91e091119aa6fad
8+
9+
psesVersion=1.10.1
10+
psesSha256Hash=1c2ec9bbe40142df370497f72a8c33aafa8328462f204b4e1c5986ea7a59a40e

0 commit comments

Comments
 (0)