Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Oct 1, 2019
0 parents commit 67c2286
Show file tree
Hide file tree
Showing 13 changed files with 5,926 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
}
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Test Action"
on:
pull_request:
push:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm ci
- run: npm test
- uses: ./
with:
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
properties: '[{"prop1": "value1"}, {"prop2": "value2"}]'
sonatype-snapshots: true

- run: cat ~/.m2/settings.xml
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# comment this out distribution branches
node_modules/

# Editors
.vscode

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Other Dependency directories
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Mac OS specific
.DS_Store
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2019 Slawomir Jaranowski and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# maven-settings-action

This action setup maven environment for use in action by:
- create maven setings.xml
- set ```interactiveMode``` to false - useful in CI system

# Usage
See [action.yml](action.yml)

Crate default ```settings.xml```:
```yml
steps:
- uses: s4u/maven-settings-action@v1
```
Create ```settings.xml``` with server section:
```yml
steps:
- uses: s4u/maven-settings-action@v1
with:
servers: '[{"id": "serverId", "username": "username", "password": "password"}]'
```

Create ```settings.xml``` with maven properties:
```yml
steps:
- uses: s4u/maven-settings-action@v1
with:
properties: '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
```

Create ```settings.xml``` with https://oss.sonatype.org/content/repositories/snapshots in repository list
```yml
steps:
- uses: s4u/maven-settings-action@v1
with:
sonatype-snapshots: true
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)

# Contributions

Contributions are welcome!
19 changes: 19 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'maven-setings-action'
description: 'Prepare maven settings.xml'

inputs:
servers:
description: 'servers definition in joson array, eg: [{"id": "serverId", "username": "username", "password": "password"}]'
required: false
properties:
description: 'json array with properties, eg [{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'
required: false
sonatype-snapshots:
description: 'add https://oss.sonatype.org/content/repositories/snapshots to repository list - true or false'
default: "false"
required: false


runs:
using: 'node12'
main: 'index.js'
32 changes: 32 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const core = require('@actions/core');
const path = require('path');
const fs = require('fs');
const settings = require('./settings');


// most @actions toolkit packages have async methods
async function run() {

try {
const settingsPath = path.join(process.env.HOME, '.m2', 'settings.xml');
core.info('Prepare maven setings: ' + settingsPath);

if ( fs.existsSync(settingsPath) ) {
core.warning('maven settings.xml already exists - skip');
return;
}

const templateXml = settings.getSettingsTemplate();
settings.fillServers(templateXml);
settings.fillProperties(templateXml);
settings.addSonatypeSnapshots(templateXml);
settings.writeSettings(settingsPath, templateXml);

} catch (error) {
core.setFailed(error.message);
}
}

run();

module.exports = { run };
42 changes: 42 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const process = require('process');
const cp = require('child_process');
const path = require('path');
const fs = require('fs');

const testHomePath = path.join(__dirname, 'temp');
const settingsPath = path.join(testHomePath, '.m2', 'settings.xml');
const indexPath = path.join(__dirname, 'index.js');

beforeAll(() => {
if (!fs.existsSync(testHomePath)) {
fs.mkdirSync(testHomePath);
}

process.env['HOME'] = testHomePath;
});

afterEach(() => {
try {
fs.unlinkSync(settingsPath);
} catch (error) {
console.error(error.message);
}
});

afterAll(() => {
try {
fs.rmdirSync(path.join(testHomePath, ".m2"));
fs.rmdirSync(testHomePath);
} catch (error) {
console.error(error.message);
}
});


test('run with default values', () => {

console.log(cp.execSync(`node ${indexPath}`, { env: process.env }).toString());
const settingsStatus = fs.lstatSync(settingsPath);
expect(settingsStatus.isFile()).toBeTruthy();
expect(settingsStatus.size).toBeGreaterThan(0);
})
Loading

0 comments on commit 67c2286

Please sign in to comment.