Skip to content

chore: remove unused test shell script #8

chore: remove unused test shell script

chore: remove unused test shell script #8

Workflow file for this run

name: Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
any_changed: ${{ steps.set-matrix.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
git diff --name-only origin/${{ github.base_ref }}..HEAD >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
git diff --name-only HEAD~1..HEAD >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Set matrix for changed parsers
id: set-matrix
run: |
# List of all available parsers
ALL_PARSERS="redshift"
# Add more parsers here as they are added to the repository
# ALL_PARSERS="redshift mysql postgresql"
CHANGED_FILES="${{ steps.changed-files.outputs.changed_files }}"
CHANGED_PARSERS=""
for parser in $ALL_PARSERS; do
if echo "$CHANGED_FILES" | grep -q "^$parser/"; then
if [ -z "$CHANGED_PARSERS" ]; then
CHANGED_PARSERS="\"$parser\""
else
CHANGED_PARSERS="$CHANGED_PARSERS,\"$parser\""
fi
fi
done
if [ -n "$CHANGED_PARSERS" ]; then
echo "matrix={\"parser\":[$CHANGED_PARSERS]}" >> $GITHUB_OUTPUT
echo "any_changed=true" >> $GITHUB_OUTPUT
echo "Changed parsers: $CHANGED_PARSERS"
else
echo "matrix={\"parser\":[]}" >> $GITHUB_OUTPUT
echo "any_changed=false" >> $GITHUB_OUTPUT
echo "No parser changes detected"
fi
go-mod-tidy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Verify go mod tidy
run: |
go mod tidy
git diff --exit-code -- go.mod go.sum
go-tests:
needs: detect-changes
if: needs.detect-changes.outputs.any_changed == 'true'
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJSON(needs.detect-changes.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Run all tests
working-directory: ${{ matrix.parser }}
run: go test -p=8 -timeout 30m -ldflags "-w -s" -v ./... | tee test.log; exit ${PIPESTATUS[0]}
- name: Pretty print tests running time
working-directory: ${{ matrix.parser }}
# grep: filter out lines like "--- PASS: Test (15.04s)"
# sed: remove unnecessary characters
# awk: re-format lines to "PASS: Test (15.04s)"
# sort: cut into columns by delimiter ' ' (single space) and sort by column 3 (test time in seconds) as numeric type in reverse order (largest comes first)
# awk: accumulate sum by test time in seconds
run: grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}'