Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Add benchmarks' enhancements #259

Merged
merged 11 commits into from
Nov 3, 2024
95 changes: 55 additions & 40 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
name: benchmarks

on: workflow_dispatch
on:
workflow_dispatch:
inputs:
workflow-run-id:
description: 'Run ID (optional) [default: latest release]'
type: number

permissions:
actions: read

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_RUN_ID: ${{ inputs.workflow-run-id }}
BENCHMARKS_DIR: .benchmarks

jobs:
amd64-macos-gcc:
runs-on: [macos-13]
runs-on: macos-13

steps:
- name: Checkout
Expand All @@ -13,42 +26,34 @@ jobs:
sparse-checkout: |
scripts/ci-run-benchmarks.sh

- name: Cache
uses: actions/cache@v4
with:
key: benchmarks-${{ runner.os }}-amd64-macos-gcc
path: |
**/*.csv
**/*.tar.gz
- name: Download build artifact from workflow run
if: ${{ env.WORKFLOW_RUN_ID }}
run: |
gh run download --repo liquidaty/zsv --pattern *amd64-macosx-gcc.tar.gz "$WORKFLOW_RUN_ID"
mkdir -p ./"$BENCHMARKS_DIR"
mv zsv-*.tar.gz/*.tar.gz ./"$BENCHMARKS_DIR"
rm -rf zsv-*.tar.gz
ls -hl ./"$BENCHMARKS_DIR"

- name: Set ZSV_TAG env var
if: ${{ env.WORKFLOW_RUN_ID }}
run: |
cd ./"$BENCHMARKS_DIR"
ZSV_TAG="$(ls *.tar.gz | sed 's|zsv-\(.*\)-amd64.*|\1|')"
echo "ZSV_TAG=$ZSV_TAG" | tee -a "$GITHUB_ENV"

- name: Run benchmarks
run: ./scripts/ci-run-benchmarks.sh

amd64-linux-gcc:
runs-on: [ubuntu-latest]
amd64-linux:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
scripts/ci-run-benchmarks.sh
strategy:
matrix:
compiler: [gcc, clang, musl]
continue-on-error: true

- name: Cache
uses: actions/cache@v4
with:
key: benchmarks-${{ runner.os }}-amd64-linux-gcc
path: |
**/*.csv
**/*.tar.gz

- name: Run benchmarks
env:
ZSV_LINUX_BUILD_COMPILER: gcc
run: ./scripts/ci-run-benchmarks.sh

amd64-linux-clang:
runs-on: [ubuntu-latest]
name: amd64-linux-${{ matrix.compiler }}

steps:
- name: Checkout
Expand All @@ -57,15 +62,25 @@ jobs:
sparse-checkout: |
scripts/ci-run-benchmarks.sh

- name: Cache
uses: actions/cache@v4
with:
key: benchmarks-${{ runner.os }}-amd64-linux-clang
path: |
**/*.csv
**/*.tar.gz
- name: Download build artifact from workflow run
if: ${{ env.WORKFLOW_RUN_ID }}
env:
COMPILER: ${{ matrix.compiler }}
run: |
gh run download --repo liquidaty/zsv --pattern *amd64-linux-$COMPILER.tar.gz "$WORKFLOW_RUN_ID"
mkdir -p ./"$BENCHMARKS_DIR"
mv zsv-*.tar.gz/*.tar.gz ./"$BENCHMARKS_DIR"
rm -rf zsv-*.tar.gz
ls -hl ./"$BENCHMARKS_DIR"

- name: Set ZSV_TAG env var
if: ${{ env.WORKFLOW_RUN_ID }}
run: |
cd ./"$BENCHMARKS_DIR"
ZSV_TAG="$(ls *.tar.gz | sed 's|zsv-\(.*\)-amd64.*|\1|')"
echo "ZSV_TAG=$ZSV_TAG" | tee -a "$GITHUB_ENV"

- name: Run benchmarks
env:
ZSV_LINUX_BUILD_COMPILER: clang
ZSV_LINUX_BUILD_COMPILER: ${{ matrix.compiler }}
run: ./scripts/ci-run-benchmarks.sh
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ name: ci
on:
push:
branches: [main]
paths-ignore: ['**.md', 'setup-action/**']
paths-ignore:
- '**.md'
- 'setup-action/**'
- '.github/workflows/codeql.yml'
- '.github/workflows/benchmarks.yml'
- 'scripts/ci-run-benchmarks.sh'
pull_request:
branches: [main]
paths-ignore: ['**.md', 'setup-action/**']
paths-ignore:
- '**.md'
- 'setup-action/**'
- '.github/workflows/codeql.yml'
- '.github/workflows/benchmarks.yml'
- 'scripts/ci-run-benchmarks.sh'
release:
types: [published]

Expand Down
56 changes: 33 additions & 23 deletions scripts/ci-run-benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUNS=${RUNS:-6}
SKIP_FIRST_RUN=${SKIP_FIRST_RUN:-true}
BENCHMARKS_DIR=${BENCHMARKS_DIR:-".benchmarks"}
ZSV_LINUX_BUILD_COMPILER=${ZSV_LINUX_BUILD_COMPILER:-gcc}
ZSV_TAG=${ZSV_TAG:-}

if [ "$OS" = "" ]; then
if [ "$CI" = true ]; then
Expand All @@ -19,27 +20,40 @@ if [ "$OS" = "" ]; then
OS=$(echo "$OS" | tr '[:upper:]' '[:lower:]')
fi

echo "[INF] OS : $OS"
echo "[INF] RUNS : $RUNS"
echo "[INF] SKIP_FIRST_RUN : $SKIP_FIRST_RUN"
echo "[INF] BENCHMARKS_DIR : $BENCHMARKS_DIR"
echo "[INF] OS: $OS"
echo "[INF] RUNS: $RUNS"
echo "[INF] SKIP_FIRST_RUN: $SKIP_FIRST_RUN"
echo "[INF] BENCHMARKS_DIR: $BENCHMARKS_DIR"

if [ "$RUNS" -lt 2 ]; then
echo "[ERR] RUNS must be greater than 2!"
exit 1
fi

if [ "$ZSV_TAG" = "" ]; then
ZSV_TAG=$(git ls-remote --tags --refs https://github.com/liquidaty/zsv | tail -n1 | cut -d '/' -f3)
fi

ZSV_TAG="$(echo "$ZSV_TAG" | sed 's/^v//')"
echo "[INF] ZSV_TAG: $ZSV_TAG"

ZSV_BUILD_FROM="[RELESAE (v$ZSV_TAG)](https://github.com/liquidaty/zsv/releases/tag/v$ZSV_TAG)"
if [ "$CI" = true ] && [ "$WORKFLOW_RUN_ID" != "" ]; then
ZSV_BUILD_FROM="[WORKFLOW ($WORKFLOW_RUN_ID)](https://github.com/liquidaty/zsv/actions/runs/$WORKFLOW_RUN_ID)"
echo "[INF] WORKFLOW_RUN_ID: $WORKFLOW_RUN_ID"
fi

if [ "$OS" = "linux" ]; then
echo "[INF] ZSV_LINUX_BUILD_COMPILER : $ZSV_LINUX_BUILD_COMPILER"
echo "[INF] ZSV_LINUX_BUILD_COMPILER: $ZSV_LINUX_BUILD_COMPILER"
if [ "$ZSV_LINUX_BUILD_COMPILER" != "gcc" ] && [ "$ZSV_LINUX_BUILD_COMPILER" != "clang" ] && [ "$ZSV_LINUX_BUILD_COMPILER" != "musl" ]; then
echo "[INF] Unknown ZSV_LINUX_BUILD_COMPILER value! [$ZSV_LINUX_BUILD_COMPILER]"
echo "[INF] Unknown value for ZSV_LINUX_BUILD_COMPILER! [$ZSV_LINUX_BUILD_COMPILER]"
exit 1
fi
ZSV_TAR_URL="https://github.com/liquidaty/zsv/releases/download/v0.3.9-alpha/zsv-0.3.9-alpha-amd64-linux-$ZSV_LINUX_BUILD_COMPILER.tar.gz"
ZSV_TAR_URL="https://github.com/liquidaty/zsv/releases/download/v$ZSV_TAG/zsv-$ZSV_TAG-amd64-linux-$ZSV_LINUX_BUILD_COMPILER.tar.gz"
TSV_TAR_URL="https://github.com/eBay/tsv-utils/releases/download/v2.2.0/tsv-utils-v2.2.0_linux-x86_64_ldc2.tar.gz"
XSV_TAR_URL="https://github.com/BurntSushi/xsv/releases/download/0.13.0/xsv-0.13.0-x86_64-unknown-linux-musl.tar.gz"
elif [ "$OS" = "macos" ] || [ "$OS" = "darwin" ]; then
ZSV_TAR_URL="https://github.com/liquidaty/zsv/releases/download/v0.3.9-alpha/zsv-0.3.9-alpha-amd64-macosx-gcc.tar.gz"
ZSV_TAR_URL="https://github.com/liquidaty/zsv/releases/download/v$ZSV_TAG/zsv-$ZSV_TAG-amd64-macosx-gcc.tar.gz"
TSV_TAR_URL="https://github.com/eBay/tsv-utils/releases/download/v2.2.1/tsv-utils-v2.2.1_osx-x86_64_ldc2.tar.gz"
XSV_TAR_URL="https://github.com/BurntSushi/xsv/releases/download/0.13.0/xsv-0.13.0-x86_64-apple-darwin.tar.gz"
else
Expand All @@ -50,32 +64,30 @@ fi
mkdir -p "$BENCHMARKS_DIR"
cd "$BENCHMARKS_DIR"

echo "[INF] Deleting existing extracted directories..."
find ./ -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} +

CSV_URL="https://burntsushi.net/stuff/worldcitiespop_mil.csv"
CSV="$(echo "$CSV_URL" | sed 's:.*/::')"
echo "[INF] Downloading CSV file... [$CSV]"
printf "[INF] Downloading CSV file... [%s] " "$CSV"
if [ ! -f "$CSV" ]; then
wget -q "$CSV_URL"
echo "[INF] Downloaded successfully!"
echo "[DOWNLOADED]"
else
echo "[INF] Download skipped! CSV file already exists! [$CSV]"
echo "[SKIPPED]"
fi

