Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a3e6ce2
Adding maven auth support
Nov 16, 2019
56b5af7
ignore vscode directory
Nov 20, 2019
56eacf9
move required parameters to auth module
Nov 20, 2019
86e8938
Add generated auth and setup-java
Nov 20, 2019
1b04170
Move auth to the bottom of setup
Nov 28, 2019
b0e5cf2
Support ids
Nov 28, 2019
dc5f78f
generated and pretty files
Nov 28, 2019
2432735
use server-id instead of ambigous id
Nov 28, 2019
b8a0027
Use console.log where appropriate
Nov 28, 2019
4450e92
Use gitattributes to ignore generated lib js files
Nov 28, 2019
18983b8
Update gitattributes and remove lib files
Nov 28, 2019
4954095
parent 52c60e0768c1c2fabcab3acf97aa77c5dbc32dfa
Nov 16, 2019
1085a2b
Use console.log where appropriate
Nov 28, 2019
c8f8a26
Add publish section to README
Nov 28, 2019
7d69f80
build index.js
Nov 28, 2019
d1d9006
Add fields to action.yml
Nov 28, 2019
cda418e
Update index.js
Nov 28, 2019
d2eada3
direct ncc to setup-java
Nov 28, 2019
ade090c
Update index.js
Nov 28, 2019
210fba7
Add note about pom.xml to README
Nov 28, 2019
d5150a6
Add publish to Maven Central example to README
Nov 29, 2019
abe10fa
Fix typo in README.md
dzirbel Nov 30, 2019
cfdbba3
Merge pull request #32 from dzirbel/patch-1
konradpabjan Dec 4, 2019
c1c11bb
Examples use v1 instead of master
Dec 5, 2019
bfbec53
log when we overwrite the file
Dec 5, 2019
12896df
logging options
Dec 5, 2019
96236d7
return but shoudl still fail
Dec 5, 2019
2b05c00
logging code
Dec 5, 2019
948db75
strringify the logs
Dec 5, 2019
7970453
code == EEXIST
Dec 5, 2019
1dac4fe
Use $HOME directory
Dec 6, 2019
5e29577
Remote options from log
Dec 6, 2019
8940139
Be explicit about second flag
Dec 6, 2019
4b6ff8c
Format auth
Dec 6, 2019
540a98a
Wrap long lines in action.yml
Dec 6, 2019
dbeab7c
Remove trailing spaces and long lines
Dec 6, 2019
b7e7041
Remove last trailing space
Dec 6, 2019
6ae690c
Add test for overwrite
Dec 6, 2019
f33acc6
build release
Dec 6, 2019
ddf78ad
Add note about $HOME directory usage
Dec 6, 2019
70aff31
Apply suggestions from code review
Dec 6, 2019
2f85cc5
Merge branch 'maven-auth' of github.com:clarkbw/setup-java into maven…
Dec 6, 2019
203550b
Add Gradle example to README
Dec 6, 2019
8ccac94
README Small spelling fix. Also some rewording
Dec 9, 2019
9d56a3b
prettier fixup
Dec 10, 2019
551e2a2
sanitzie XML characters
Dec 10, 2019
4757680
Add Shared Runner to README
Dec 10, 2019
ae11e1a
Allow for alternate settings.xml file location
Dec 10, 2019
ce88fee
Move to settings-path
Dec 10, 2019
2e749e5
Update settings-path for github.workspace
Dec 10, 2019
998be8d
Add default to settings-path description
Dec 18, 2019
6924f73
Address latest review feedback
Dec 19, 2019
1bba665
Try env variables
Dec 19, 2019
0e5545e
improve tests
Dec 19, 2019
7e36086
Pass undefined when empty
Dec 19, 2019
c05b45b
Update README with env sections
Dec 19, 2019
2ccd1ad
Add examples of the settings.xml file generated
Dec 19, 2019
9b11fe4
Add defaults descriptions to actions.yml
Dec 20, 2019
d8ada52
Merge pull request #29 from clarkbw/maven-auth
konradpabjan Dec 20, 2019
f806141
Add support for matching -ea version formats
giltene Dec 22, 2019
ae687a7
Update index.js
giltene Dec 22, 2019
5c4dee6
Bump handlebars from 4.1.2 to 4.5.3
dependabot[bot] Dec 29, 2019
0e40802
Merge pull request #35 from foo-actions/master
konradpabjan Dec 31, 2019
4bec33a
Merge pull request #36 from actions/dependabot/npm_and_yarn/handlebar…
konradpabjan Dec 31, 2019
ae23cbb
Update master with dependabot fixes
konradpabjan Dec 31, 2019
b52cd69
Update workflow.yml
konradpabjan Dec 31, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/index.js -diff -merge
dist/index.js linguist-generated=true
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Main workflow
on: [push]
on: [push, pull_request]
jobs:
run:
name: Run
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ typings/

