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

Improve pipeline #358

Merged
merged 18 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 30 additions & 23 deletions .github/workflows/ghc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
permissions:
contents: write # to submit Haddock documentation to GitHub Pages

env:
syntax-dir: "eo-phi-normalizer/src/Language/EO/Phi/Syntax"

jobs:
check:
name: "Run static checks"
Expand All @@ -29,7 +32,7 @@ jobs:
version: "0.14.0.0"
pattern: |
eo-phi-normalizer/**/*.hs
!eo-phi-normalizer/src/Language/EO/Phi/Syntax/**/*.hs
!${{ env.syntax-dir }}/**/*.hs
!eo-phi-normalizer/Setup.hs

- uses: haskell-actions/hlint-setup@v2
Expand All @@ -52,8 +55,6 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-12]
fail-fast: false
env:
syntax-path: "eo-phi-normalizer/src/Language/EO/Phi/Syntax"
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
Expand All @@ -69,19 +70,19 @@ jobs:
id: restore-syntax-files
uses: actions/cache/restore@v4
with:
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-path), 'stack.yaml.lock') }}
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-dir), 'stack.yaml.lock') }}
path: |
${{ env.syntax-path }}/Lex.hs
${{ env.syntax-path }}/Par.hs
${{ env.syntax-dir }}/Lex.hs
${{ env.syntax-dir }}/Par.hs

- name: Check Syntax files exist
if: steps.restore-syntax-files.outputs.cache-hit == 'true'
shell: bash
id: check-syntax-files
run: |
if [[ -f ${{ env.syntax-path }}/Lex.hs && -f ${{ env.syntax-path }}/Par.hs ]]; then
printf "SYNTAX_FILES_EXIST=true\n" >> $GITHUB_OUTPUT
fi
source scripts/lib.sh
check_syntax_files_exist
printf "SYNTAX_FILES_EXIST=$SYNTAX_FILES_EXIST\n" >> $GITHUB_OUTPUT

- name: 🧰 Setup Stack
uses: freckle/stack-action@v5
Expand All @@ -94,10 +95,10 @@ jobs:
uses: actions/cache/save@v4
if: steps.restore-syntax-files.outputs.cache-hit != 'true'
with:
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-path), 'stack.yaml.lock') }}
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-dir), 'stack.yaml.lock') }}
path: |
${{ env.syntax-path }}/Lex.hs
${{ env.syntax-path }}/Par.hs
${{ env.syntax-dir }}/Lex.hs
${{ env.syntax-dir }}/Par.hs

pipeline:
name: Run pipeline
Expand All @@ -107,8 +108,6 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-12]
fail-fast: false
env:
syntax-path: "eo-phi-normalizer/src/Language/EO/Phi/Syntax"
permissions:
contents: write
pull-requests: write
Expand All @@ -127,19 +126,19 @@ jobs:
id: restore-syntax-files
uses: actions/cache/restore@v4
with:
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-path), 'stack.yaml.lock') }}
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-dir), 'stack.yaml.lock') }}
path: |
${{ env.syntax-path }}/Lex.hs
${{ env.syntax-path }}/Par.hs
${{ env.syntax-dir }}/Lex.hs
${{ env.syntax-dir }}/Par.hs

- name: Check Syntax files exist
if: steps.restore-syntax-files.outputs.cache-hit == 'true'
shell: bash
id: check-syntax-files
run: |
if [[ -f ${{ env.syntax-path }}/Lex.hs && -f ${{ env.syntax-path }}/Par.hs ]]; then
printf "SYNTAX_FILES_EXIST=true\n" >> $GITHUB_OUTPUT
fi
source scripts/lib.sh
check_syntax_files_exist
printf "SYNTAX_FILES_EXIST=$SYNTAX_FILES_EXIST\n" >> $GITHUB_OUTPUT

- name: 🧰 Setup Stack
uses: freckle/stack-action@v5
Expand All @@ -151,10 +150,10 @@ jobs:
uses: actions/cache/save@v4
if: steps.restore-syntax-files.outputs.cache-hit != 'true'
with:
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-path), 'stack.yaml.lock') }}
key: syntax-files-${{ runner.os }}-${{ hashFiles(format('{0}.cf', env.syntax-dir), 'stack.yaml.lock') }}
path: |
${{ env.syntax-path }}/Lex.hs
${{ env.syntax-path }}/Par.hs
${{ env.syntax-dir }}/Lex.hs
${{ env.syntax-dir }}/Par.hs

- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -200,6 +199,14 @@ jobs:
NORMALIZER_INSTALLED: "true"
run: ./scripts/pipeline.sh

