Skip to content

Commit

Permalink
Merge pull request #764 from PubMatic-OpenWrap/ci
Browse files Browse the repository at this point in the history
Openwrap_Release_23rd_April_2024
  • Loading branch information
pm-nilesh-chate authored Apr 22, 2024
2 parents f8c11c2 + 13816bd commit f9b88f3
Show file tree
Hide file tree
Showing 1,875 changed files with 59,569 additions and 27,393 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/adapter-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,39 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.5

- name: Checkout pull request branch
uses: actions/checkout@v3
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: Get adapter directories
id: get_directories
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const utils = require('./.github/workflows/helpers/pull-request-utils.js')
function directoryExtractor(filepath) {
// extract directory name from filepath of the form adapters/<adapter-name>/*.go
if (filepath.startsWith("adapters/") && filepath.split("/").length > 2) {
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 files = await helper.getDirectories(directoryExtractor)
return files.length == 0 ? "" : JSON.stringify(files);
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 }} != ""
if: steps.get_directories.outputs.result != ''
run: |
git config --global url."https://${USERNAME}:${TOKEN}@git.pubmatic.com".insteadOf "https://git.pubmatic.com"
Expand Down Expand Up @@ -74,14 +75,14 @@ jobs:
USERNAME: ${{ secrets.PM_OPENWRAP_CICD_USERNAME }}

- name: Checkout coverage-preview branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: coverage-preview
repository: PubMatic-OpenWrap/prebid-server

- name: Commit coverage files to coverage-preview branch
if: ${{ steps.run_coverage.outputs.coverage_dir }} != ""
if: steps.run_coverage.outputs.coverage_dir != ''
id: commit_coverage
run: |
directory=.github/preview/${{ github.run_id }}_$(date +%s)
Expand All @@ -95,12 +96,12 @@ jobs:
echo "remote_coverage_preview_dir=${directory}" >> $GITHUB_OUTPUT
- name: Checkout master branch
if: ${{ steps.get_directories.outputs.result }} != ""
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@v6
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')
Expand Down
31 changes: 28 additions & 3 deletions .github/workflows/helpers/pull-request-utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const synchronizeEvent = "synchronize",
openedEvent = "opened",
completedStatus = "completed",
resultSize = 100
resultSize = 100,
adminPermission = "admin",
writePermission = "write"

class diffHelper {
constructor(input) {
Expand Down Expand Up @@ -213,8 +215,8 @@ class diffHelper {
})

const directories = []
for (const { filename } of data) {
const directory = directoryExtractor(filename)
for (const { filename, status } of data) {
const directory = directoryExtractor(filename, status)
if (directory != "" && !directories.includes(directory)) {
directories.push(directory)
}
Expand Down Expand Up @@ -407,8 +409,31 @@ class coverageHelper {
}
}

class userHelper {
constructor(input) {
this.owner = input.context.repo.owner
this.repo = input.context.repo.repo
this.github = input.github
this.user = input.user
}

/*
Checks if the user has write permissions for the repository
@returns {boolean} - returns true if the user has write permissions, otherwise false
*/
async hasWritePermissions() {
const { data } = await this.github.rest.repos.getCollaboratorPermissionLevel({
owner: this.owner,
repo: this.repo,
username: this.user,
})
return data.permission === writePermission || data.permission === adminPermission
}
}

module.exports = {
diffHelper: (input) => new diffHelper(input),
semgrepHelper: (input) => new semgrepHelper(input),
coverageHelper: (input) => new coverageHelper(input),
userHelper: (input) => new userHelper(input),
}
2 changes: 1 addition & 1 deletion .github/workflows/issue_prioritization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@36464acb844fc53b9b8b2401da68844f6b05ebb0
uses: tibdex/github-app-token@v2.1.0
with:
app_id: ${{ secrets.PBS_PROJECT_APP_ID }}
private_key: ${{ secrets.PBS_PROJECT_APP_PEM }}
Expand Down
43 changes: 31 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ on:
releaseType:
type: choice
options:
- major
- minor
- patch
default: minor
required: true
description: 'minor: v0.X.0, patch: v0.0.X'
description: 'major: vX.0.0, minor: v0.X.0, patch: v0.0.X'
debug:
type: boolean
default: true
Expand All @@ -24,13 +25,25 @@ jobs:
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.repository }}
ref: master
- name: Check user permission
uses: actions-cool/check-user-permission@v2.2.0
uses: actions/github-script@v7
id: check
with:
require: 'write'
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const utils = require('./.github/workflows/helpers/pull-request-utils.js')
const helper = utils.userHelper({github, context, user: '${{ github.actor }}'})
const hasPermission = await helper.hasWritePermissions()
return hasPermission
outputs:
hasWritePermission: ${{ steps.check.outputs.require-result }}
hasWritePermission: ${{ steps.check.outputs.result }}

