Skip to content

Commit

Permalink
Update deps, add CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop committed Oct 6, 2024
1 parent 68e5907 commit e9caabd
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 90 deletions.
68 changes: 43 additions & 25 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,26 @@ 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.17.x
GO_VERSION: 1.23.x
jobs:
bench:
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: env.GO_VERSION != 'tip'
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Go tip
if: env.GO_VERSION == 'tip'
run: |
Expand All @@ -35,12 +41,14 @@ jobs:
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@v2
uses: actions/checkout@v3
with:
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}

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

- name: Restore base benchmark result
id: base-benchmark
if: env.CACHE_BENCHMARK == 'on'
id: benchmark-base
uses: actions/cache@v2
uses: actions/cache@v3
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: 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@v2
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 != '')

- 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 != '')
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
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
make bench-run bench-stat
git reset --hard $HEAD
- name: Benchmark stats
id: bench
run: |
export REF_NAME=new
BENCH_COUNT=5 make bench
OUTPUT=$(make bench-stat-diff)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "::set-output name=diff::$OUTPUT"
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
OUTPUT=$(make bench-stat)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "::set-output name=result::$OUTPUT"
- name: Comment Benchmark Result
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Comment benchmark result
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
21 changes: 14 additions & 7 deletions .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,36 @@
name: cloc
on:
pull_request:

# 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

jobs:
cloc:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: pr
- name: Checkout base code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
- name: Count Lines Of Code
- name: Count lines of code
id: loc
run: |
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.3/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
sccdiff_hash=$(git hash-object ./sccdiff)
[ "$sccdiff_hash" == "ae8a07b687bd3dba60861584efe724351aa7ff63" ] || (echo "::error::unexpected hash for sccdiff, possible tampering: $sccdiff_hash" && exit 1)
OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "::set-output name=diff::$OUTPUT"
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Comment Code Lines
- name: Comment lines of code
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ on:
- master
- main
pull_request:

# 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

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.23.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2.5.2
uses: golangci/golangci-lint-action@v6.1.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.43.0
version: v1.61.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
23 changes: 14 additions & 9 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
name: gorelease
on:
pull_request:

# 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:
GO_VERSION: 1.17.x
GO_VERSION: 1.23.x
jobs:
gorelease:
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: env.GO_VERSION != 'tip'
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Go tip
Expand All @@ -23,22 +29,21 @@ jobs:
~/sdk/gotip/bin/go version
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Gorelease cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/go/bin/gorelease
key: ${{ runner.os }}-gorelease
key: ${{ runner.os }}-gorelease-generic
- name: Gorelease
id: gorelease
run: |
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
OUTPUT=$(gorelease || exit 0)
OUTPUT=$(gorelease 2>&1 || exit 0)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "::set-output name=report::$OUTPUT"
- name: Comment Report
echo "report<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Comment report
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# This script is provided by github.com/bool64/dev.

# This script uploads application binaries as GitHub release assets.
name: release-assets
on:
release:
types:
- created
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GO_VERSION: 1.23.x
jobs:
build:
name: Upload Release Assets
runs-on: ubuntu-latest
steps:
- name: Install Go stable
if: env.GO_VERSION != 'tip'
uses: actions/setup-go@v4
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
- name: Build artifacts
run: |
make release-assets
- name: Upload linux_amd64.tar.gz
if: hashFiles('linux_amd64.tar.gz') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./linux_amd64.tar.gz
asset_name: linux_amd64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload linux_amd64_dbg.tar.gz
if: hashFiles('linux_amd64_dbg.tar.gz') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./linux_amd64_dbg.tar.gz
asset_name: linux_amd64_dbg.tar.gz
asset_content_type: application/tar+gzip
- name: Upload linux_arm64.tar.gz
if: hashFiles('linux_arm64.tar.gz') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./linux_arm64.tar.gz
asset_name: linux_arm64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload linux_arm.tar.gz
if: hashFiles('linux_arm.tar.gz') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./linux_arm.tar.gz
asset_name: linux_arm.tar.gz
asset_content_type: application/tar+gzip
- name: Upload darwin_amd64.tar.gz
if: hashFiles('darwin_amd64.tar.gz') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./darwin_amd64.tar.gz
asset_name: darwin_amd64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload darwin_arm64.tar.gz
if: hashFiles('darwin_arm64.tar.gz') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./darwin_arm64.tar.gz
asset_name: darwin_arm64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload windows_amd64.zip
if: hashFiles('windows_amd64.zip') != ''
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./windows_amd64.zip
asset_name: windows_amd64.zip
asset_content_type: application/zip

Loading

0 comments on commit e9caabd

Please sign in to comment.