├── README.md ├── .prettierrc.json ├── action.yml ├── src ├── setup-maven.ts └── installer.ts ├── LICENSE ├── package.json ├── .gitignore ├── lib ├── setup-maven.js └── installer.js └── tsconfig.json /README.md: -------------------------------------------------------------------------------- 1 | ### How To Use 2 | 3 | Add this step into workflow 4 | 5 | ``` 6 | - name: Set up Maven 7 | uses: stCarolas/setup-maven@v5 8 | with: 9 | maven-version: 3.8.2 10 | ``` 11 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": true, 6 | "singleQuote": true, 7 | "trailingComma": "none", 8 | "bracketSpacing": false, 9 | "arrowParens": "avoid", 10 | "parser": "typescript" 11 | } -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Setup Maven' 2 | description: 'Install a specific version of Apache Maven and add it to the PATH' 3 | author: 'stCarolas' 4 | inputs: 5 | maven-version: 6 | description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0' 7 | default: '3.8.2' 8 | runs: 9 | using: 'node20' 10 | main: 'lib/setup-maven.js' 11 | -------------------------------------------------------------------------------- /src/setup-maven.ts: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core'; 2 | import * as installer from './installer'; 3 | 4 | async function run() { 5 | try { 6 | let version = core.getInput('maven-version'); 7 | if (version) { 8 | await installer.getMaven(version); 9 | } 10 | } catch (error) { 11 | core.setFailed((error as Error).message); 12 | } 13 | } 14 | 15 | run(); 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 stCarolas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "setup-maven", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "setup maven action", 6 | "main": "lib/setup-maven.js", 7 | "scripts": { 8 | "build": "tsc", 9 | "format": "prettier --write **/*.ts", 10 | "format-check": "prettier --check **/*.ts" 11 | }, 12 | "keywords": [ 13 | "actions", 14 | "maven", 15 | "setup" 16 | ], 17 | "author": "stCarolas", 18 | "license": "MIT", 19 | "dependencies": { 20 | "@actions/core": "^1.2.6", 21 | "@actions/github": "^1.0.0", 22 | "@actions/io": "^1.0.0", 23 | "@actions/tool-cache": "1.3.1", 24 | "semver": "^6.1.1", 25 | "typed-rest-client": "^1.5.0" 26 | }, 27 | "devDependencies": { 28 | "@types/node": "^20.11.6", 29 | "@types/semver": "^6.0.0", 30 | "husky": "^2.3.0", 31 | "prettier": "^1.17.1", 32 | "typescript": "^5.3.3" 33 | }, 34 | "husky": { 35 | "skipCI": true, 36 | "hooks": { 37 | "pre-commit": "npm run build && npm run format", 38 | "post-commit": "npm prune --production && git add node_modules/* && git commit -m \"Husky commit correct node modules\"" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/installer.ts: -------------------------------------------------------------------------------- 1 | // Load tempDirectory before it gets wiped by tool-cache 2 | let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; 3 | 4 | import * as core from '@actions/core'; 5 | import * as tc from '@actions/tool-cache'; 6 | import * as path from 'path'; 7 | 8 | if (!tempDirectory) { 9 | let baseLocation: string; 10 | if (process.platform === 'win32') { 11 | baseLocation = process.env['USERPROFILE'] || 'C:\\'; 12 | } else { 13 | if (process.platform === 'darwin') { 14 | baseLocation = '/Users'; 15 | } else { 16 | baseLocation = '/home'; 17 | } 18 | } 19 | tempDirectory = path.join(baseLocation, 'actions', 'temp'); 20 | } 21 | 22 | export async function getMaven(version: string) { 23 | let toolPath: string; 24 | toolPath = tc.find('maven', version); 25 | 26 | if (!toolPath) { 27 | toolPath = await downloadMaven(version); 28 | } 29 | 30 | toolPath = path.join(toolPath, 'bin'); 31 | core.addPath(toolPath); 32 | } 33 | 34 | async function downloadMaven(version: string): Promise { 35 | const toolDirectoryName = `apache-maven-${version}`; 36 | const downloadUrl = `https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${version}/apache-maven-${version}-bin.tar.gz`; 37 | console.log(`downloading ${downloadUrl}`); 38 | 39 | try { 40 | const downloadPath = await tc.downloadTool(downloadUrl); 41 | const extractedPath = await tc.extractTar(downloadPath); 42 | let toolRoot = path.join(extractedPath, toolDirectoryName); 43 | return await tc.cacheDir(toolRoot, 'maven', version); 44 | } catch (err) { 45 | throw err; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Explicitly not ignoring node_modules so that they are included in package downloaded by runner 2 | !node_modules/ 3 | __tests__/runner/* 4 | 5 | # Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # Diagnostic reports (https://nodejs.org/api/report.html) 15 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 16 | 17 | # Runtime data 18 | pids 19 | *.pid 20 | *.seed 21 | *.pid.lock 22 | 23 | # Directory for instrumented libs generated by jscoverage/JSCover 24 | lib-cov 25 | 26 | # Coverage directory used by tools like istanbul 27 | coverage 28 | *.lcov 29 | 30 | # nyc test coverage 31 | .nyc_output 32 | 33 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 34 | .grunt 35 | 36 | # Bower dependency directory (https://bower.io/) 37 | bower_components 38 | 39 | # node-waf configuration 40 | .lock-wscript 41 | 42 | # Compiled binary addons (https://nodejs.org/api/addons.html) 43 | build/Release 44 | 45 | # Dependency directories 46 | jspm_packages/ 47 | 48 | # TypeScript v1 declaration files 49 | typings/ 50 | 51 | # TypeScript cache 52 | *.tsbuildinfo 53 | 54 | # Optional npm cache directory 55 | .npm 56 | 57 | # Optional eslint cache 58 | .eslintcache 59 | 60 | # Optional REPL history 61 | .node_repl_history 62 | 63 | # Output of 'npm pack' 64 | *.tgz 65 | 66 | # Yarn Integrity file 67 | .yarn-integrity 68 | 69 | # dotenv environment variables file 70 | .env 71 | .env.test 72 | 73 | # parcel-bundler cache (https://parceljs.org/) 74 | .cache 75 | 76 | # next.js build output 77 | .next 78 | 79 | # nuxt.js build output 80 | .nuxt 81 | 82 | # vuepress build output 83 | .vuepress/dist 84 | 85 | # Serverless directories 86 | .serverless/ 87 | 88 | # FuseBox cache 89 | .fusebox/ 90 | 91 | # DynamoDB Local files 92 | .dynamodb/ 93 | -------------------------------------------------------------------------------- /lib/setup-maven.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | var desc = Object.getOwnPropertyDescriptor(m, k); 5 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { 6 | desc = { enumerable: true, get: function() { return m[k]; } }; 7 | } 8 | Object.defineProperty(o, k2, desc); 9 | }) : (function(o, m, k, k2) { 10 | if (k2 === undefined) k2 = k; 11 | o[k2] = m[k]; 12 | })); 13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 14 | Object.defineProperty(o, "default", { enumerable: true, value: v }); 15 | }) : function(o, v) { 16 | o["default"] = v; 17 | }); 18 | var __importStar = (this && this.__importStar) || function (mod) { 19 | if (mod && mod.__esModule) return mod; 20 | var result = {}; 21 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 22 | __setModuleDefault(result, mod); 23 | return result; 24 | }; 25 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 26 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 27 | return new (P || (P = Promise))(function (resolve, reject) { 28 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 29 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 30 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 31 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 32 | }); 33 | }; 34 | Object.defineProperty(exports, "__esModule", { value: true }); 35 | const core = __importStar(require("@actions/core")); 36 | const installer = __importStar(require("./installer")); 37 | function run() { 38 | return __awaiter(this, void 0, void 0, function* () { 39 | try { 40 | let version = core.getInput('maven-version'); 41 | if (version) { 42 | yield installer.getMaven(version); 43 | } 44 | } 45 | catch (error) { 46 | core.setFailed(error.message); 47 | } 48 | }); 49 | } 50 | run(); 51 | -------------------------------------------------------------------------------- /lib/installer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { 3 | if (k2 === undefined) k2 = k; 4 | var desc = Object.getOwnPropertyDescriptor(m, k); 5 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { 6 | desc = { enumerable: true, get: function() { return m[k]; } }; 7 | } 8 | Object.defineProperty(o, k2, desc); 9 | }) : (function(o, m, k, k2) { 10 | if (k2 === undefined) k2 = k; 11 | o[k2] = m[k]; 12 | })); 13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { 14 | Object.defineProperty(o, "default", { enumerable: true, value: v }); 15 | }) : function(o, v) { 16 | o["default"] = v; 17 | }); 18 | var __importStar = (this && this.__importStar) || function (mod) { 19 | if (mod && mod.__esModule) return mod; 20 | var result = {}; 21 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); 22 | __setModuleDefault(result, mod); 23 | return result; 24 | }; 25 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 26 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 27 | return new (P || (P = Promise))(function (resolve, reject) { 28 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 29 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 30 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 31 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 32 | }); 33 | }; 34 | Object.defineProperty(exports, "__esModule", { value: true }); 35 | exports.getMaven = void 0; 36 | // Load tempDirectory before it gets wiped by tool-cache 37 | let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''; 38 | const core = __importStar(require("@actions/core")); 39 | const tc = __importStar(require("@actions/tool-cache")); 40 | const path = __importStar(require("path")); 41 | if (!tempDirectory) { 42 | let baseLocation; 43 | if (process.platform === 'win32') { 44 | baseLocation = process.env['USERPROFILE'] || 'C:\\'; 45 | } 46 | else { 47 | if (process.platform === 'darwin') { 48 | baseLocation = '/Users'; 49 | } 50 | else { 51 | baseLocation = '/home'; 52 | } 53 | } 54 | tempDirectory = path.join(baseLocation, 'actions', 'temp'); 55 | } 56 | function getMaven(version) { 57 | return __awaiter(this, void 0, void 0, function* () { 58 | let toolPath; 59 | toolPath = tc.find('maven', version); 60 | if (!toolPath) { 61 | toolPath = yield downloadMaven(version); 62 | } 63 | toolPath = path.join(toolPath, 'bin'); 64 | core.addPath(toolPath); 65 | }); 66 | } 67 | exports.getMaven = getMaven; 68 | function downloadMaven(version) { 69 | return __awaiter(this, void 0, void 0, function* () { 70 | const toolDirectoryName = `apache-maven-${version}`; 71 | const downloadUrl = `https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/${version}/apache-maven-${version}-bin.tar.gz`; 72 | console.log(`downloading ${downloadUrl}`); 73 | try { 74 | const downloadPath = yield tc.downloadTool(downloadUrl); 75 | const extractedPath = yield tc.extractTar(downloadPath); 76 | let toolRoot = path.join(extractedPath, toolDirectoryName); 77 | return yield tc.cacheDir(toolRoot, 'maven', version); 78 | } 79 | catch (err) { 80 | throw err; 81 | } 82 | }); 83 | } 84 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | // "incremental": true, /* Enable incremental compilation */ 5 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ 6 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 7 | "lib": [ 8 | "es6" 9 | ], 10 | // "allowJs": true, /* Allow javascript files to be compiled. */ 11 | // "checkJs": true, /* Report errors in .js files. */ 12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 13 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 14 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 15 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 16 | // "outFile": "./", /* Concatenate and emit output to single file. */ 17 | "outDir": "./lib", /* Redirect output structure to the directory. */ 18 | "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 19 | // "composite": true, /* Enable project compilation */ 20 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 21 | // "removeComments": true, /* Do not emit comments to output. */ 22 | // "noEmit": true, /* Do not emit outputs. */ 23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 26 | 27 | /* Strict Type-Checking Options */ 28 | "strict": true, /* Enable all strict type-checking options. */ 29 | "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ 30 | // "strictNullChecks": true, /* Enable strict null checks. */ 31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 36 | 37 | /* Additional Checks */ 38 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 42 | 43 | /* Module Resolution Options */ 44 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 45 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 46 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 47 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 48 | // "typeRoots": [], /* List of folders to include type definitions from. */ 49 | // "types": [], /* Type declaration files to be included in compilation. */ 50 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 51 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 52 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 53 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 54 | 55 | /* Source Map Options */ 56 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 59 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 60 | 61 | /* Experimental Options */ 62 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 63 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 64 | }, 65 | "exclude": ["node_modules", "**/*.test.ts"] 66 | } 67 | --------------------------------------------------------------------------------