Skip to content

Commit

Permalink
ci: rework sonar scan workflow (#927)
Browse files Browse the repository at this point in the history
---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
zxkane authored May 5, 2024
1 parent 325e47a commit d9604d1
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 0 additions & 38 deletions .github/workflows/lint-pr.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .github/workflows/pull-request-lint.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions .github/workflows/release.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 18 additions & 17 deletions .github/workflows/sonar-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ jobs:
- 9000:9000
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: yarn install --check-files && yarn --cwd example/ install --check-files
- name: Run unit tests
run: npx projen test
- name: Configure sonarqube
env:
SONARQUBE_URL: http://localhost:9000
Expand All @@ -24,31 +32,24 @@ jobs:
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_HOST_URL: http://sonarqube:9000
SONAR_TOKEN: ${{ env.SONARQUBE_TOKEN }}
with:
args: >
-Dsonar.login=admin
-Dsonar.password=${{ secrets.SONARQUBE_ADMIN_PASSWORD }}
-Dsonar.projectKey=pr-${{ github.event.pull_request.number }}
# Check the Quality Gate status.
# - name: SonarQube Quality Gate check
# id: sonarqube-quality-gate-check
# uses: sonarsource/sonarqube-quality-gate-action@master
# # Force to fail step after specific time.
# timeout-minutes: 10
# env:
# DEBUG: "true"
# SONAR_TOKEN: ${{ env.SONARQUBE_TOKEN }}
# SONAR_HOST_URL: http://localhost:9000

- name: SonarQube Quality Gate check
id: sonarqube-quality-gate-check
uses: sonarsource/sonarqube-quality-gate-action@master
# Force to fail step after specific time.
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ env.SONARQUBE_TOKEN }}
SONAR_HOST_URL: http://localhost:9000
- uses: phwt/sonarqube-quality-gate-action@v1
id: quality-gate-check
if: always()
with:
sonar-project-key: pr-${{ github.event.pull_request.number }}
sonar-host-url: http://sonarqube:9000
sonar-token: ${{ env.SONARQUBE_TOKEN }}
github-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}

- name: Output result
run: |
echo "${{ steps.quality-gate-check.outputs.project-status }}"
echo "${{ steps.quality-gate-check.outputs.quality-gate-result }}"
2 changes: 1 addition & 1 deletion .github/workflows/sonarqube/sonar-configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ else
status_code=$(echo "$token_gen_resp" | sed 's/^.*HTTPSTATUS://')
if [ "$status_code" -eq 200 ]; then
token=$(echo "$response_body" | jq -r '.token')
echo "SONARQUBE_TOKEN=${token}:" >> $GITHUB_ENV
echo "SONARQUBE_TOKEN=${token}" >> $GITHUB_ENV
info "admin-ci-token generated."
else
error "admin-ci-token generation failed."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade-main.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
license: 'Apache-2.0', /* License's SPDX identifier. */
licensed: true, /* Indicates if a license should be added. */
// maxNodeVersion: undefined, /* Minimum node.js version to require via `engines` (inclusive). */
minNodeVersion: '16.20.0',
minNodeVersion: '20.12.2',
// npmAccess: undefined, /* Access level of the npm package. */
// npmDistTag: 'latest', /* Tags can be used to provide an alias instead of version numbers. */
// npmRegistryUrl: 'https://registry.npmjs.org', /* The base URL of the npm package registry. */
Expand Down Expand Up @@ -127,6 +127,20 @@ const project = new awscdk.AwsCdkConstructLibrary({
'---',
'By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.',
],
githubOptions: {
pullRequestLintOptions: {
semanticTitleOptions: {
types: [
'feat',
'fix',
'chore',
'docs',
'ci',
'tests',
],
},
},
},
// releaseBranches: [ 'main' ], /* Branches which trigger a release. */
// releaseEveryCommit: true, /* Automatically release new versions every commit to one of branches in `releaseBranches`. */
// releaseSchedule: undefined, /* CRON schedule to trigger new releases. */
Expand Down
2 changes: 1 addition & 1 deletion example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const env = vpcId ? {
region: process.env.CDK_DEFAULT_REGION,
} : undefined;

new SimpleNATStack(app, 'simple-nat-stack', {
new SimpleNATStack(app, 'simple-nat-stack', { //NOSONAR
env: env,
});

Expand Down
4 changes: 2 additions & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Customize sonar.sources, sonar.exclusions, sonar.coverage.exclusions, sonar.tests and sonar
# unit test coverage reports based on your solutions

# Refer to https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
# for details on sources and exclusions. Note also .gitignore
#
sonar.sources=src/
sonar.tests=test/

# Focusing sonarqube analysis on non test code first and reducing noise from analysis of test code. Projects
# can customize the exclusions to include analyzing of test code if desired
sonar.exclusions=example/

sonar.issue.ignore.multicriteria=e1,e2
# exclude False Positive findings for instantiating CDK objects only
sonar.issue.ignore.multicriteria.e1.ruleKey=typescript:S1848
sonar.issue.ignore.multicriteria.e1.resourceKey=src/**/*.ts
sonar.issue.ignore.multicriteria.e2.ruleKey=typescript:S3776
sonar.issue.ignore.multicriteria.e2.resourceKey=src/index.ts

# Code coverage Specific Properties
sonar.coverage.exclusions=examples/**
sonar.javascript.lcov.reportPaths=coverage/lcov.info

sonar.junit.reportPaths=test-reports/
sonar.junit.reportFormat=xml

# Encoding of the source files
sonar.sourceEncoding=UTF-8
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class SimpleNAT extends Resource {
constructor(scope: Construct, id: string, props: SimpleNATProps) {
super(scope, id);

var subnets;
let subnets;
try {
subnets = props.vpc.selectSubnets(props.natSubnetsSelection ?? {
subnetType: SubnetType.PUBLIC,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d9604d1

Please sign in to comment.