diff --git a/.github/actions/create-lines-of-code-report/action.yaml b/.github/actions/create-lines-of-code-report/action.yaml deleted file mode 100644 index b21f0667020..00000000000 --- a/.github/actions/create-lines-of-code-report/action.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: "Count lines of code" -description: "Count lines of code" -inputs: - build_datetime: - description: "Build datetime, set by the CI/CD pipeline workflow" - required: true - build_timestamp: - description: "Build timestamp, set by the CI/CD pipeline workflow" - required: true - idp_aws_report_upload_account_id: - description: "IDP AWS account ID" - required: true - idp_aws_report_upload_region: - description: "IDP AWS account region" - required: true - idp_aws_report_upload_role_name: - description: "Role to upload the report" - required: true - idp_aws_report_upload_bucket_endpoint: - description: "Bucket endpoint for the report" - required: true -runs: - using: "composite" - steps: - - name: "Create CLOC report" - shell: bash - run: | - export BUILD_DATETIME=${{ inputs.build_datetime }} - ./scripts/reports/create-lines-of-code-report.sh - - name: "Compress CLOC report" - shell: bash - run: zip lines-of-code-report.json.zip lines-of-code-report.json - - name: "Upload CLOC report as an artefact" - if: ${{ !env.ACT }} - uses: actions/upload-artifact@v4 - with: - name: lines-of-code-report.json.zip - path: ./lines-of-code-report.json.zip - retention-days: 21 - - name: "Check prerequisites for sending the report" - shell: bash - id: check - run: | - echo "secrets_exist=${{ inputs.idp_aws_report_upload_role_name != '' && inputs.idp_aws_report_upload_bucket_endpoint != '' }}" >> $GITHUB_OUTPUT - - name: "Authenticate to send the report" - if: steps.check.outputs.secrets_exist == 'true' - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: arn:aws:iam::${{ inputs.idp_aws_report_upload_account_id }}:role/${{ inputs.idp_aws_report_upload_role_name }} - aws-region: ${{ inputs.idp_aws_report_upload_region }} - - name: "Send the CLOC report to the central location" - shell: bash - if: steps.check.outputs.secrets_exist == 'true' - run: | - aws s3 cp \ - ./lines-of-code-report.json.zip \ - ${{ inputs.idp_aws_report_upload_bucket_endpoint }}/${{ inputs.build_timestamp }}-lines-of-code-report.json.zip diff --git a/.github/workflows/stage-1-commit.yaml b/.github/workflows/stage-1-commit.yaml index 209efb0d25e..4fc82c64edd 100644 --- a/.github/workflows/stage-1-commit.yaml +++ b/.github/workflows/stage-1-commit.yaml @@ -73,25 +73,6 @@ jobs: fetch-depth: 0 # Full history is needed to compare branches - name: "Check English usage" uses: ./.github/actions/check-english-usage - count-lines-of-code: - name: "Count lines of code" - runs-on: ubuntu-latest - permissions: - id-token: write - contents: read - timeout-minutes: 2 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Count lines of code" - uses: ./.github/actions/create-lines-of-code-report - with: - build_datetime: "${{ inputs.build_datetime }}" - build_timestamp: "${{ inputs.build_timestamp }}" - idp_aws_report_upload_account_id: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ACCOUNT_ID }}" - idp_aws_report_upload_region: "${{ secrets.IDP_AWS_REPORT_UPLOAD_REGION }}" - idp_aws_report_upload_role_name: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ROLE_NAME }}" - idp_aws_report_upload_bucket_endpoint: "${{ secrets.IDP_AWS_REPORT_UPLOAD_BUCKET_ENDPOINT }}" scan-dependencies: name: "Scan dependencies" runs-on: ubuntu-latest diff --git a/scripts/reports/create-lines-of-code-report.sh b/scripts/reports/create-lines-of-code-report.sh deleted file mode 100755 index 01645c7d049..00000000000 --- a/scripts/reports/create-lines-of-code-report.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash - -# WARNING: Please, DO NOT edit this file! It is maintained in the Repository Template (https://github.com/nhs-england-tools/repository-template). Raise a PR instead. - -set -euo pipefail - -# Count lines of code of this repository. This is a gocloc command wrapper. It -# will run gocloc natively if it is installed, otherwise it will run it in a -# Docker container. -# -# Usage: -# $ [options] ./create-lines-of-code-report.sh -# -# Options: -# BUILD_DATETIME=%Y-%m-%dT%H:%M:%S%z # Build datetime, default is `date -u +'%Y-%m-%dT%H:%M:%S%z'` -# FORCE_USE_DOCKER=true # If set to true the command is run in a Docker container, default is 'false' -# VERBOSE=true # Show all the executed commands, default is `false` - -# ============================================================================== - -function main() { - - cd "$(git rev-parse --show-toplevel)" - - create-report - enrich-report -} - -function create-report() { - - if command -v gocloc > /dev/null 2>&1 && ! is-arg-true "${FORCE_USE_DOCKER:-false}"; then - run-gocloc-natively - else - run-gocloc-in-docker - fi - # shellcheck disable=SC2002 - cat lines-of-code-report.tmp.json \ - | jq -r '["Language","files","blank","comment","code"],["--------"],(.languages[]|[.name,.files,.blank,.comment,.code]),["-----"],(.total|["TOTAL",.files,.blank,.comment,.code])|@tsv' \ - | sed 's/Plain Text/Plaintext/g' \ - | column -t -} - -function run-gocloc-natively() { - - gocloc --output-type=json . > lines-of-code-report.tmp.json -} - -function run-gocloc-in-docker() { - - # shellcheck disable=SC1091 - source ./scripts/docker/docker.lib.sh - - # shellcheck disable=SC2155 - local image=$(name=ghcr.io/make-ops-tools/gocloc docker-get-image-version-and-pull) - docker run --rm --platform linux/amd64 \ - --volume "$PWD":/workdir \ - "$image" \ - --output-type=json \ - . \ - > lines-of-code-report.tmp.json -} - -function enrich-report() { - - build_datetime=${BUILD_DATETIME:-$(date -u +'%Y-%m-%dT%H:%M:%S%z')} - git_url=$(git config --get remote.origin.url) - git_branch=$(git rev-parse --abbrev-ref HEAD) - git_commit_hash=$(git rev-parse HEAD) - git_tags=$(echo \""$(git tag | tr '\n' ',' | sed 's/,$//' | sed 's/,/","/g')"\" | sed 's/""//g') - pipeline_run_id=${GITHUB_RUN_ID:-0} - pipeline_run_number=${GITHUB_RUN_NUMBER:-0} - pipeline_run_attempt=${GITHUB_RUN_ATTEMPT:-0} - - # shellcheck disable=SC2086 - jq \ - '.creationInfo |= . + {"created":"'${build_datetime}'","repository":{"url":"'${git_url}'","branch":"'${git_branch}'","tags":['${git_tags}'],"commitHash":"'${git_commit_hash}'"},"pipeline":{"id":'${pipeline_run_id}',"number":'${pipeline_run_number}',"attempt":'${pipeline_run_attempt}'}}' \ - lines-of-code-report.tmp.json \ - > lines-of-code-report.json - rm -f lines-of-code-report.tmp.json -} - -# ============================================================================== - -function is-arg-true() { - - if [[ "$1" =~ ^(true|yes|y|on|1|TRUE|YES|Y|ON)$ ]]; then - return 0 - else - return 1 - fi -} - -# ============================================================================== - -is-arg-true "${VERBOSE:-false}" && set -x - -main "$@" - -exit 0