# DynamoDB Local files
.dynamodb/
.vscode/
128 changes: 124 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This action sets up a java environment for use in actions by:

See [action.yml](action.yml)

Basic:
## Basic
```yaml
steps:
- uses: actions/checkout@v1
Expand All @@ -25,7 +25,7 @@ steps:
- run: java -cp java HelloWorldApp
```

From local file:
## Local file
```yaml
steps:
- uses: actions/checkout@v1
Expand All @@ -37,15 +37,15 @@ steps:
- run: java -cp java HelloWorldApp
```

Matrix Testing:
## Matrix Testing
```yaml
jobs:
build:
runs-on: ubuntu-16.04
strategy:
matrix:
# test against latest update of each major Java version, as well as specific updates of LTS versions:
java: [ 1.6, 6.0.83, 7, 7.0.181, 8, 8.0.192, 9.0,x, 10, 11.0.x, 11.0.3, 12, 13 ]
java: [ 1.6, 6.0.83, 7, 7.0.181, 8, 8.0.192, 9.0.x, 10, 11.0.x, 11.0.3, 12, 13 ]
name: Java ${{ matrix.java }} sample
steps:
- uses: actions/checkout@master
Expand All @@ -56,6 +56,126 @@ jobs:
- run: java -cp java HelloWorldApp
```

## Publishing using Apache Maven
```yaml
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Publish to GitHub Packages Apache Maven
run: mvn deploy
env:
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password

- name: Set up Apache Maven Central
uses: actions/setup-java@v1
with: # running setup-java again overwrites the settings.xml
java-version: 1.8
server-id: maven # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy

- name: Publish to Apache Maven Central
run: mvn deploy
env:
MAVEN_USERNAME: maven_username123
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
```

The two `settings.xml` files created from the above example look like the following.

`settings.xml` file created for the first deploy to GitHub Packages
```xml
<servers>
<server>
<id>github</id>
<username>${env.GITHUB_ACTOR}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
```

`settings.xml` file created for the second deploy to Apache Maven Central
```xml
<servers>
<server>
<id>maven</id>
<username>${env.MAVEN_USERNAME}</username>
<password>${env.MAVEN_CENTRAL_TOKEN}</password>
</server>
</servers>
```

***NOTE: The `settings.xml` file is created in the Actions $HOME directory. If you have an existing `settings.xml` file at that location, it will be overwritten. See below for using the `settings-path` to change your `settings.xml` file location.***

