Skip to content

Adhese: Switch to openrtb2 endpoint #1203

Adhese: Switch to openrtb2 endpoint

Adhese: Switch to openrtb2 endpoint #1203

name: Adapter Code Coverage
on:
pull_request_target:
paths: ["adapters/*/*.go"]
permissions:
pull-requests: write
contents: write
jobs:
run-coverage:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.22.3
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Discover Adapter Directories
id: get_directories
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const utils = require('./.github/workflows/helpers/pull-request-utils.js')
function directoryExtractor(filepath, status) {
// extract directory name only if file is not removed and file is in adapters directory
if (status != "removed" && filepath.startsWith("adapters/") && filepath.split("/").length > 2) {
return filepath.split("/")[1]
}
return ""
}
const helper = utils.diffHelper({github, context})
const directories = await helper.getDirectories(directoryExtractor)
// run coverage for maximum of 2 directories
return (directories.length == 0 || directories.length > 2) ? "" : JSON.stringify(directories)
- name: Run Coverage Tests
id: run_coverage
if: steps.get_directories.outputs.result != ''
run: |
directories=$(echo '${{ steps.get_directories.outputs.result }}' | jq -r '.[]')
go mod download
# create a temporary directory to store the coverage output
temp_dir=$(mktemp -d)
touch ${temp_dir}/coverage_output.txt
# generate coverage for adapter
cd ./adapters
for directory in $directories; do
cd $directory
coverage_profile_path="${PWD}/${directory}.out"
go test -coverprofile="${coverage_profile_path}"
go tool cover -html="${coverage_profile_path}" -o "${temp_dir}/${directory}.html"
go tool cover -func="${coverage_profile_path}" -o "${temp_dir}/${directory}.txt"
cd ..
done
echo "coverage_dir=${temp_dir}" >> $GITHUB_OUTPUT
# remove pull request branch files
cd ..
rm -f -r ./*
- name: Checkout Coverage Preview Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: coverage-preview
repository: prebid/prebid-server
- name: Upload Coverage Results
if: steps.run_coverage.outputs.coverage_dir != ''
id: commit_coverage
run: |
directory=.github/preview/${{ github.run_id }}_$(date +%s)
mkdir -p $directory
cp -r ${{ steps.run_coverage.outputs.coverage_dir }}/*.html ./$directory
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add $directory/*
git commit -m 'Add coverage files'
git push origin coverage-preview
echo "remote_coverage_preview_dir=${directory}" >> $GITHUB_OUTPUT
- name: Checkout Master Branch
if: steps.get_directories.outputs.result != ''
run: git checkout master
- name: Add Coverage Summary To Pull Request
if: steps.run_coverage.outputs.coverage_dir != '' && steps.commit_coverage.outputs.remote_coverage_preview_dir != ''
uses: actions/github-script@v7
with:
script: |
const utils = require('./.github/workflows/helpers/pull-request-utils.js')
const helper = utils.coverageHelper({
github, context,
headSha: '${{ github.event.pull_request.head.sha }}',
tmpCoverageDir: '${{ steps.run_coverage.outputs.coverage_dir }}',
remoteCoverageDir: '${{ steps.commit_coverage.outputs.remote_coverage_preview_dir }}'
})
const adapterDirectories = JSON.parse('${{ steps.get_directories.outputs.result }}')
await helper.AddCoverageSummary(adapterDirectories)