build-master:
name: Build master
Expand All @@ -39,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.repository }}
Expand All @@ -51,13 +64,12 @@ jobs:
publish-tag:
name: Publish tag
needs: build-master
if: contains(needs.check-permission.outputs.hasWritePermission, 'true')
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Prebid Server
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create & publish tag
Expand All @@ -78,11 +90,18 @@ jobs:
nextTag=''
releaseType=${{ inputs.releaseType }}
if [ $releaseType == "minor" ]; then
# increment minor version and reset patch version
nextTag=$(echo "${currentTag}" | awk -F. '{OFS="."; $2+=1; $3=0; print $0}')
if [ $releaseType == "major" ]; then
# PBS-GO skipped the v1.0.0 major release - https://github.com/prebid/prebid-server/issues/3068
# If the current tag is v0.x.x, the script sets the next release tag to v2.0.0
# Otherwise, the script increments the major version by 1 and sets the minor and patch versions to zero
# For example, v2.x.x will be incremented to v3.0.0
major=$(echo "${currentTag}" | awk -F. '{gsub(/^v/, "", $1); if($1 == 0) $1=2; else $1+=1; print $1}')
nextTag="v${major}.0.0"
elif [ $releaseType == "minor" ]; then
# Increment minor version and reset patch version
nextTag=$(echo "${currentTag}" | awk -F. '{OFS="."; $2+=1; $3=0; print $0}')
else
# increment patch version
# Increment patch version
nextTag=$(echo "${currentTag}" | awk -F. '{OFS="."; $3+=1; print $0}')
fi
Expand All @@ -103,7 +122,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Prebid Server
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build image
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Resolves to empty string for push events and falls back to HEAD.
ref: ${{ github.event.pull_request.head.sha }}
Expand All @@ -29,6 +29,6 @@ jobs:
severity: 'CRITICAL,HIGH'

- name: Upload Results To GitHub Security Tab
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
6 changes: 3 additions & 3 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
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: Calculate diff
id: calculate_diff
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
result-encoding: string
script: |
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Add pull request comment
id: add_pull_request_comment
if: contains(steps.should_run_semgrep.outputs.hasChanges, 'true')
uses: actions/github-script@v6.4.1
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:

steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: 1.20.5

- name: Checkout Merged Branch
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Validate
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:

steps:
- name: Install Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Resolves to empty string for push events and falls back to HEAD.
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ vendor

# build artifacts
prebid-server
build
debug
/build
/debug
__debug_bin

# config files
Expand All @@ -41,6 +41,7 @@ inventory_url.yaml
# generated log files during tests
analytics/config/testFiles/
analytics/config/xyz*
analytics/build/xyz*
analytics/filesystem/testFiles/

# autogenerated version file
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN go mod tidy
RUN go mod vendor
ARG TEST="true"
RUN if [ "$TEST" != "false" ]; then ./validate.sh ; fi
RUN go build -mod=vendor -ldflags "-X github.com/prebid/prebid-server/version.Ver=`git describe --tags | sed 's/^v//'` -X github.com/prebid/prebid-server/version.Rev=`git rev-parse HEAD`" .
RUN go build -mod=vendor -ldflags "-X github.com/prebid/prebid-server/v2/version.Ver=`git describe --tags | sed 's/^v//'` -X github.com/prebid/prebid-server/v2/version.Rev=`git rev-parse HEAD`" .

FROM ubuntu:20.04 AS release
LABEL maintainer="hans.hjort@xandr.com"
Expand Down
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test: deps
ifeq "$(adapter)" ""
./validate.sh
else
go test github.com/prebid/prebid-server/adapters/$(adapter) -bench=.
go test github.com/prebid/prebid-server/v2/adapters/$(adapter) -bench=.
endif

# build-modules generates modules/builder.go file which provides a list of all available modules
Expand All @@ -33,6 +33,10 @@ image:
# format runs format
format:
./scripts/format.sh -f true

# formatcheck runs format for diagnostics, without modifying the code
formatcheck:
./scripts/format.sh -f false

mockgen: mockgeninstall mockgendb mockgencache mockgenmetrics

Expand All @@ -43,20 +47,20 @@ mockgeninstall:
mockgendb:
mkdir -p modules/pubmatic/openwrap/database/mock modules/pubmatic/openwrap/database/mock_driver
mockgen database/sql/driver Driver,Connector,Conn,DriverContext > modules/pubmatic/openwrap/database/mock_driver/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/modules/pubmatic/openwrap/database Database > modules/pubmatic/openwrap/database/mock/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/database Database > modules/pubmatic/openwrap/database/mock/mock.go

mockgencache:
mkdir -p modules/pubmatic/openwrap/cache/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/modules/pubmatic/openwrap/cache Cache > modules/pubmatic/openwrap/cache/mock/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/cache Cache > modules/pubmatic/openwrap/cache/mock/mock.go

mockgenmetrics:
mkdir -p modules/pubmatic/openwrap/metrics/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/modules/pubmatic/openwrap/metrics MetricsEngine > modules/pubmatic/openwrap/metrics/mock/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/metrics MetricsEngine > modules/pubmatic/openwrap/metrics/mock/mock.go

mockgenlogger:
mkdir -p analytics/pubmatic/mhttp/mock
mockgen github.com/PubMatic-OpenWrap/prebid-server/analytics/pubmatic/mhttp HttpCallInterface,MultiHttpContextInterface > analytics/pubmatic/mhttp/mock/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/analytics/pubmatic/mhttp HttpCallInterface,MultiHttpContextInterface > analytics/pubmatic/mhttp/mock/mock.go

mockgenpublisherfeature:
mkdir -p modules/pubmatic/openwrap/publisherfeature
mockgen github.com/PubMatic-OpenWrap/prebid-server/modules/pubmatic/openwrap/publisherfeature Feature > modules/pubmatic/openwrap/publisherfeature/mock/mock.go
mockgen github.com/PubMatic-OpenWrap/prebid-server/v2/modules/pubmatic/openwrap/publisherfeature Feature > modules/pubmatic/openwrap/publisherfeature/mock/mock.go
Loading

0 comments on commit f9b88f3

Please sign in to comment.