From c30d17a4a02ad860f82b53ce813133e4130aba48 Mon Sep 17 00:00:00 2001 From: Stephan Schnabel Date: Thu, 28 Oct 2021 11:43:06 +0200 Subject: [PATCH] Add linter. --- .github/workflows/ci.yml | 36 ++++--- .github/workflows/release.yml | 73 ++++++++------ .github/workflows/snapshot.yml | 57 +++++++---- .markdownlint.yaml | 6 ++ .yamllint | 10 ++ README.md | 96 +++++++++++-------- .../resources/application-test-composite.yaml | 4 +- src/test/resources/application-test-mdc.yaml | 18 ++-- 8 files changed, 187 insertions(+), 113 deletions(-) create mode 100644 .markdownlint.yaml create mode 100644 .yamllint diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3616fdc..4efb2e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,32 @@ name: PullRequest -on: [pull_request] +"on": [pull_request] jobs: + + lint-yaml: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ibiqlik/action-yamllint@v3 + with: + format: colored + strict: true + + lint-markdown: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker://avtodev/markdown-lint:v1 + with: + args: /github/workspace + build: runs-on: ubuntu-latest steps: - - name: checkout - uses: actions/checkout@v2 - - name: setup - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: dependencies - run: mvn -B -q dependency:go-offline - - name: verify - run: mvn -B verify + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 11 + - run: mvn -B dependency:go-offline -q + - run: mvn -B verify diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d46f22d..e26eba4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,37 +1,52 @@ name: Release -on: +"on": workflow_dispatch: {} jobs: - build: + + lint-yaml: runs-on: ubuntu-latest steps: - - name: checkout - uses: actions/checkout@v2 - with: - token: ${{ secrets.GIT_ACTION_TOKEN }} - - name: git-configure - run: | - git config user.email "actions@github.com" - git config user.name "GitHub Actions" - - name: setup - uses: actions/setup-java@v1 - with: - java-version: 11 - server-id: sonatype-nexus - server-username: SERVER_USERNAME - server-password: SERVER_PASSWORD - gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} - gpg-passphrase: GPG_PASSPHRASE - - name: dependencies - run: mvn -B -q dependency:go-offline - - name: prepare - run: mvn -B release:prepare - - name: perform - run: mvn -B release:perform - env: - SERVER_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} - SERVER_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + - uses: actions/checkout@v2 + - uses: ibiqlik/action-yamllint@v3 + with: + format: colored + strict: true + lint-markdown: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker://avtodev/markdown-lint:v1 + with: + args: /github/workspace + + build: + runs-on: ubuntu-latest + needs: + - lint-markdown + - lint-yaml + steps: + - uses: actions/checkout@v2 + with: + token: ${{ secrets.GIT_ACTION_TOKEN }} + - name: git-configure + run: | + git config user.email "actions@github.com" + git config user.name "GitHub Actions" + - uses: actions/setup-java@v1 + with: + java-version: 11 + server-id: sonatype-nexus + server-username: SERVER_USERNAME + server-password: SERVER_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: GPG_PASSPHRASE + - run: mvn -B dependency:go-offline -q + - run: mvn -B release:prepare + - run: mvn -B release:perform -DreleaseProfiles=oss-release + env: + SERVER_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + SERVER_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 624ac4d..5f08a0a 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -1,28 +1,45 @@ name: Snapshot -on: +"on": push: branches: - - 'main' - - '[1-9]+.[0-9]+.x' + - 'main' + - '[1-9]+.[0-9]+.x' jobs: - build: + + lint-yaml: runs-on: ubuntu-latest steps: - - name: checkout - uses: actions/checkout@v2 - - name: setup - uses: actions/setup-java@v1 - with: - java-version: 11 - server-id: sonatype-nexus - server-username: SERVER_USERNAME - server-password: SERVER_PASSWORD - - name: dependencies - run: mvn -B -q dependency:go-offline - - name: deploy - run: mvn -B deploy - env: - SERVER_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} - SERVER_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + - uses: actions/checkout@v2 + - uses: ibiqlik/action-yamllint@v3 + with: + format: colored + strict: true + + lint-markdown: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker://avtodev/markdown-lint:v1 + with: + args: /github/workspace + + build: + runs-on: ubuntu-latest + needs: + - lint-markdown + - lint-yaml + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 11 + server-id: sonatype-nexus + server-username: SERVER_USERNAME + server-password: SERVER_PASSWORD + - run: mvn -B dependency:go-offline -q + - run: mvn -B deploy -Poss + env: + SERVER_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + SERVER_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..dd23793 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,6 @@ +# Default state for all rules +default: true + +# MD013/line-length - Line length +MD013: + line_length: 10000 diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..9d1b12e --- /dev/null +++ b/.yamllint @@ -0,0 +1,10 @@ +extends: default + +## see https://yamllint.readthedocs.io/en/stable/rules.html +rules: + + # no need for document start + document-start: disable + + # line length is not important + line-length: disable diff --git a/README.md b/README.md index 232bb4c..05d3835 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,22 @@ ### Available Appender - * console format - * Stackdriver format (with support for error reporting) +* console format +* Stackdriver format (with support for error reporting) ### Set log level based on MDC values Configuration: - * *enabled*: enable MDC filter (`true` is default) - * *key*: MDC key, is optional (will use name instead, see example `user` below) - * *level*: log level to use (`TRACE` is default) - * *loggers*: passlist of logger names, matches all loggers if empty - * *values*: values for matching MDC key, matches all values if empty + +* *enabled*: enable MDC filter (`true` is default) +* *key*: MDC key, is optional (will use name instead, see example `user` below) +* *level*: log level to use (`TRACE` is default) +* *loggers*: passlist of logger names, matches all loggers if empty +* *values*: values for matching MDC key, matches all values if empty Example for setting different values for different values/logger: -``` + +```yaml logger: levels: io.kokuwa: INFO @@ -26,36 +28,38 @@ logger: key: gateway level: DEBUG loggers: - - io.kokuwa + - io.kokuwa values: - - 6a1bae7f-eb6c-4c81-af9d-dc15396584e2 - - fb3318f1-2c73-48e9-acd4-a2be3c9f9256 + - 6a1bae7f-eb6c-4c81-af9d-dc15396584e2 + - fb3318f1-2c73-48e9-acd4-a2be3c9f9256 gateway-trace: key: gateway level: TRACE loggers: - - io.kokuwa - - io.micronaut + - io.kokuwa + - io.micronaut values: - - 257802b2-22fe-4dcc-bb99-c1db2a47861f + - 257802b2-22fe-4dcc-bb99-c1db2a47861f ``` Example for omiting level and key: -``` + +```yaml logger: levels: io.kokuwa: INFO mdc: gateway: loggers: - - io.kokuwa + - io.kokuwa values: - - 257802b2-22fe-4dcc-bb99-c1db2a47861f - - 0a44738b-0c3a-4798-8210-2495485f10b2 + - 257802b2-22fe-4dcc-bb99-c1db2a47861f + - 0a44738b-0c3a-4798-8210-2495485f10b2 ``` Example for minimal configuration: -``` + +```yaml logger: levels: io.kokuwa: INFO @@ -66,19 +70,22 @@ logger: ### Set log level based on HTTP request header Configuration for server filter (prefixed with *logger.request.filter*): - * *enabled*: enable HTTP server filter (`true` is default) - * *order*: order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/master/core/src/main/java/io/micronaut/core/order/Ordered.java) (highest is default) - * *path*: filter path (`/**` is default) - * *header*: name of HTTP header (`x-log-level` is default) - + +* *enabled*: enable HTTP server filter (`true` is default) +* *order*: order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/master/core/src/main/java/io/micronaut/core/order/Ordered.java) (highest is default) +* *path*: filter path (`/**` is default) +* *header*: name of HTTP header (`x-log-level` is default) + Configuration for client filter for propagation (prefixed with *logger.request.propagation*): - * *enabled*: enable HTTP client filter (`true` is default) - * *order*: order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/master/core/src/main/java/io/micronaut/core/order/Ordered.java) (tracing is default) - * *path*: filter path (`/**` is default) - * *header*: name of HTTP header (server header is default) + +* *enabled*: enable HTTP client filter (`true` is default) +* *order*: order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/master/core/src/main/java/io/micronaut/core/order/Ordered.java) (tracing is default) +* *path*: filter path (`/**` is default) +* *header*: name of HTTP header (server header is default) Example with default configuration: -``` + +```yaml logger: request: filter: @@ -96,13 +103,15 @@ logger: ### Add principal for request to MDC Configuration: - * *enabled*: enable HTTP principal filter (`true` is default) - * *order*: order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/master/core/src/main/java/io/micronaut/core/order/Ordered.java) ([ServerFilterPhase.SECURITY.after()](https://github.com/micronaut-projects/micronaut-core/blob/v2.0.1/http/src/main/java/io/micronaut/http/filter/ServerFilterPhase.java#L54) is default) - * *path*: filter path (`/**` is default) - * *key*: name of MDC header (`principal` is default) + +* *enabled*: enable HTTP principal filter (`true` is default) +* *order*: order for [Ordered](https://github.com/micronaut-projects/micronaut-core/blob/master/core/src/main/java/io/micronaut/core/order/Ordered.java) ([ServerFilterPhase.SECURITY.after()](https://github.com/micronaut-projects/micronaut-core/blob/v2.0.1/http/src/main/java/io/micronaut/http/filter/ServerFilterPhase.java#L54) is default) +* *path*: filter path (`/**` is default) +* *key*: name of MDC header (`principal` is default) Example with default configuration: -``` + +```yaml logger: request: principal: @@ -117,25 +126,28 @@ logger: ### Dependency updates Display dependency updates: -``` + +```sh mvn versions:display-property-updates -U ``` Update dependencies: -``` + +```sh mvn versions:update-properties ``` ### Release locally Run: -``` -mvn release:prepare release:perform release:clean -B + +```sh +mvn release:prepare release:perform release:clean -B -DreleaseProfiles=oss-release ``` ## Open Topics - * configure mdc on refresh event - * add stackdriver per configuration - * add fluent per configuration - * read **serviceName** and **serviceVersion** from yaml +* configure mdc on refresh event +* add stackdriver per configuration +* add fluent per configuration +* read **serviceName** and **serviceVersion** from yaml diff --git a/src/test/resources/application-test-composite.yaml b/src/test/resources/application-test-composite.yaml index 7ba34db..d15a885 100644 --- a/src/test/resources/application-test-composite.yaml +++ b/src/test/resources/application-test-composite.yaml @@ -3,6 +3,6 @@ logger: principal: level: DEBUG loggers: - - io.kokuwa + - io.kokuwa values: - - horst + - horst diff --git a/src/test/resources/application-test-mdc.yaml b/src/test/resources/application-test-mdc.yaml index ef6bfc5..c0fd2a2 100644 --- a/src/test/resources/application-test-mdc.yaml +++ b/src/test/resources/application-test-mdc.yaml @@ -4,23 +4,23 @@ logger: key: key level: DEBUG loggers: - - io.kokuwa.a - - io.kokuwa.b + - io.kokuwa.a + - io.kokuwa.b values: - - value-1 - - value-2 + - value-1 + - value-2 key2: key: key level: TRACE loggers: - - io.kokuwa.b - - io.kokuwa.c + - io.kokuwa.b + - io.kokuwa.c values: - - value-2 + - value-2 key: level: TRACE loggers: - - io.kokuwa + - io.kokuwa values: - - value-3 + - value-3 user: {}