See the help docs on [Publishing a Package](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-apache-maven-for-use-with-github-packages#publishing-a-package) for more information on the `pom.xml` file.

## Publishing using Gradle
```yaml
jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Set up JDK 1.8
uses: actions/setup-java@v1

- name: Build with Gradle
run: gradle build

- name: Publish to GitHub Packages
run: gradle publish
env:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
```

***NOTE: The `USERNAME` and `PASSWORD` need to correspond to the credentials environment variables used in the publishing section of your `build.gradle`.***

See the help docs on [Publishing a Package with Gradle](https://help.github.com/en/github/managing-packages-with-github-packages/configuring-gradle-for-use-with-github-packages#example-using-gradle-groovy-for-a-single-package-in-a-repository) for more information on the `build.gradle` configuration file.

## Apache Maven with a settings path

When using an Actions self-hosted runner with multiple shared runners the default `$HOME` directory can be shared by a number runners at the same time which could overwrite existing settings file. Setting the `settings-path` variable allows you to choose a unique location for your settings file.

```yaml
jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8 for Shared Runner
uses: actions/setup-java@v1
with:
java-version: 1.8
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Publish to GitHub Packages Apache Maven
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
Expand Down
144 changes: 144 additions & 0 deletions __tests__/auth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');

// make the os.homedir() call be local to the tests
jest.doMock('os', () => {
return {
homedir: jest.fn(() => __dirname)
};
});

import * as auth from '../src/auth';

const m2Dir = path.join(__dirname, auth.M2_DIR);
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);

describe('auth tests', () => {
beforeEach(async () => {
await io.rmRF(m2Dir);
}, 300000);

afterAll(async () => {
try {
await io.rmRF(m2Dir);
} catch {
console.log('Failed to remove test directories');
}
}, 100000);

it('creates settings.xml in alternate locations', async () => {
const id = 'packages';
const username = 'UNAMI';
const password = 'TOLKIEN';

const altHome = path.join(__dirname, 'runner', 'settings');
const altSettingsFile = path.join(altHome, auth.SETTINGS_FILE);
process.env[`INPUT_SETTINGS-PATH`] = altHome;
await io.rmRF(altHome); // ensure it doesn't already exist

await auth.configAuthentication(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(false);
expect(fs.existsSync(settingsFile)).toBe(false);

expect(fs.existsSync(altHome)).toBe(true);
expect(fs.existsSync(altSettingsFile)).toBe(true);
expect(fs.readFileSync(altSettingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
);

delete process.env[`INPUT_SETTINGS-PATH`];
await io.rmRF(altHome);
}, 100000);

it('creates settings.xml with username and password', async () => {
const id = 'packages';
const username = 'UNAME';
const password = 'TOKEN';

await auth.configAuthentication(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
);
}, 100000);

it('overwrites existing settings.xml files', async () => {
const id = 'packages';
const username = 'USERNAME';
const password = 'PASSWORD';

fs.mkdirSync(m2Dir, {recursive: true});
fs.writeFileSync(settingsFile, 'FAKE FILE');
expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);

await auth.configAuthentication(id, username, password);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(id, username, password)
);
}, 100000);

it('does not create settings.xml without required parameters', async () => {
await auth.configAuthentication('FOO');

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate('FOO', auth.DEFAULT_USERNAME, auth.DEFAULT_PASSWORD)
);

await auth.configAuthentication(undefined, 'BAR', undefined);

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(auth.DEFAULT_ID, 'BAR', auth.DEFAULT_PASSWORD)
);

await auth.configAuthentication(undefined, undefined, 'BAZ');

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(auth.DEFAULT_ID, auth.DEFAULT_USERNAME, 'BAZ')
);

await auth.configAuthentication();

expect(fs.existsSync(m2Dir)).toBe(true);
expect(fs.existsSync(settingsFile)).toBe(true);
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
auth.generate(
auth.DEFAULT_ID,
auth.DEFAULT_USERNAME,
auth.DEFAULT_PASSWORD
)
);
}, 100000);

it('escapes invalid XML inputs', () => {
const id = 'packages';
const username = 'USER';
const password = '&<>"\'\'"><&';

expect(auth.generate(id, username, password)).toEqual(`
<settings>
<servers>
<server>
<id>${id}</id>
<username>\${env.${username}}</username>
<password>\${env.&amp;&lt;&gt;&quot;&apos;&apos;&quot;&gt;&lt;&amp;}</password>
</server>
</servers>
</settings>
`);
});
});
26 changes: 22 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: 'Setup Java JDK'
description: 'Set up a specific version of the Java JDK and add the command-line tools to the PATH'
description: 'Set up a specific version of the Java JDK and add the
command-line tools to the PATH'
author: 'GitHub'
inputs:
inputs:
java-version:
description: 'The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x)'
description: 'The Java version to make available on the path. Takes a whole
or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x)'
required: true
java-package:
description: 'The package type (jre, jdk, jdk+fx)'
Expand All @@ -14,7 +16,23 @@ inputs:
required: false
default: 'x64'
jdkFile:
description: 'Path to where the compressed JDK is located. The path could be in your source repository or a local path on the agent.'
description: 'Path to where the compressed JDK is located. The path could
be in your source repository or a local path on the agent.'
required: false
server-id:
description: 'ID of the distributionManagement repository in the pom.xml
file. Default is `github`'
required: false
server-username:
description: 'Environment variable name for the username for authentication
to the Apache Maven repository. Default is $GITHUB_ACTOR'
required: false
server-password:
description: 'Environment variable name for password or token for
authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
required: false
settings-path:
description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
required: false
runs:
using: 'node12'
Expand Down
Loading