From d5fc17c8ddbb1410b0f52ef8cf56bdcef4d2b572 Mon Sep 17 00:00:00 2001 From: Tetsuro Yoshikawa Date: Tue, 17 May 2022 01:11:46 +0900 Subject: [PATCH 1/2] chore: for fail npx. --- .github/workflows/review.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml index 706f7ff..f8a1ff6 100644 --- a/.github/workflows/review.yml +++ b/.github/workflows/review.yml @@ -29,7 +29,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm ci --ignore-scripts - run: npm run test - - if: ${{ matrix.node-version == '18.x' }} + - if: ${{ matrix.node-version == '16.x' }} name: Get Coverage for badge run: | SUMMARY="$(npm test -- --silent --coverage --coverageReporters='text-summary' | tail -4 | head -1)" @@ -51,7 +51,7 @@ jobs: echo $BRANCH_NAME echo "BRANCH=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV - - if: ${{ matrix.node-version == '18.x' }} + - if: ${{ matrix.node-version == '16.x' }} name: Create the Coverage Badge uses: schneegans/dynamic-badges-action@v1.0.0 with: @@ -63,7 +63,7 @@ jobs: color: ${{ env.COVERAGE_COLOR }} namedLogo: jest - - if: ${{ matrix.node-version == '18.x' }} + - if: ${{ matrix.node-version == '16.x' }} name: Create the LineOfCode Badge uses: schneegans/dynamic-badges-action@v1.0.0 with: @@ -74,7 +74,7 @@ jobs: message: ${{ env.LINE_OF_CODE }} color: ${{ env.LINE_OF_CODE_COLOR }} - - if: ${{ matrix.node-version == '18.x' }} + - if: ${{ matrix.node-version == '16.x' }} name: Create the CognitiveComplexity Badge uses: schneegans/dynamic-badges-action@v1.0.0 with: @@ -85,7 +85,7 @@ jobs: message: ${{ env.COGNITIVE_COMPLEXITY }} color: ${{ env.COGNITIVE_COMPLEXITY_COLOR }} - - if: ${{ matrix.node-version == '18.x' }} + - if: ${{ matrix.node-version == '16.x' }} name: Create the Maintainability Badge uses: schneegans/dynamic-badges-action@v1.0.0 with: From 1954e7d6ac0059df1c0c3b757c73e1c7a73536a2 Mon Sep 17 00:00:00 2001 From: Tetsuro Yoshikawa Date: Tue, 17 May 2022 01:25:51 +0900 Subject: [PATCH 2/2] chore: separated workflow, for badge generate and release and auto test. --- .github/workflows/build.yml | 81 ++++++++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 10 ++--- .github/workflows/review.yml | 66 ----------------------------- 3 files changed, 86 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3095c09 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,81 @@ +name: Build +on: + push: + branches: + - master + workflow_dispatch: +jobs: + generateBadge: + name: GenerateBadge + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['16.x'] + fail-fast: false + steps: + - uses: actions/checkout@v1 + - name: Setting up Node.js (v${{ matrix.node-version }}.x) + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Get Coverage for badge + run: | + SUMMARY="$(npm test -- --silent --coverage --coverageReporters='text-summary' | tail -4 | head -1)" + TOKENS=($SUMMARY) + echo "COVERAGE=$(echo ${TOKENS[2]})" >> $GITHUB_ENV + echo "COVERAGE_COLOR=$(([[ ${TOKENS[2]%%.*} -ge 80 ]] && echo "green") || ([[ ${TOKENS[2]%%.*} -ge 50 ]] && echo "yellow") || echo "red")" >> $GITHUB_ENV + SUMMARY=$(npx sabik ./src -t JSON | jq -r '.summaries | (."LogicalLineOfCode(Average per method)".value|tostring) + " " + (."CognitiveComplexity(Max)".value|tostring) + " " + (."Maintainability(Min)".value|tostring)') + TOKENS=($SUMMARY) + echo "LINE_OF_CODE=$(printf "%.2f\n" ${TOKENS[0]})" >> $GITHUB_ENV + echo "LINE_OF_CODE_COLOR=$(([[ ${TOKENS[0]%%.*} -le 15 ]] && echo "green") || ([[ ${TOKENS[0]%%.*} -le 20 ]] && echo "yellow") || echo "red")" >> $GITHUB_ENV + echo "COGNITIVE_COMPLEXITY=$(printf "%.2f\n" ${TOKENS[1]})" >> $GITHUB_ENV + echo "COGNITIVE_COMPLEXITY_COLOR=$(([[ ${TOKENS[1]%%.*} -le 8 ]] && echo "green") || echo "red")" >> $GITHUB_ENV + echo "MAINTAINABILITY=$(printf "%.2f\n" ${TOKENS[2]})" >> $GITHUB_ENV + echo "MAINTAINABILITY_COLOR=$(([[ ${TOKENS[2]%%.*} -ge 80 ]] && echo "green") || ([[ ${TOKENS[2]%%.*} -ge 50 ]] && echo "yellow") || echo "red")" >> $GITHUB_ENV + REF=${{ github.ref }} + echo "github.ref: $REF" + IFS='/' read -ra PATHS <<< "$REF" + BRANCH_NAME="${PATHS[1]}_${PATHS[2]}" + echo $BRANCH_NAME + echo "BRANCH=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV + + - name: Create the Coverage Badge + uses: schneegans/dynamic-badges-action@v1.0.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: 32248b8c823155bb09711c7a5b960d3d + filename: sabik_coverage_${{ env.BRANCH }}.json + label: Test Coverage + message: ${{ env.COVERAGE }} + color: ${{ env.COVERAGE_COLOR }} + namedLogo: jest + + - name: Create the LineOfCode Badge + uses: schneegans/dynamic-badges-action@v1.0.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: 32248b8c823155bb09711c7a5b960d3d + filename: sabik_line_of_code_${{ env.BRANCH }}.json + label: LogicalLineOfCode(Average per method) + message: ${{ env.LINE_OF_CODE }} + color: ${{ env.LINE_OF_CODE_COLOR }} + + - name: Create the CognitiveComplexity Badge + uses: schneegans/dynamic-badges-action@v1.0.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: 32248b8c823155bb09711c7a5b960d3d + filename: sabik_cognitive_complexity_${{ env.BRANCH }}.json + label: CognitiveComplexity(Max) + message: ${{ env.COGNITIVE_COMPLEXITY }} + color: ${{ env.COGNITIVE_COMPLEXITY_COLOR }} + + - name: Create the Maintainability Badge + uses: schneegans/dynamic-badges-action@v1.0.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: 32248b8c823155bb09711c7a5b960d3d + filename: sabik_maintainability_${{ env.BRANCH }}.json + label: Maintainability(Min) + message: ${{ env.MAINTAINABILITY }} + color: ${{ env.MAINTAINABILITY_COLOR }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 42392f8..316b058 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,12 +1,12 @@ name: Publish on: - push: - branches: - - master - workflow_dispatch: + workflow_run: + workflows: [Build] + types: + - completed jobs: deploy: - name: Build + name: Release runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml index f8a1ff6..d69c881 100644 --- a/.github/workflows/review.yml +++ b/.github/workflows/review.yml @@ -29,72 +29,6 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm ci --ignore-scripts - run: npm run test - - if: ${{ matrix.node-version == '16.x' }} - name: Get Coverage for badge - run: | - SUMMARY="$(npm test -- --silent --coverage --coverageReporters='text-summary' | tail -4 | head -1)" - TOKENS=($SUMMARY) - echo "COVERAGE=$(echo ${TOKENS[2]})" >> $GITHUB_ENV - echo "COVERAGE_COLOR=$(([[ ${TOKENS[2]%%.*} -ge 80 ]] && echo "green") || ([[ ${TOKENS[2]%%.*} -ge 50 ]] && echo "yellow") || echo "red")" >> $GITHUB_ENV - SUMMARY=$(npx sabik ./src -t JSON | jq -r '.summaries | (."LogicalLineOfCode(Average per method)".value|tostring) + " " + (."CognitiveComplexity(Max)".value|tostring) + " " + (."Maintainability(Min)".value|tostring)') - TOKENS=($SUMMARY) - echo "LINE_OF_CODE=$(printf "%.2f\n" ${TOKENS[0]})" >> $GITHUB_ENV - echo "LINE_OF_CODE_COLOR=$(([[ ${TOKENS[0]%%.*} -le 15 ]] && echo "green") || ([[ ${TOKENS[0]%%.*} -le 20 ]] && echo "yellow") || echo "red")" >> $GITHUB_ENV - echo "COGNITIVE_COMPLEXITY=$(printf "%.2f\n" ${TOKENS[1]})" >> $GITHUB_ENV - echo "COGNITIVE_COMPLEXITY_COLOR=$(([[ ${TOKENS[1]%%.*} -le 8 ]] && echo "green") || echo "red")" >> $GITHUB_ENV - echo "MAINTAINABILITY=$(printf "%.2f\n" ${TOKENS[2]})" >> $GITHUB_ENV - echo "MAINTAINABILITY_COLOR=$(([[ ${TOKENS[2]%%.*} -ge 80 ]] && echo "green") || ([[ ${TOKENS[2]%%.*} -ge 50 ]] && echo "yellow") || echo "red")" >> $GITHUB_ENV - REF=${{ github.ref }} - echo "github.ref: $REF" - IFS='/' read -ra PATHS <<< "$REF" - BRANCH_NAME="${PATHS[1]}_${PATHS[2]}" - echo $BRANCH_NAME - echo "BRANCH=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV - - - if: ${{ matrix.node-version == '16.x' }} - name: Create the Coverage Badge - uses: schneegans/dynamic-badges-action@v1.0.0 - with: - auth: ${{ secrets.GIST_SECRET }} - gistID: 32248b8c823155bb09711c7a5b960d3d - filename: sabik_coverage_${{ env.BRANCH }}.json - label: Test Coverage - message: ${{ env.COVERAGE }} - color: ${{ env.COVERAGE_COLOR }} - namedLogo: jest - - - if: ${{ matrix.node-version == '16.x' }} - name: Create the LineOfCode Badge - uses: schneegans/dynamic-badges-action@v1.0.0 - with: - auth: ${{ secrets.GIST_SECRET }} - gistID: 32248b8c823155bb09711c7a5b960d3d - filename: sabik_line_of_code_${{ env.BRANCH }}.json - label: LogicalLineOfCode(Average per method) - message: ${{ env.LINE_OF_CODE }} - color: ${{ env.LINE_OF_CODE_COLOR }} - - - if: ${{ matrix.node-version == '16.x' }} - name: Create the CognitiveComplexity Badge - uses: schneegans/dynamic-badges-action@v1.0.0 - with: - auth: ${{ secrets.GIST_SECRET }} - gistID: 32248b8c823155bb09711c7a5b960d3d - filename: sabik_cognitive_complexity_${{ env.BRANCH }}.json - label: CognitiveComplexity(Max) - message: ${{ env.COGNITIVE_COMPLEXITY }} - color: ${{ env.COGNITIVE_COMPLEXITY_COLOR }} - - - if: ${{ matrix.node-version == '16.x' }} - name: Create the Maintainability Badge - uses: schneegans/dynamic-badges-action@v1.0.0 - with: - auth: ${{ secrets.GIST_SECRET }} - gistID: 32248b8c823155bb09711c7a5b960d3d - filename: sabik_maintainability_${{ env.BRANCH }}.json - label: Maintainability(Min) - message: ${{ env.MAINTAINABILITY }} - color: ${{ env.MAINTAINABILITY_COLOR }} build: name: Build