feat: introduce redshift parser into mono #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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=$(git diff --name-only origin/${{ github.base_ref }}..HEAD | xargs)" >> $GITHUB_OUTPUT | |
| echo "Debug: Changed files in PR: $(git diff --name-only origin/${{ github.base_ref }}..HEAD | xargs)" | |
| else | |
| echo "changed_files=$(git diff --name-only HEAD~1..HEAD | xargs)" >> $GITHUB_OUTPUT | |
| echo "Debug: Changed files in push: $(git diff --name-only HEAD~1..HEAD | xargs)" | |
| 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 }}" | |
| echo "Debug: Changed files: $CHANGED_FILES" | |
| CHANGED_PARSERS="" | |
| for parser in $ALL_PARSERS; do | |
| echo "Checking changes for parser: $parser" | |
| if echo "$CHANGED_FILES" | grep -q "^$parser/"; then | |
| echo "True - $parser has changes." | |
| 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: Build parser | |
| working-directory: ${{ matrix.parser }} | |
| run: | | |
| # Generate parser code from ANTLR grammar if build script exists | |
| if [ -f "build.sh" ]; then | |
| chmod +x build.sh | |
| ./build.sh | |
| elif [ -f "Makefile" ] && grep -q "^build:" Makefile; then | |
| make build | |
| fi | |
| - 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"}' |