- name: Check failing tests
shell: bash
if: always()
run: |
source scripts/lib.sh
get_failing_tests_non_normalized
get_failing_tests_normalized

- name: Save pipeline files
if: steps.check-pipeline-lock.outputs.PIPELINE_LOCK_CHANGED
uses: actions/cache/save@v4
Expand Down
1 change: 0 additions & 1 deletion eo-phi-normalizer/src/Language/EO/Phi/Rules/Common.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# HLINT ignore "Use &&" #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
Expand Down
16 changes: 0 additions & 16 deletions pipeline/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ sets:
- source: eo/eo-runtime/src/test/eo/org/eolang/bool-tests.eo
yaml: pipeline/yaml/bool-tests.yaml
destination: pipeline/eo/bool-tests.eo
# enable: false
- source: eo/eo-runtime/src/test/eo/org/eolang/bytes-tests.eo
yaml: pipeline/yaml/bytes-tests.yaml
destination: pipeline/eo/bytes-tests.eo
Expand Down Expand Up @@ -43,15 +42,9 @@ sets:
- source: eo/eo-runtime/src/test/eo/org/eolang/positive-infinity-tests.eo
yaml: pipeline/yaml/positive-infinity-tests.yaml
destination: pipeline/eo/positive-infinity-tests.eo
exclude:
- float-equal-to-nan-and-infinites-is-false-highload
- source: eo/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo
yaml: pipeline/yaml/runtime-tests.yaml
destination: pipeline/eo/runtime-tests.eo
exclude:
- compiles-correctly-with-long-duplicate-names
- constant-defends-against-side-effects
- takes-object-id-from-abstract-empty
- source: eo/eo-runtime/src/test/eo/org/eolang/rust-tests.eo
yaml: pipeline/yaml/rust-tests.yaml
destination: pipeline/eo/rust-tests.eo
Expand All @@ -65,15 +58,6 @@ sets:
- source: eo/eo-runtime/src/test/eo/org/eolang/switch-tests.eo
yaml: pipeline/yaml/switch-tests.yaml
destination: pipeline/eo/switch-tests.eo
exclude:
- switch-complex-case
- switch-simple-case
# fails on windows
- switch-strings-case
# fails on windows
- switch-with-all-false-cases
# fails on windows
- switch-with-several-true-cases
- source: eo/eo-runtime/src/test/eo/org/eolang/try-tests.eo
yaml: pipeline/yaml/try-tests.yaml
destination: pipeline/eo/try-tests.eo
Expand Down
2 changes: 1 addition & 1 deletion pipeline/pipeline.lock
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
EO_HEAD_HASH="0584492ff764dda0ff81a3731548dd0fc68c5196"
PIPELINE_CONFIG_HASH="f4b5a8abe34c83aabe2f4464d84baa1165752fff"
PIPELINE_CONFIG_HASH="0328290f8a4ee9c86b30eb6801d617c3adcde7bb"
81 changes: 79 additions & 2 deletions scripts/lib.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# shellcheck disable=SC2148

set -uo pipefail

PWD_DIR="$PWD"
PIPELINE_DIR_RELATIVE="pipeline"
PIPELINE_DIR="$PWD/$PIPELINE_DIR_RELATIVE"
Expand All @@ -10,6 +12,10 @@ PIPELINE_EO_NORMALIZED_DIR="$PIPELINE_DIR/eo-normalized"
PIPELINE_PHI_NORMALIZED_DIR="$PIPELINE_DIR/phi-normalized"
PIPELINE_NORMALIZER_DIR="$PWD/eo-phi-normalizer"
PIPELINE_REPORT_DIR="$PWD/report"
PIPELINE_YAML_DIR="$PIPELINE_DIR/yaml"

SCRIPTS_DIR="$PWD_DIR/scripts"
PIPELINE_SCRIPT="$SCRIPTS_DIR/pipeline.sh"

PIPELINE_CONFIG_FILE="$PIPELINE_DIR/config.yaml"

Expand All @@ -24,6 +30,22 @@ PIPELINE_LOCK_FILE_NEW_RELATIVE="$PIPELINE_DIR_RELATIVE/$PIPELINE_LOCK_FILE_NEW_

NORMALIZER_INSTALLED="${NORMALIZER_INSTALLED:-false}"

PIPELINE_LOGS_DIR="$PIPELINE_DIR/logs"
PIPELINE_LOGS_NON_NORMALIZED="$PIPELINE_LOGS_DIR/test-non-normalized-logs.txt"
PIPELINE_LOGS_NORMALIZED="$PIPELINE_LOGS_DIR/test-normalized-logs.txt"

SYNTAX_DIR="eo-phi-normalizer/src/Language/EO/Phi/Syntax"

