-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
127 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./release.js"; | ||
export * from "./setup.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {Release} from "./release.js"; | ||
|
||
/** | ||
* Manages the download and installation of Apache Ant. | ||
*/ | ||
export declare class Setup { | ||
|
||
/** | ||
* The release to download and install. | ||
*/ | ||
release: Release; | ||
|
||
/** | ||
* Creates a new setup. | ||
* @param release The release to download and install. | ||
*/ | ||
constructor(release: Release); | ||
|
||
/** | ||
* Downloads and extracts the ZIP archive of Apache Ant. | ||
* @param options Value indicating whether to fetch the Ant optional tasks. | ||
* @returns The path to the extracted directory. | ||
*/ | ||
download(options?: {optionalTasks?: boolean}): Promise<string>; | ||
|
||
/** | ||
* Installs Apache Ant, after downloading it if required. | ||
* @param options Value indicating whether to fetch the Ant optional tasks. | ||
* @returns The path to the installation directory. | ||
*/ | ||
install(options?: {optionalTasks?: boolean}): Promise<string>; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {getBooleanInput, getInput, info, setFailed} from "@actions/core" | ||
import process from "node:process" | ||
import {Release} from "./release.js" | ||
import {Setup} from "./setup.js" | ||
|
||
try | ||
process.title = "Setup Ant" | ||
|
||
version = getInput "version" | ||
release = Release.find if not version or version is "latest" then "*" else version | ||
throw Error "No release matching the version constraint." if not release | ||
|
||
optionalTasks = getBooleanInput "optional-tasks" | ||
installed = if optionalTasks then "installed with optional tasks" else "installed" | ||
path = await new Setup(release).install {optionalTasks} | ||
info "Apache Ant #{release.version} successfully #{installed} in \"#{path}\"." | ||
|
||
catch error | ||
setFailed if error instanceof Error then error else String error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./release.js" | ||
export * from "./setup.js" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {addPath, exportVariable} from "@actions/core" | ||
import {cacheDir, downloadTool, extractZip, find} from "@actions/tool-cache" | ||
import {execFile} from "node:child_process" | ||
import {readdir} from "node:fs/promises" | ||
import {join} from "node:path" | ||
import {promisify} from "node:util" | ||
|
||
# Manages the download and installation of Apache Ant. | ||
export class Setup | ||
|
||
# Creates a new setup. | ||
constructor: (release) -> | ||
|
||
# The release to download and install. | ||
@release = release | ||
|
||
# Downloads and extracts the ZIP archive of Apache Ant. | ||
# Returns the path to the extracted directory. | ||
download: (options = {}) -> | ||
directory = await extractZip await downloadTool @release.url.href | ||
antHome = join directory, await @_findSubfolder directory | ||
await @_fetchOptionalTasks antHome if options.optionalTasks | ||
antHome | ||
|
||
# Installs Apache Ant, after downloading it if required. | ||
# Returns the path to the install directory. | ||
install: (options = {}) -> | ||
antHome = find("ant", @release.version) ? await cacheDir (await @download options), "ant", @release.version | ||
addPath join antHome, "bin" | ||
exportVariable "ANT_HOME", antHome | ||
antHome | ||
|
||
# Fetches the external libraries required by Ant optional tasks. | ||
_fetchOptionalTasks: (antHome) -> | ||
run = promisify execFile | ||
run "java", ["-jar", "lib/ant-launcher.jar", "-buildfile", "fetch.xml", "-noinput", "-silent", "-Ddest=system"], | ||
cwd: antHome | ||
env: {ANT_HOME: antHome} | ||
|
||
# Determines the name of the single subfolder in the specified directory. | ||
_findSubfolder: (directory) -> | ||
folders = (await readdir directory, withFileTypes: true).filter (entity) -> entity.isDirectory() | ||
switch folders.length | ||
when 0 then throw Error "No subfolder found in: #{directory}." | ||
when 1 then return folders[0].name | ||
else throw Error "Multiple subfolders found in: #{directory}." |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {doesNotReject, equal, ok} from "node:assert/strict" | ||
import {access, readdir} from "node:fs/promises" | ||
import {extname, join, resolve} from "node:path" | ||
import {env, platform} from "node:process" | ||
import {describe, it} from "node:test" | ||
import {Release, Setup} from "@cedx/setup-ant" | ||
|
||
# Tests the features of the `Setup` class. | ||
describe "Setup", -> | ||
env.RUNNER_TEMP ?= resolve "var/tmp" | ||
env.RUNNER_TOOL_CACHE ?= resolve "var/cache" | ||
|
||
describe "download()", -> | ||
it "should properly download and extract Apache Ant", -> | ||
path = await new Setup(Release.latest).download optionalTasks: yes | ||
await doesNotReject access join path, "bin", if platform is "win32" then "ant.cmd" else "ant" | ||
|
||
jars = (await readdir join path, "lib").filter (file) -> extname(file) is ".jar" | ||
equal jars.filter((file) -> file.startsWith "ivy-").length, 1 | ||
|
||
describe "install()", -> | ||
it "should add the Ant directory to the PATH environment variable", -> | ||
path = await new Setup(Release.latest).install optionalTasks: no | ||
equal env.ANT_HOME, path | ||
ok env.PATH.includes path |