ls -hl "$CSV"

for URL in "$ZSV_TAR_URL" "$TSV_TAR_URL" "$XSV_TAR_URL"; do
TAR="$(echo "$URL" | sed 's:.*/::')"
echo "[INF] Downloading... [$TAR]"
printf "[INF] Downloading... [%s] " "$TAR"
if [ ! -f "$TAR" ]; then
wget -q "$URL"
echo "[INF] Downloaded successfully! [$TAR]"
else
echo "[INF] Download skipped! Archive already exists! [$TAR]"
echo "[DONE]"
else
echo "[SKIPPED]"
fi
echo "[INF] Extracting... [$TAR]"
printf "[INF] Extracting... [%s] " "$TAR"
tar xf "$TAR"
echo "[DONE]"
done

TOOLS_DIR="tools"
Expand All @@ -89,11 +101,8 @@ for FILE in $FILES; do
fi
done

ls -hl "$TOOLS_DIR"

COUNT_OUTPUT_FILE="count.out"
SELECT_OUTPUT_FILE="select.out"

rm -f "$COUNT_OUTPUT_FILE" "$SELECT_OUTPUT_FILE"

echo "[INF] Running count benchmarks..."
Expand Down Expand Up @@ -152,7 +161,8 @@ TIMESTAMP="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
{
echo '# Benchmarks'
echo
echo "- Timestamp UTC: \`$TIMESTAMP\`"
echo "- Timestamp UTC: $TIMESTAMP"
echo "- zsv build from: $ZSV_BUILD_FROM"
echo
echo "## Releases Used"
echo
Expand Down