Skip to content

Commit

Permalink
Update CI (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Jan 20, 2025
1 parent f54ba6b commit b59113f
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 107 deletions.
91 changes: 33 additions & 58 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,27 @@ on:
description: 'New Ref'
required: true

# Cancel the workflow in progress in newer build is about to start.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

env:
GO111MODULE: "on"
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
GO_VERSION: 1.22.x
jobs:
bench:
strategy:
matrix:
go-version: [ stable ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: env.GO_VERSION != 'tip'
uses: actions/setup-go@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Go tip
if: env.GO_VERSION == 'tip'
run: |
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
ls -lah gotip.tar.gz
mkdir -p ~/sdk/gotip
tar -C ~/sdk/gotip -xzf gotip.tar.gz
~/sdk/gotip/bin/go version
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}

- name: Go cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
# In order:
# * Module download cache
Expand All @@ -59,58 +43,49 @@ jobs:
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-cache
- name: Restore benchstat
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/go/bin/benchstat
key: ${{ runner.os }}-benchstat-legacy

key: ${{ runner.os }}-benchstat
- name: Restore base benchmark result
id: base-benchmark
if: env.CACHE_BENCHMARK == 'on'
uses: actions/cache@v3
id: benchmark-base
uses: actions/cache@v4
with:
path: |
bench-master.txt
bench-main.txt
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}

- name: Run benchmark
run: |
export REF_NAME=new
make bench
OUTPUT=$(make bench-stat-diff)
echo "${OUTPUT}"
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
OUTPUT=$(make bench-stat)
echo "${OUTPUT}"
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Run benchmark for base code
if: env.RUN_BASE_BENCHMARK == 'on' && steps.base-benchmark.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
- name: Checkout base code
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
uses: actions/checkout@v4
with:
ref: ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
path: __base
- name: Run base benchmark
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
run: |
git fetch origin master ${{ github.event.pull_request.base.sha }}
HEAD=$(git rev-parse HEAD)
git reset --hard ${{ github.event.pull_request.base.sha }}
export REF_NAME=master
make bench-run bench-stat
git reset --hard $HEAD
- name: Benchmark stats
cd __base
make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
- name: Benchmark
id: bench
run: |
export REF_NAME=new
BENCH_COUNT=5 make bench
OUTPUT=$(make bench-stat-diff)
echo "${OUTPUT}"
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "::set-output name=diff::$OUTPUT"
OUTPUT=$(make bench-stat)
echo "${OUTPUT}"
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Comment benchmark result
continue-on-error: true
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "::set-output name=result::$OUTPUT"
- name: Comment Benchmark Result
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: pr
- name: Checkout base code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v5
with:
go-version: 1.22.x
- uses: actions/checkout@v2
go-version: stable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.0.1
uses: golangci/golangci-lint-action@v6.2.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.59.1
version: v1.63.4

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
20 changes: 5 additions & 15 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,19 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.22.x
GO_VERSION: stable
jobs:
gorelease:
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: env.GO_VERSION != 'tip'
uses: actions/setup-go@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Go tip
if: env.GO_VERSION == 'tip'
run: |
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
ls -lah gotip.tar.gz
mkdir -p ~/sdk/gotip
tar -C ~/sdk/gotip -xzf gotip.tar.gz
~/sdk/gotip/bin/go version
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Gorelease cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/go/bin/gorelease
Expand Down
29 changes: 9 additions & 20 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,25 @@ concurrency:
env:
GO111MODULE: "on"
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
COV_GO_VERSION: 1.22.x # Version of Go to collect coverage
COV_GO_VERSION: stable # Version of Go to collect coverage
TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents
jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.21.x, 1.22.x ]
go-version: [ 1.13.x, stable, oldstable ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: matrix.go-version != 'tip'
uses: actions/setup-go@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Install Go tip
if: matrix.go-version == 'tip'
run: |
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
ls -lah gotip.tar.gz
mkdir -p ~/sdk/gotip
tar -C ~/sdk/gotip -xzf gotip.tar.gz
~/sdk/gotip/bin/go version
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Go cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
# In order:
# * Module download cache
Expand All @@ -59,7 +48,7 @@ jobs:
- name: Restore base test coverage
id: base-coverage
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
unit-base.txt
Expand Down Expand Up @@ -130,7 +119,7 @@ jobs:

- name: Upload code coverage
if: matrix.go-version == env.COV_GO_VERSION
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v5
with:
file: ./unit.coverprofile
files: ./unit.coverprofile
flags: unittests
9 changes: 6 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters-settings:
linters:
enable-all: true
disable:
- fatcontext
- err113
- maintidx
- musttag
Expand All @@ -31,7 +32,6 @@ linters:
- cyclop
- lll
- gochecknoglobals
- gomnd
- wrapcheck
- paralleltest
- forbidigo
Expand All @@ -46,9 +46,9 @@ linters:
- dupword
- depguard
- tagalign
- execinquery
- mnd
- testifylint
- recvcheck

issues:
exclude:
Expand All @@ -59,12 +59,12 @@ issues:
exclude-use-default: false
exclude-rules:
- linters:
- gomnd
- mnd
- goconst
- noctx
- funlen
- dupl
- structcheck
- unused
- unparam
- nosnakecase
Expand All @@ -74,4 +74,7 @@ issues:
- errchkjson
- gosec
path: "example_"
- linters:
- revive
text: "unused-parameter: parameter"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.59.1" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.63.4" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/swaggest/jsonschema-go
go 1.18

require (
github.com/bool64/dev v0.2.35
github.com/bool64/dev v0.2.38
github.com/stretchr/testify v1.8.2
github.com/swaggest/assertjson v1.9.0
github.com/swaggest/refl v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bool64/dev v0.2.35 h1:M17TLsO/pV2J7PYI/gpe3Ua26ETkzZGb+dC06eoMqlk=
github.com/bool64/dev v0.2.35/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.38 h1:C5H9wkx/BhTYRfV14X90iIQKpSuhzsG+OHQvWdQ5YQ4=
github.com/bool64/dev v0.2.38/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit b59113f

Please sign in to comment.