function init_logs {
mkdir -p "$PIPELINE_LOGS_DIR"
touch "$PIPELINE_LOGS_NON_NORMALIZED"
touch "$PIPELINE_LOGS_NORMALIZED"
}

export -f init_logs

init_logs

function print_message {
printf "\n\n\n[[[%s]]]\n\n\n" "$1"
}
Expand Down Expand Up @@ -147,8 +169,10 @@ function install_normalizer {

print_message "Install the Normalizer"

if [[ "$NORMALIZER_INSTALLED" = "true" && "$IS_WINDOWS" = "true" ]]; then
mv "$INSTALLATION_PATH/normalizer.exe" "$INSTALLATION_PATH/normalizer"
if [[ "$NORMALIZER_INSTALLED" = "true" ]]; then
if [[ "$IS_WINDOWS" = "true" ]]; then
mv "$INSTALLATION_PATH/normalizer.exe" "$INSTALLATION_PATH/normalizer"
fi
else
stack install eo-phi-normalizer:exe:normalizer --ghc-options -O2
fi
Expand All @@ -157,3 +181,56 @@ function install_normalizer {
}

export -f install_normalizer

function run_pipeline {
bash "$PIPELINE_SCRIPT"
}

export -f run_pipeline

function get_failing_tests {
local logs="$1"
local stage="$2"

export logs

failed="$(
perl -ne 'print if /<<< FAILURE/' "$logs" \
| perl -pe 's/^.*EOorg.EOeolang.EO(.*)Test$/$1/p' \
| perl -pe 's/_/-/g'
)"

if [[ "$failed" = "" ]]; then
print_message "No tests failed $stage normalization"
else
print_message "Some tests failed $stage normalization"

printf "%s\n" "$failed"
fi
}

export -f get_failing_tests

function get_failing_tests_non_normalized {
get_failing_tests "$PIPELINE_LOGS_NON_NORMALIZED" "before"
}

export -f get_failing_tests_non_normalized

function get_failing_tests_normalized {
get_failing_tests "$PIPELINE_LOGS_NORMALIZED" "after"
}

export -f get_failing_tests_normalized

function check_syntax_files_exist {
SYNTAX_FILES_EXIST=false

if [[ -f "$SYNTAX_DIR/Lex.hs" && -f "$SYNTAX_DIR/Par.hs" ]]; then
SYNTAX_FILES_EXIST=true
fi

print_message "Syntax files exist: $SYNTAX_FILES_EXIST"
}

export -f check_syntax_files_exist
28 changes: 23 additions & 5 deletions scripts/pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ function check_configs {
function generate_eo_tests {
print_message "Generate EO test files"

mkdir_clean "$PIPELINE_YAML_DIR"
mkdir_clean "$PIPELINE_EO_DIR"

stack run transform-eo-tests
}

Expand Down Expand Up @@ -90,7 +93,7 @@ function convert_phi_to_eo {

print_message "Convert PHI to EO without normalization"

mkdir_clean eo-non-normalized
mkdir_clean "$PIPELINE_EO_NON_NORMALIZED_DIR"

cd "$PIPELINE_PHI_DIR"
cp -r ../eo/.eoc .
Expand All @@ -102,20 +105,35 @@ function convert_phi_to_eo {

}

function test_with_logs {
local logs="$1"

local fail=false

eo test | tee "$logs" || fail=true

if [[ "$fail" = true ]]; then
perl -i -pe 's/\x1b\[[0-9;]*[mGKHF]//g' "$logs"
perl -i -pe 's/\x0//g' "$logs"

exit 1
fi
}

function test_without_normalization {

print_message "Test EO without normalization"

cd "$PIPELINE_EO_NON_NORMALIZED_DIR"
eo test
test_with_logs "$PIPELINE_LOGS_NON_NORMALIZED"
cd "$PIPELINE_DIR"
}

function normalize {

print_message "Normalize PHI"

mkdir_clean phi-normalized
mkdir_clean "$PIPELINE_PHI_NORMALIZED_DIR"

cd "$PIPELINE_PHI_DIR"

Expand Down Expand Up @@ -180,11 +198,11 @@ function test_with_normalization {

print_message "Test EO with normalization"

mkdir_clean eo-normalized
mkdir_clean "$PIPELINE_EO_NORMALIZED_DIR"

cd "$PIPELINE_EO_NORMALIZED_DIR"
cp -r "$PIPELINE_PHI_NORMALIZED_DIR"/.eoc/print/!(org) .
eo test
test_with_logs "$PIPELINE_LOGS_NORMALIZED"
cd "$PIPELINE_DIR"
}

Expand Down
Loading