Skip to content

Commit

Permalink
Upgrade To Go 1.22 (#3686)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxNode authored Jun 7, 2024
1 parent 7702a78 commit e13d786
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 178 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/adapter-code-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
name: Adapter code coverage
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.20.5
go-version: 1.22.3

- name: Checkout pull request branch
- 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: Get adapter directories
- name: Discover Adapter Directories
id: get_directories
uses: actions/github-script@v7
with:
Expand All @@ -40,7 +43,7 @@ jobs:
// run coverage for maximum of 2 directories
return (directories.length == 0 || directories.length > 2) ? "" : JSON.stringify(directories)
- name: Run coverage tests
- name: Run Coverage Tests
id: run_coverage
if: steps.get_directories.outputs.result != ''
run: |
Expand All @@ -67,14 +70,14 @@ jobs:
cd ..
rm -f -r ./*
- name: Checkout coverage-preview branch
- name: Checkout Coverage Preview Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: coverage-preview
repository: prebid/prebid-server

- name: Commit coverage files to coverage-preview branch
- name: Upload Coverage Results
if: steps.run_coverage.outputs.coverage_dir != ''
id: commit_coverage
run: |
Expand All @@ -88,11 +91,11 @@ jobs:
git push origin coverage-preview
echo "remote_coverage_preview_dir=${directory}" >> $GITHUB_OUTPUT
- name: Checkout master branch
- name: Checkout Master Branch
if: steps.get_directories.outputs.result != ''
run: git checkout master

- name: Add coverage summary to pull request
- 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:
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
name: Adapter semgrep checks
name: Adapter Semgrep Check

on:
pull_request_target:
paths: ["adapters/*/*.go"]

permissions:
pull-requests: write

jobs:
semgrep-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
- 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: Calculate diff
- name: Calculate Code Diff
id: calculate_diff
uses: actions/github-script@v7
with:
Expand All @@ -29,7 +32,7 @@ jobs:
const helper = utils.diffHelper({github, context, fileNameFilter, event: "${{github.event.action}}", testName: "${{github.job}}"})
return await helper.buildDiff()
- name: Should run semgrep
- name: Check For Changes
id: should_run_semgrep
run: |
hasChanges=$(echo '${{ steps.calculate_diff.outputs.result }}' | jq .pullRequest.hasChanges)
Expand All @@ -41,15 +44,15 @@ jobs:
pip3 install semgrep==1.22.0
semgrep --version
- name: Run semgrep tests
- name: Run Semgrep
id: run_semgrep_tests
if: contains(steps.should_run_semgrep.outputs.hasChanges, 'true')
run: |
unqouted_string=$(echo '${{ steps.calculate_diff.outputs.result }}' | jq .pullRequest.files | tr -d '"')
outputs=$(semgrep --gitlab-sast --config=.semgrep/adapter $unqouted_string | jq '[.vulnerabilities[] | {"file": .location.file, "severity": .severity, "start": .location.start_line, "end": .location.end_line, "message": (.message | gsub("\\n"; "\n"))}]' | jq -c | jq -R)
echo "semgrep_result=${outputs}" >> "$GITHUB_OUTPUT"
- name: Add pull request comment
- name: Add Pull Request Comment
id: add_pull_request_comment
if: contains(steps.should_run_semgrep.outputs.hasChanges, 'true')
uses: actions/github-script@v7
Expand All @@ -66,7 +69,7 @@ jobs:
const { previousScan, currentScan } = await helper.addReviewComments()
return previousScan.unAddressedComments + currentScan.newComments
- name: Adapter semgrep checks result
- name: Check Results
if: contains(steps.should_run_semgrep.outputs.hasChanges, 'true')
run: |
if [ "${{steps.add_pull_request_comment.outputs.result}}" -ne "0" ]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.20.5
go-version: 1.22.3

- name: Checkout Merged Branch
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
validate:
strategy:
matrix:
go-version: [1.19.x, 1.20.x]
go-version: [1.21.x, 1.22.x]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y wget
WORKDIR /tmp
RUN wget https://dl.google.com/go/go1.20.5.linux-amd64.tar.gz && \
tar -xf go1.20.5.linux-amd64.tar.gz && \
RUN wget https://dl.google.com/go/go1.22.3.linux-amd64.tar.gz && \
tar -xf go1.22.3.linux-amd64.tar.gz && \
mv go /usr/local
RUN mkdir -p /app/prebid-server/
WORKDIR /app/prebid-server/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Ensure that you deploy the `/static` directory, as Prebid Server requires those

## Developing

Prebid Server requires [Go](https://go.dev) version 1.19 or newer. You can develop on any operating system that Go supports; however, please note that our helper scripts are written in bash.
Prebid Server requires [Go](https://go.dev) version 1.21 or newer. You can develop on any operating system that Go supports; however, please note that our helper scripts are written in bash.

1. Clone The Repository
``` bash
Expand Down
4 changes: 2 additions & 2 deletions adapters/appnexus/appnexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"net/http"
"net/url"
"strconv"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/prebid/openrtb/v20/adcom1"
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/util/maputil"
"github.com/prebid/prebid-server/v2/util/ptrutil"
"github.com/prebid/prebid-server/v2/util/randomutil"

Expand Down Expand Up @@ -315,7 +315,7 @@ func splitRequests(imps []openrtb2.Imp, request *openrtb2.BidRequest, requestExt
errs = append(errs, err)
}

requestExtClone := maputil.Clone(requestExt)
requestExtClone := maps.Clone(requestExt)
requestExtClone["appnexus"] = appnexusExtJson

request.Ext, err = json.Marshal(requestExtClone)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/prebid/prebid-server/v2

go 1.20
go 1.21

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
Expand Down
9 changes: 5 additions & 4 deletions openrtb_ext/floors.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package openrtb_ext

import (
"github.com/prebid/prebid-server/v2/util/maputil"
"maps"
"slices"

"github.com/prebid/prebid-server/v2/util/ptrutil"
"github.com/prebid/prebid-server/v2/util/sliceutil"
)

// Defines strings for FetchStatus
Expand Down Expand Up @@ -182,10 +183,10 @@ func (data *PriceFloorData) DeepCopy() *PriceFloorData {
eachGroup.ModelWeight = ptrutil.Clone(data.ModelGroups[i].ModelWeight)
eachGroup.ModelVersion = data.ModelGroups[i].ModelVersion
eachGroup.SkipRate = data.ModelGroups[i].SkipRate
eachGroup.Values = maputil.Clone(data.ModelGroups[i].Values)
eachGroup.Values = maps.Clone(data.ModelGroups[i].Values)
eachGroup.Default = data.ModelGroups[i].Default
eachGroup.Schema = PriceFloorSchema{
Fields: sliceutil.Clone(data.ModelGroups[i].Schema.Fields),
Fields: slices.Clone(data.ModelGroups[i].Schema.Fields),
Delimiter: data.ModelGroups[i].Schema.Delimiter,
}
newModelGroups[i] = eachGroup
Expand Down
6 changes: 2 additions & 4 deletions openrtb_ext/regs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package openrtb_ext

import (
"github.com/prebid/prebid-server/v2/util/sliceutil"
)
import "slices"

// ExtRegs defines the contract for bidrequest.regs.ext
type ExtRegs struct {
Expand Down Expand Up @@ -48,7 +46,7 @@ func (erd *ExtRegsDSA) Clone() *ExtRegsDSA {
clonedTransparency := make([]ExtBidDSATransparency, len(erd.Transparency))
for i, transparency := range erd.Transparency {
newTransparency := transparency
newTransparency.Params = sliceutil.Clone(transparency.Params)
newTransparency.Params = slices.Clone(transparency.Params)
clonedTransparency[i] = newTransparency
}
clone.Transparency = clonedTransparency
Expand Down
38 changes: 19 additions & 19 deletions openrtb_ext/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package openrtb_ext
import (
"encoding/json"
"fmt"
"maps"
"slices"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/util/jsonutil"
"github.com/prebid/prebid-server/v2/util/maputil"
"github.com/prebid/prebid-server/v2/util/ptrutil"
"github.com/prebid/prebid-server/v2/util/sliceutil"
)

// FirstPartyDataExtKey defines a field name within request.ext and request.imp.ext reserved for first party data.
Expand Down Expand Up @@ -381,14 +381,14 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
}

clone := *erp
clone.Aliases = maputil.Clone(erp.Aliases)
clone.AliasGVLIDs = maputil.Clone(erp.AliasGVLIDs)
clone.BidAdjustmentFactors = maputil.Clone(erp.BidAdjustmentFactors)
clone.Aliases = maps.Clone(erp.Aliases)
clone.AliasGVLIDs = maps.Clone(erp.AliasGVLIDs)
clone.BidAdjustmentFactors = maps.Clone(erp.BidAdjustmentFactors)

if erp.BidderConfigs != nil {
clone.BidderConfigs = make([]BidderConfig, len(erp.BidderConfigs))
for i, bc := range erp.BidderConfigs {
clonedBidderConfig := BidderConfig{Bidders: sliceutil.Clone(bc.Bidders)}
clonedBidderConfig := BidderConfig{Bidders: slices.Clone(bc.Bidders)}
if bc.Config != nil {
config := &Config{ORTB2: ptrutil.Clone(bc.Config.ORTB2)}
clonedBidderConfig.Config = config
Expand Down Expand Up @@ -417,7 +417,7 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
if erp.CurrencyConversions != nil {
newConvRates := make(map[string]map[string]float64, len(erp.CurrencyConversions.ConversionRates))
for key, val := range erp.CurrencyConversions.ConversionRates {
newConvRates[key] = maputil.Clone(val)
newConvRates[key] = maps.Clone(val)
}
clone.CurrencyConversions = &ExtRequestCurrency{ConversionRates: newConvRates}
if erp.CurrencyConversions.UsePBSRates != nil {
Expand All @@ -426,13 +426,13 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
}

if erp.Data != nil {
clone.Data = &ExtRequestPrebidData{Bidders: sliceutil.Clone(erp.Data.Bidders)}
clone.Data = &ExtRequestPrebidData{Bidders: slices.Clone(erp.Data.Bidders)}
if erp.Data.EidPermissions != nil {
newEidPermissions := make([]ExtRequestPrebidDataEidPermission, len(erp.Data.EidPermissions))
for i, eidp := range erp.Data.EidPermissions {
newEidPermissions[i] = ExtRequestPrebidDataEidPermission{
Source: eidp.Source,
Bidders: sliceutil.Clone(eidp.Bidders),
Bidders: slices.Clone(eidp.Bidders),
}
}
clone.Data.EidPermissions = newEidPermissions
Expand All @@ -451,7 +451,7 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
for i, mulBid := range erp.MultiBid {
newMulBid := &ExtMultiBid{
Bidder: mulBid.Bidder,
Bidders: sliceutil.Clone(mulBid.Bidders),
Bidders: slices.Clone(mulBid.Bidders),
TargetBidderCodePrefix: mulBid.TargetBidderCodePrefix,
}
if mulBid.MaxBids != nil {
Expand All @@ -465,7 +465,7 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
clone.SChains = make([]*ExtRequestPrebidSChain, len(erp.SChains))
for i, schain := range erp.SChains {
newChain := *schain
newNodes := sliceutil.Clone(schain.SChain.Nodes)
newNodes := slices.Clone(schain.SChain.Nodes)
for j, node := range newNodes {
if node.HP != nil {
newNodes[j].HP = ptrutil.ToPtr(*newNodes[j].HP)
Expand All @@ -483,13 +483,13 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
if erp.Targeting != nil {
newTargeting := &ExtRequestTargeting{
IncludeFormat: erp.Targeting.IncludeFormat,
DurationRangeSec: sliceutil.Clone(erp.Targeting.DurationRangeSec),
DurationRangeSec: slices.Clone(erp.Targeting.DurationRangeSec),
PreferDeals: erp.Targeting.PreferDeals,
AppendBidderNames: erp.Targeting.AppendBidderNames,
}
if erp.Targeting.PriceGranularity != nil {
newPriceGranularity := &PriceGranularity{
Ranges: sliceutil.Clone(erp.Targeting.PriceGranularity.Ranges),
Ranges: slices.Clone(erp.Targeting.PriceGranularity.Ranges),
}
newPriceGranularity.Precision = ptrutil.Clone(erp.Targeting.PriceGranularity.Precision)
newTargeting.PriceGranularity = newPriceGranularity
Expand All @@ -504,7 +504,7 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
clone.Targeting = newTargeting
}

clone.NoSale = sliceutil.Clone(erp.NoSale)
clone.NoSale = slices.Clone(erp.NoSale)

if erp.AlternateBidderCodes != nil {
newAlternateBidderCodes := ExtAlternateBidderCodes{Enabled: erp.AlternateBidderCodes.Enabled}
Expand All @@ -513,7 +513,7 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
for key, val := range erp.AlternateBidderCodes.Bidders {
newBidders[key] = ExtAdapterAlternateBidderCodes{
Enabled: val.Enabled,
AllowedBidderCodes: sliceutil.Clone(val.AllowedBidderCodes),
AllowedBidderCodes: slices.Clone(val.AllowedBidderCodes),
}
}
newAlternateBidderCodes.Bidders = newBidders
Expand All @@ -531,8 +531,8 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
for i, pfmg := range erp.Floors.Data.ModelGroups {
clonedData.ModelGroups[i] = pfmg
clonedData.ModelGroups[i].ModelWeight = ptrutil.Clone(pfmg.ModelWeight)
clonedData.ModelGroups[i].Schema.Fields = sliceutil.Clone(pfmg.Schema.Fields)
clonedData.ModelGroups[i].Values = maputil.Clone(pfmg.Values)
clonedData.ModelGroups[i].Schema.Fields = slices.Clone(pfmg.Schema.Fields)
clonedData.ModelGroups[i].Values = maps.Clone(pfmg.Values)
}
}
clonedFloors.Data = &clonedData
Expand All @@ -554,12 +554,12 @@ func (erp *ExtRequestPrebid) Clone() *ExtRequestPrebid {
clone.MultiBidMap = make(map[string]ExtMultiBid, len(erp.MultiBidMap))
for k, v := range erp.MultiBidMap {
// Make v a deep copy of the ExtMultiBid struct
v.Bidders = sliceutil.Clone(v.Bidders)
v.Bidders = slices.Clone(v.Bidders)
v.MaxBids = ptrutil.Clone(v.MaxBids)
clone.MultiBidMap[k] = v
}
}
clone.AdServerTargeting = sliceutil.Clone(erp.AdServerTargeting)
clone.AdServerTargeting = slices.Clone(erp.AdServerTargeting)

return &clone
}
Loading

0 comments on commit e13d786

Please sign in to comment.