diff --git a/.github/workflows/build-status.yml b/.github/workflows/build-status.yml index 3b24f4845..de9d38b3b 100644 --- a/.github/workflows/build-status.yml +++ b/.github/workflows/build-status.yml @@ -4,6 +4,9 @@ on: branches: - master +permissions: + contents: read + jobs: build-and-test: name: Build And Test ${{matrix.os}} @@ -81,21 +84,37 @@ jobs: uses: actions/download-artifact@v8 with: name: coverage-reports + path: ${{ runner.temp }}/artifacts - - name: Set Coverage Report Paths - id: coverage-paths + - name: Download Codacy Coverage Reporter + env: + CODACY_REPORTER_VERSION: 14.1.3 + CODACY_REPORTER_SHA256: 15c5f052207d27b8501ab5d5910c68c206ea70b0157ee1725132780530580875 run: | - readarray -d '' coveragePathArray < <(find . -name "coverage.cobertura.xml" -print0) - coveragePaths=$(printf -- "-r %s " "${coveragePathArray[@]}") - echo "COVERAGE_REPORT_PATHS=$coveragePaths" >> $GITHUB_OUTPUT + reporter="$RUNNER_TEMP/codacy/codacy-coverage-reporter" + mkdir -p "$(dirname "$reporter")" + curl --proto "=https" --proto-redir "=https" --tlsv1.2 -fsSL --retry 3 -o "$reporter" \ + "https://github.com/codacy/codacy-coverage-reporter/releases/download/${CODACY_REPORTER_VERSION}/codacy-coverage-reporter-linux" + echo "${CODACY_REPORTER_SHA256} ${reporter}" | sha256sum --check --strict + chmod +x "$reporter" - name: Publish Code Coverage Results + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} run: | - auth="--project-token ${{ secrets.CODACY_PROJECT_TOKEN }}" + reports=() + while IFS= read -r -d '' file; do + reports+=(-r "$file") + done < <(find "$RUNNER_TEMP/artifacts" -type f -name "coverage.cobertura.xml" -print0) + + if [ ${#reports[@]} -eq 0 ]; then + echo "::error::No coverage reports found in artifact" + exit 1 + fi - bash <(curl -Ls https://coverage.codacy.com/get.sh) report $auth \ - ${{ steps.coverage-paths.outputs.COVERAGE_REPORT_PATHS }} --partial &&\ - bash <(curl -Ls https://coverage.codacy.com/get.sh) final $auth + reporter="$RUNNER_TEMP/codacy/codacy-coverage-reporter" + "$reporter" report "${reports[@]}" --partial &&\ + "$reporter" final report-benchmark-results: needs: build-and-test @@ -108,6 +127,7 @@ jobs: uses: actions/download-artifact@v8 with: name: benchmark-results + path: ${{ runner.temp }}/artifacts - name: 'Report benchmark result' - run: cat ./NHapi.Benchmarks.LargeEmbeddedFileTest-report-github.md >> $GITHUB_STEP_SUMMARY + run: cat "$RUNNER_TEMP/artifacts/NHapi.Benchmarks.LargeEmbeddedFileTest-report-github.md" >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/publish-pr-coverage-results.yml b/.github/workflows/publish-pr-coverage-results.yml index d6c8138eb..348ecc796 100644 --- a/.github/workflows/publish-pr-coverage-results.yml +++ b/.github/workflows/publish-pr-coverage-results.yml @@ -6,36 +6,65 @@ on: types: - completed +permissions: + contents: read + jobs: publish-test-results: name: Publish Code Coverage Results runs-on: ubuntu-latest + permissions: + actions: read # the build-and-test job might be skipped, we don't need to run this job then - if: > + if: >- ${{ github.event.workflow_run.event == 'pull_request' && ( github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' ) }} steps: + # The artifact comes from an untrusted pull request build. It is downloaded + # outside the workspace, nothing in it is ever executed, and only regular + # coverage.cobertura.xml files are read from it as data. - name: 'Download artifact' uses: actions/download-artifact@v8 with: name: coverage-reports + path: ${{ runner.temp }}/artifacts github-token: ${{ secrets.GITHUB_TOKEN }} run-id: ${{ github.event.workflow_run.id }} - - name: Set Coverage Report Paths - id: coverage-paths + - name: Download Codacy Coverage Reporter + env: + CODACY_REPORTER_VERSION: 14.1.3 + CODACY_REPORTER_SHA256: 15c5f052207d27b8501ab5d5910c68c206ea70b0157ee1725132780530580875 run: | - readarray -d '' coveragePathArray < <(find . -name "coverage.cobertura.xml" -print0) - coveragePaths=$(printf -- "-r %s " "${coveragePathArray[@]}") - echo "COVERAGE_REPORT_PATHS=$coveragePaths" >> $GITHUB_OUTPUT + reporter="$RUNNER_TEMP/codacy/codacy-coverage-reporter" + mkdir -p "$(dirname "$reporter")" + curl --proto "=https" --proto-redir "=https" --tlsv1.2 -fsSL --retry 3 -o "$reporter" \ + "https://github.com/codacy/codacy-coverage-reporter/releases/download/${CODACY_REPORTER_VERSION}/codacy-coverage-reporter-linux" + echo "${CODACY_REPORTER_SHA256} ${reporter}" | sha256sum --check --strict + chmod +x "$reporter" - name: Publish Code Coverage Results + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} run: | - auth="--project-token ${{ secrets.CODACY_PROJECT_TOKEN }}" + if [[ ! "$HEAD_SHA" =~ ^[0-9a-f]{40}$ ]]; then + echo "::error::Unexpected head SHA format" + exit 1 + fi + + reports=() + while IFS= read -r -d '' file; do + reports+=(-r "$file") + done < <(find "$RUNNER_TEMP/artifacts" -type f -name "coverage.cobertura.xml" -print0) + + if [ ${#reports[@]} -eq 0 ]; then + echo "::error::No coverage reports found in artifact" + exit 1 + fi - bash <(curl -Ls https://coverage.codacy.com/get.sh) report $auth \ - --commit-uuid ${{ github.event.workflow_run.head_sha }} \ - ${{ steps.coverage-paths.outputs.COVERAGE_REPORT_PATHS }} --partial &&\ - bash <(curl -Ls https://coverage.codacy.com/get.sh) final $auth + reporter="$RUNNER_TEMP/codacy/codacy-coverage-reporter" + "$reporter" report --commit-uuid "$HEAD_SHA" "${reports[@]}" --partial &&\ + "$reporter" final diff --git a/.github/workflows/publish-pr-test-results.yml b/.github/workflows/publish-pr-test-results.yml index 0eb5221ef..79dcec120 100644 --- a/.github/workflows/publish-pr-test-results.yml +++ b/.github/workflows/publish-pr-test-results.yml @@ -6,12 +6,19 @@ on: types: - completed +permissions: + contents: read + jobs: publish-test-results: name: Publish Test Results runs-on: ubuntu-latest + permissions: + actions: read + checks: write + pull-requests: write # the build-and-test job might be skipped, we don't need to run this job then - if: > + if: >- ${{ github.event.workflow_run.event == 'pull_request' && ( github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' ) }} @@ -21,6 +28,7 @@ jobs: uses: actions/download-artifact@v8 with: name: unit-test-results + path: artifacts/unit-test-results github-token: ${{ secrets.GITHUB_TOKEN }} run-id: ${{ github.event.workflow_run.id }} @@ -30,6 +38,6 @@ jobs: check_name: Unit Test Results github_token: ${{ secrets.GITHUB_TOKEN }} commit: ${{ github.event.workflow_run.head_sha }} - trx_files: "**/*.trx" + trx_files: "artifacts/unit-test-results/**/*.trx" report_individual_runs: true check_run_annotations: all tests, skipped tests diff --git a/.github/workflows/receive-pr.yml b/.github/workflows/receive-pr.yml index 7d2189d1e..21a387af9 100644 --- a/.github/workflows/receive-pr.yml +++ b/.github/workflows/receive-pr.yml @@ -2,6 +2,9 @@ name: Receive Pull Request on: [pull_request] +permissions: + contents: read + jobs: build-and-test: name: Build And Test ${{matrix.os}} diff --git a/.github/workflows/report-benchmark-results.yml b/.github/workflows/report-benchmark-results.yml index 2149f6469..a5801a5b6 100644 --- a/.github/workflows/report-benchmark-results.yml +++ b/.github/workflows/report-benchmark-results.yml @@ -6,12 +6,17 @@ on: types: - completed +permissions: + contents: read + jobs: publish-test-results: name: Report Benchmark Results runs-on: ubuntu-latest + permissions: + actions: read # the build-and-test job might be skipped, we don't need to run this job then - if: > + if: >- ${{ github.event.workflow_run.event == 'pull_request' && ( github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' ) }} @@ -20,8 +25,9 @@ jobs: uses: actions/download-artifact@v8 with: name: benchmark-results + path: ${{ runner.temp }}/artifacts github-token: ${{ secrets.GITHUB_TOKEN }} run-id: ${{ github.event.workflow_run.id }} - name: 'Report benchmark result' - run: cat ./NHapi.Benchmarks.LargeEmbeddedFileTest-report-github.md >> $GITHUB_STEP_SUMMARY + run: cat "$RUNNER_TEMP/artifacts/NHapi.Benchmarks.LargeEmbeddedFileTest-report-github.md" >> "$GITHUB_STEP_SUMMARY"