Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve and optimize to release v5.1 #25

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
max_line_length = 100
insert_final_newline = true
trim_trailing_whitespace = true

[*.{bat,cmd}]
end_of_line = crlf

[*.{ts,js,yml}]
quote_type = single
spaces_around_brackets = inside

[*.{md,txt}]
max_line_length = off
trim_trailing_whitespace = false
85 changes: 85 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"env": {
"es6": true,
"node": true
},
"extends": ["eslint:all"],
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module"
},
"rules": {
"capitalized-comments": [
"warn",
"always",
{
"ignorePattern": "noinspection|pragma",
"ignoreInlineComments": true
}
],
"one-var": ["warn", "never"],
"sort-imports": [
"warn",
{
"allowSeparatedGroups": true,
"ignoreDeclarationSort": true
}
],
"no-undefined": "off",
"require-unicode-regexp": "off",
"no-ternary": "off",
"no-negated-condition": "off",
"prefer-named-capture-group": "off"
},
"overrides": [
{
"files": ["**/*.ts"],
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/all"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json"
},
"rules": {
"func-style": [
"error",
"declaration",
{
"allowArrowFunctions": true
}
],
"@typescript-eslint/no-implicit-any-catch": "off",
"@typescript-eslint/no-magic-numbers": [
"warn",
{
"ignore": [0, 1],
"ignoreArrayIndexes": true
}
],
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
"allowNullableString": true
}
]
}
},
{
"files": ["**/*.test.ts"],
"env": {
"jest/globals": true
},
"plugins": ["jest"],
"extends": ["plugin:jest/all"],
"rules": {
"max-lines-per-function": ["warn", 120],
"jest/no-hooks": "off",
"jest/prefer-expect-assertions": "off"
}
},
{
"files": ["**/*"],
"extends": ["prettier"]
}
]
}
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
* text=auto eol=lf

# Excluded from stats, hidden in diffs
dist/** -diff -merge linguist-generated

# These are explicitly windows files and should use crlf
*.bat text eol=crlf
*.cmd text eol=crlf
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This workflow will install node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build Action

on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
version: [12, 14, 16]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}
cache: yarn
- name: Install dependencies
run: yarn --no-bin-links
- run: yarn build
- run: yarn lint
- run: yarn test
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Integration Tests

on: [push, pull_request]

jobs:
tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
version: ['3.3', '=3.2.5', '~3.3.1', '>=3.2.1 <3.2.5']
include:
- version: '3.3'
expected: 3.3.9
- version: '=3.2.5'
expected: 3.2.5
- version: '~3.3.1'
expected: 3.3.9
- version: '>=3.2.1 <3.2.5'
expected: 3.2.3

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Setup OpenJDK 8
uses: actions/setup-java@v3
with:
java-version: 8
distribution: temurin
- name: Setup Maven ${{ matrix.version }}
uses: ./
id: setup-maven
with:
maven-version: ${{ matrix.version }}
- if: steps.setup-maven.outputs.version != matrix.expected
run: mvn -B --file pom.xml
14 changes: 11 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Explicitly not ignoring node_modules so that they are included in package downloaded by runner
!node_modules/
# Ignore node_modules, ncc is used to compile nodejs modules into a single file
node_modules/
__tests__/runner/*

# Ignore js files that are transpiled from ts files in src/
lib/

# Rest of the file pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
# Logs
logs
Expand All @@ -12,7 +15,8 @@ yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
report.*.*.*.*.json
.scannerwork/

# Runtime data
pids
Expand Down Expand Up @@ -90,3 +94,7 @@ typings/

# DynamoDB Local files
.dynamodb/

# Covers JetBrains IDEs and Visual Studio Code
.idea/
.vscode/
11 changes: 0 additions & 11 deletions .prettierrc.json

This file was deleted.

72 changes: 66 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
### How To Use
# setup-maven

Add this step into workflow
[![Build Action](https://github.com/thachnn/setup-maven/actions/workflows/build.yml/badge.svg)](https://github.com/thachnn/setup-maven/actions/workflows/build.yml)
[![Integration Tests](https://github.com/thachnn/setup-maven/actions/workflows/tests.yml/badge.svg)](https://github.com/thachnn/setup-maven/actions/workflows/tests.yml)

This action provides the following functionality for GitHub Actions runners:

- Optionally downloading and caching a requested version of Maven, and adding it to the PATH
- The requested version supports an exact version or a version range using [SemVer](https://semver.org/) notation

## Usage

See [action.yml](action.yml)

**Basic:**

```yaml
steps:
- name: Set up Maven
uses: thachnn/setup-maven@v5
with:
maven-version: 3.8
```

The `maven-version` input is optional. If not supplied, the maven version from PATH will be used.

### Supported version syntax

The `maven-version` input supports the [Semantic Versioning Specification](https://github.com/npm/node-semver), examples:

- Major versions: `2`, `3`
- More specific versions: `3.2`, `3.3.9`, `3.5.x`, `~3.8.2`, `>=3.3.3`
- Latest release: `*`

## Contributing

### Development using [Docker](https://docs.docker.com/)

Clone this repository and build the project with command

```batch
docker run --rm -it -v "%PWD%:/usr/src/app" -w /usr/src/app node:12-alpine /bin/sh -c ^
"yarn --no-bin-links && yarn lint && yarn test && yarn build"
```

**Note** that `%PWD%` is the project working directory in `Unix` format, such as: `/c/Users/source/repos/setup-maven`

### Analyze source code with [SonarQube](https://www.sonarqube.org/)

Download [SonarQube Docker image](https://hub.docker.com/_/sonarqube/) and start the server

```batch
docker pull sonarqube:community
docker run --rm -d --name docker-sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube
```
- name: Set up Maven
uses: stCarolas/setup-maven@v4.4
with:
maven-version: 3.8.2

Login to http://localhost:9000/ using `Administrator` account (admin/admin) and configure the project to analyze.
For more details, see: https://docs.sonarqube.org/latest/setup/get-started-2-minutes/

Run `SonarScanner` from [the Docker image](https://hub.docker.com/r/sonarsource/sonar-scanner-cli) to analyze the project

```batch
docker run --rm -it --link docker-sonarqube -v "%PWD%:/usr/src/app" -w /usr/src/app ^
-e "SONAR_HOST_URL=http://docker-sonarqube:9000" -e "SONAR_LOGIN=<projectToken>" sonarsource/sonar-scanner-cli ^
-Dsonar.projectKey=setup-maven -Dsonar.sources=. "-Dsonar.exclusions=dist/**,lib/**"
```

## License

The scripts and documentation in this project are released under the `MIT License`
7 changes: 7 additions & 0 deletions __tests__/data/mvn
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
echo 'Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T07:58:13Z)'
echo 'Maven home: /usr/share/maven'
echo 'Java version: 1.8.0_121, vendor: Oracle Corporation'
echo 'Java home: /usr/lib/jvm/java-1.8-openjdk/jre'
echo 'Default locale: en_US, platform encoding: UTF-8'
echo 'OS name: "linux", version: "4.4.0-210-generic", arch: "amd64", family: "unix"'
6 changes: 6 additions & 0 deletions __tests__/data/mvn.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ECHO OFF
ECHO Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d)
ECHO Maven home: C:\Program Files\Java\maven3
ECHO Java version: 11.0.15.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0
ECHO Default locale: en_US, platform encoding: Cp1252
ECHO OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Loading