github.com/prebid/prebid-server/v2@v2.18.0/.github/workflows/adapter-code-coverage.yml (about) 1 name: Adapter code coverage 2 on: 3 pull_request_target: 4 paths: ["adapters/*/*.go"] 5 permissions: 6 pull-requests: write 7 contents: write 8 jobs: 9 run-coverage: 10 runs-on: ubuntu-latest 11 steps: 12 - name: Install Go 13 uses: actions/setup-go@v5 14 with: 15 go-version: 1.20.5 16 17 - name: Checkout pull request branch 18 uses: actions/checkout@v4 19 with: 20 fetch-depth: 0 21 ref: ${{github.event.pull_request.head.ref}} 22 repository: ${{github.event.pull_request.head.repo.full_name}} 23 24 - name: Get adapter directories 25 id: get_directories 26 uses: actions/github-script@v7 27 with: 28 result-encoding: string 29 script: | 30 const utils = require('./.github/workflows/helpers/pull-request-utils.js') 31 function directoryExtractor(filepath, status) { 32 // extract directory name only if file is not removed and file is in adapters directory 33 if (status != "removed" && filepath.startsWith("adapters/") && filepath.split("/").length > 2) { 34 return filepath.split("/")[1] 35 } 36 return "" 37 } 38 const helper = utils.diffHelper({github, context}) 39 const directories = await helper.getDirectories(directoryExtractor) 40 // run coverage for maximum of 2 directories 41 return (directories.length == 0 || directories.length > 2) ? "" : JSON.stringify(directories) 42 43 - name: Run coverage tests 44 id: run_coverage 45 if: steps.get_directories.outputs.result != '' 46 run: | 47 directories=$(echo '${{ steps.get_directories.outputs.result }}' | jq -r '.[]') 48 go mod download 49 50 # create a temporary directory to store the coverage output 51 temp_dir=$(mktemp -d) 52 touch ${temp_dir}/coverage_output.txt 53 54 # generate coverage for adapter 55 cd ./adapters 56 for directory in $directories; do 57 cd $directory 58 coverage_profile_path="${PWD}/${directory}.out" 59 go test -coverprofile="${coverage_profile_path}" 60 go tool cover -html="${coverage_profile_path}" -o "${temp_dir}/${directory}.html" 61 go tool cover -func="${coverage_profile_path}" -o "${temp_dir}/${directory}.txt" 62 cd .. 63 done 64 echo "coverage_dir=${temp_dir}" >> $GITHUB_OUTPUT 65 66 # remove pull request branch files 67 cd .. 68 rm -f -r ./* 69 70 - name: Checkout coverage-preview branch 71 uses: actions/checkout@v4 72 with: 73 fetch-depth: 0 74 ref: coverage-preview 75 repository: prebid/prebid-server 76 77 - name: Commit coverage files to coverage-preview branch 78 if: steps.run_coverage.outputs.coverage_dir != '' 79 id: commit_coverage 80 run: | 81 directory=.github/preview/${{ github.run_id }}_$(date +%s) 82 mkdir -p $directory 83 cp -r ${{ steps.run_coverage.outputs.coverage_dir }}/*.html ./$directory 84 git config --global user.name "github-actions[bot]" 85 git config --global user.email "github-actions[bot]@users.noreply.github.com" 86 git add $directory/* 87 git commit -m 'Add coverage files' 88 git push origin coverage-preview 89 echo "remote_coverage_preview_dir=${directory}" >> $GITHUB_OUTPUT 90 91 - name: Checkout master branch 92 if: steps.get_directories.outputs.result != '' 93 run: git checkout master 94 95 - name: Add coverage summary to pull request 96 if: steps.run_coverage.outputs.coverage_dir != '' && steps.commit_coverage.outputs.remote_coverage_preview_dir != '' 97 uses: actions/github-script@v7 98 with: 99 script: | 100 const utils = require('./.github/workflows/helpers/pull-request-utils.js') 101 const helper = utils.coverageHelper({ 102 github, context, 103 headSha: '${{ github.event.pull_request.head.sha }}', 104 tmpCoverageDir: '${{ steps.run_coverage.outputs.coverage_dir }}', 105 remoteCoverageDir: '${{ steps.commit_coverage.outputs.remote_coverage_preview_dir }}' 106 }) 107 const adapterDirectories = JSON.parse('${{ steps.get_directories.outputs.result }}') 108 await helper.AddCoverageSummary(adapterDirectories)