From 1d3ea85b600bd4991391aa32fefd915946530e16 Mon Sep 17 00:00:00 2001 From: graur Date: Mon, 21 Nov 2022 20:03:20 +0300 Subject: [PATCH 01/10] #35 - added github actions workflow for find division by zero errors --- .github/workflows/validate.yml | 34 ++++++++++++++++++++++++++++++++++ examples/div-by-zero.c | 3 +++ polystat.sh | 8 ++++++++ 3 files changed, 45 insertions(+) create mode 100644 .github/workflows/validate.yml create mode 100644 examples/div-by-zero.c create mode 100644 polystat.sh diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..21ca828 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,34 @@ +name: С++ division by zero validation + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Pull the Docker image + run: | + mkdir out + docker pull yegor256/c2eo:0.1.24 + - name: Run the Docker image + run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/hello.c out/global.eo + - name: Check out/global.eo + run: cat out/global.eo + - name: Run Polystat Jar + run: bash polystat.sh + - name: Check polystat-eo-out.txt + run: cat polystat-eo-out.txt + - name: Upload results + uses: actions/upload-artifact@v3 + with: + name: polystat-eo-out + path: polystat-eo-out.txt diff --git a/examples/div-by-zero.c b/examples/div-by-zero.c new file mode 100644 index 0000000..4134be4 --- /dev/null +++ b/examples/div-by-zero.c @@ -0,0 +1,3 @@ +auto test(int a, int b) -> int { + return (a / b) + ((b / a) / a); +} \ No newline at end of file diff --git a/polystat.sh b/polystat.sh new file mode 100644 index 0000000..7101acc --- /dev/null +++ b/polystat.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Run Polystat (EO) and save reports to "results" folder +curl -L -o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" +echo "Polystat (EO) analysis has started" +touch polystat-eo-out.txt +java -jar polystat.jar eo --in out --to file=polystat-eo-out.txt --sarif +echo "Polystat (EO) analysis has finished"o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" \ No newline at end of file From b783a8cee7a40b79a91ca9a335b7a49b25f95c08 Mon Sep 17 00:00:00 2001 From: graur Date: Thu, 24 Nov 2022 16:51:16 +0300 Subject: [PATCH 02/10] #35 - fixed workflow --- .github/workflows/validate.yml | 50 +++++++++++++++++++--------------- copy.sh | 7 +++++ dejump.sh | 10 +++++++ examples/div-by-zero.c | 4 +-- 4 files changed, 47 insertions(+), 24 deletions(-) create mode 100644 copy.sh create mode 100644 dejump.sh diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 21ca828..6039566 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,25 +10,31 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - name: Pull the Docker image - run: | - mkdir out - docker pull yegor256/c2eo:0.1.24 - - name: Run the Docker image - run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/hello.c out/global.eo - - name: Check out/global.eo - run: cat out/global.eo - - name: Run Polystat Jar - run: bash polystat.sh - - name: Check polystat-eo-out.txt - run: cat polystat-eo-out.txt - - name: Upload results - uses: actions/upload-artifact@v3 - with: - name: polystat-eo-out - path: polystat-eo-out.txt + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Pull the Docker image + run: | + mkdir out + docker pull yegor256/c2eo:0.1.24 + - name: Copy c2o.cooperators + run: bash copy.sh + - name: Run the Docker image + run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/hello.c out/global.eo + - name: Check out/global.eo + run: | + ls -la out + cat out/global.eo + - name: Removing goto + run: bash dejump.sh + - name: Run Polystat Jar + run: bash polystat.sh + - name: Check polystat-eo-out.txt + run: cat polystat-eo-out.txt + - name: Upload results + uses: actions/upload-artifact@v3 + with: + name: polystat-eo-out + path: polystat-eo-out.txt diff --git a/copy.sh b/copy.sh new file mode 100644 index 0000000..0c2c636 --- /dev/null +++ b/copy.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +mkdir out/c2eo +git clone "https://github.com/polystat/c2eo.git" --branch master +ls -la +ls -la c2eo +cp -r c2eo/project/eo-lib out/c2eo diff --git a/dejump.sh b/dejump.sh new file mode 100644 index 0000000..e6d1f78 --- /dev/null +++ b/dejump.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Download Dejump jar file +curl -L -o dejump-0.0.2-jar-with-dependencies.jar "https://repo1.maven.org/maven2/org/eolang/dejump/0.0.2/dejump-0.0.2-jar-with-dependencies.jar" +echo "Dejump jar was downloaded" +java -jar dejump-0.0.2-jar-with-dependencies.jar --eo out/global.eo +echo "GOTO was removed, check the result: " +cat out/generated/global_transformed.eo +echo "Rename file" +mv out/generated/global_transformed.eo out/generated/global.eo \ No newline at end of file diff --git a/examples/div-by-zero.c b/examples/div-by-zero.c index 4134be4..840544e 100644 --- a/examples/div-by-zero.c +++ b/examples/div-by-zero.c @@ -1,3 +1,3 @@ -auto test(int a, int b) -> int { - return (a / b) + ((b / a) / a); +int check(int x) { + return 42 / x; } \ No newline at end of file From 7adbeb369a5b6ad3216a944fde95fca5e646f3f3 Mon Sep 17 00:00:00 2001 From: graur Date: Thu, 24 Nov 2022 16:58:04 +0300 Subject: [PATCH 03/10] #35 - fixed dicker run --- .github/workflows/validate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 6039566..b43b0cf 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -22,7 +22,7 @@ jobs: - name: Copy c2o.cooperators run: bash copy.sh - name: Run the Docker image - run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/hello.c out/global.eo + run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/div-by-zero.c out/global.eo - name: Check out/global.eo run: | ls -la out From 8d380fa680ae2dc997698dacc79bde6582852925 Mon Sep 17 00:00:00 2001 From: graur Date: Mon, 21 Nov 2022 20:03:20 +0300 Subject: [PATCH 04/10] #35 - fixed docker run #35 - fixed workflow #35 - added github actions workflow for find division by zero errors --- .github/workflows/validate.yml | 40 ++++++++++++++++++++++++++++++++++ copy.sh | 7 ++++++ dejump.sh | 10 +++++++++ examples/div-by-zero.c | 3 +++ polystat.sh | 8 +++++++ 5 files changed, 68 insertions(+) create mode 100644 .github/workflows/validate.yml create mode 100644 copy.sh create mode 100644 dejump.sh create mode 100644 examples/div-by-zero.c create mode 100644 polystat.sh diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..b43b0cf --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,40 @@ +name: С++ division by zero validation + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - name: Pull the Docker image + run: | + mkdir out + docker pull yegor256/c2eo:0.1.24 + - name: Copy c2o.cooperators + run: bash copy.sh + - name: Run the Docker image + run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/div-by-zero.c out/global.eo + - name: Check out/global.eo + run: | + ls -la out + cat out/global.eo + - name: Removing goto + run: bash dejump.sh + - name: Run Polystat Jar + run: bash polystat.sh + - name: Check polystat-eo-out.txt + run: cat polystat-eo-out.txt + - name: Upload results + uses: actions/upload-artifact@v3 + with: + name: polystat-eo-out + path: polystat-eo-out.txt diff --git a/copy.sh b/copy.sh new file mode 100644 index 0000000..0c2c636 --- /dev/null +++ b/copy.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +mkdir out/c2eo +git clone "https://github.com/polystat/c2eo.git" --branch master +ls -la +ls -la c2eo +cp -r c2eo/project/eo-lib out/c2eo diff --git a/dejump.sh b/dejump.sh new file mode 100644 index 0000000..e6d1f78 --- /dev/null +++ b/dejump.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Download Dejump jar file +curl -L -o dejump-0.0.2-jar-with-dependencies.jar "https://repo1.maven.org/maven2/org/eolang/dejump/0.0.2/dejump-0.0.2-jar-with-dependencies.jar" +echo "Dejump jar was downloaded" +java -jar dejump-0.0.2-jar-with-dependencies.jar --eo out/global.eo +echo "GOTO was removed, check the result: " +cat out/generated/global_transformed.eo +echo "Rename file" +mv out/generated/global_transformed.eo out/generated/global.eo \ No newline at end of file diff --git a/examples/div-by-zero.c b/examples/div-by-zero.c new file mode 100644 index 0000000..840544e --- /dev/null +++ b/examples/div-by-zero.c @@ -0,0 +1,3 @@ +int check(int x) { + return 42 / x; +} \ No newline at end of file diff --git a/polystat.sh b/polystat.sh new file mode 100644 index 0000000..7101acc --- /dev/null +++ b/polystat.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Run Polystat (EO) and save reports to "results" folder +curl -L -o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" +echo "Polystat (EO) analysis has started" +touch polystat-eo-out.txt +java -jar polystat.jar eo --in out --to file=polystat-eo-out.txt --sarif +echo "Polystat (EO) analysis has finished"o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" \ No newline at end of file From 43840c3a64c6f4d460c41985ffd2ace1c509cddb Mon Sep 17 00:00:00 2001 From: graur Date: Thu, 24 Nov 2022 17:13:05 +0300 Subject: [PATCH 05/10] #35 - clean up --- .github/workflows/validate.yml | 12 +++++------- copy.sh | 2 -- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index b43b0cf..16f7ff6 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -15,25 +15,23 @@ jobs: with: java-version: '17' distribution: 'temurin' - - name: Pull the Docker image + - name: Pull c2eo Docker image run: | mkdir out docker pull yegor256/c2eo:0.1.24 - name: Copy c2o.cooperators run: bash copy.sh - - name: Run the Docker image + - name: Run c2eo Docker image run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/div-by-zero.c out/global.eo - name: Check out/global.eo - run: | - ls -la out - cat out/global.eo + run: cat out/global.eo - name: Removing goto run: bash dejump.sh - - name: Run Polystat Jar + - name: Start Polystat Check run: bash polystat.sh - name: Check polystat-eo-out.txt run: cat polystat-eo-out.txt - - name: Upload results + - name: Upload results as artifact uses: actions/upload-artifact@v3 with: name: polystat-eo-out diff --git a/copy.sh b/copy.sh index 0c2c636..8b7a503 100644 --- a/copy.sh +++ b/copy.sh @@ -2,6 +2,4 @@ mkdir out/c2eo git clone "https://github.com/polystat/c2eo.git" --branch master -ls -la -ls -la c2eo cp -r c2eo/project/eo-lib out/c2eo From 4fef7227f4651e92a1a5e449afabefd4a3865a9a Mon Sep 17 00:00:00 2001 From: graur Date: Fri, 25 Nov 2022 13:34:21 +0300 Subject: [PATCH 06/10] #35 - clean up --- .github/workflows/validate.yml | 20 +++------------ copy.sh | 5 ---- dejump.sh | 10 -------- examples/README.md | 21 ++++++++++++++++ examples/run.sh | 46 ++++++++++++++++++++++++++++++++++ polystat.sh | 8 ------ 6 files changed, 70 insertions(+), 40 deletions(-) delete mode 100644 copy.sh delete mode 100644 dejump.sh create mode 100644 examples/README.md create mode 100644 examples/run.sh delete mode 100644 polystat.sh diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 16f7ff6..17727fb 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -7,7 +7,7 @@ on: branches: [ "master" ] jobs: - build: + validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -15,22 +15,8 @@ jobs: with: java-version: '17' distribution: 'temurin' - - name: Pull c2eo Docker image - run: | - mkdir out - docker pull yegor256/c2eo:0.1.24 - - name: Copy c2o.cooperators - run: bash copy.sh - - name: Run c2eo Docker image - run: docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 examples/div-by-zero.c out/global.eo - - name: Check out/global.eo - run: cat out/global.eo - - name: Removing goto - run: bash dejump.sh - - name: Start Polystat Check - run: bash polystat.sh - - name: Check polystat-eo-out.txt - run: cat polystat-eo-out.txt + - name: Validate + run: bash examples/run.sh examples/div-by-zero.c - name: Upload results as artifact uses: actions/upload-artifact@v3 with: diff --git a/copy.sh b/copy.sh deleted file mode 100644 index 8b7a503..0000000 --- a/copy.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -mkdir out/c2eo -git clone "https://github.com/polystat/c2eo.git" --branch master -cp -r c2eo/project/eo-lib out/c2eo diff --git a/dejump.sh b/dejump.sh deleted file mode 100644 index e6d1f78..0000000 --- a/dejump.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# Download Dejump jar file -curl -L -o dejump-0.0.2-jar-with-dependencies.jar "https://repo1.maven.org/maven2/org/eolang/dejump/0.0.2/dejump-0.0.2-jar-with-dependencies.jar" -echo "Dejump jar was downloaded" -java -jar dejump-0.0.2-jar-with-dependencies.jar --eo out/global.eo -echo "GOTO was removed, check the result: " -cat out/generated/global_transformed.eo -echo "Rename file" -mv out/generated/global_transformed.eo out/generated/global.eo \ No newline at end of file diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..b5bbb2d --- /dev/null +++ b/examples/README.md @@ -0,0 +1,21 @@ + + +[![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org) +[![DevOps By Rultor.com](http://www.rultor.com/b/polystat/far)](http://www.rultor.com/p/polystat/far) +[![We recommend IntelliJ IDEA](https://www.elegantobjects.org/intellij-idea.svg)](https://www.jetbrains.com/idea/) + +[![CI checks](https://github.com/polystat/far/actions/workflows/mvn.yml/badge.svg)](https://github.com/polystat/far/actions/workflows/mvn.yml) +[![PDD status](http://www.0pdd.com/svg?name=polystat/far)](http://www.0pdd.com/p?name=polystat/far) +[![codecov](https://codecov.io/gh/polystat/far/branch/master/graph/badge.svg)](https://codecov.io/gh/polystat/far) + +[![Javadoc](http://www.javadoc.io/badge/org.polystat/far.svg)](http://www.javadoc.io/doc/org.polystat/far) +[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/polystat/far/blob/master/LICENSE.txt) +[![Maven Central](https://img.shields.io/maven-central/v/org.polystat/far.svg)](https://maven-badges.herokuapp.com/maven-central/org.polystat/far) +[![Hits-of-Code](https://hitsofcode.com/github/polystat/far)](https://hitsofcode.com/view/github/polystat/far) +![Lines of code](https://img.shields.io/tokei/lines/github/polystat/far) + +To start validating C/C++ file and checking it for division by zero error, just do: +```shell +bash run.sh {your C/C++ file path} +``` + diff --git a/examples/run.sh b/examples/run.sh new file mode 100644 index 0000000..b61126c --- /dev/null +++ b/examples/run.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +file=$1 + +echo "Pull c2eo Docker image" +mkdir out +docker pull yegor256/c2eo:0.1.24 +echo "Finished pulling" + +echo "Run c2eo Docker image" +docker run -v $(pwd):/eo yegor256/c2eo:0.1.24 $file out/global.eo +echo "Finished running" + +echo "Check out/global.eo" +ls -la out +cat out/global.eo +echo "Finished cheking" + +echo "Copy c2o.cooperators" +mkdir out/c2eo +git clone "https://github.com/polystat/c2eo.git" --branch master +cp -r c2eo/project/eo-lib out/c2eo +echo "Finished copy" + +echo "Removing goto" +# Download Dejump jar file +curl -L -o dejump-0.0.2-jar-with-dependencies.jar "https://repo1.maven.org/maven2/org/eolang/dejump/0.0.2/dejump-0.0.2-jar-with-dependencies.jar" +echo "Dejump jar was downloaded" +java -jar dejump-0.0.2-jar-with-dependencies.jar --eo out/global.eo +echo "GOTO was removed, check the result: " +cat out/generated/global_transformed.eo +echo "Rename file" +mv out/generated/global_transformed.eo out/generated/global.eo +echo "Finished Removing" + +echo "Run Polystat Jar" +# Run Polystat (EO) and save reports to "results" folder +curl -L -o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" +echo "Polystat (EO) analysis has started" +touch polystat-eo-out.txt +java -jar polystat.jar eo --in out/generated --to file=polystat-eo-out.txt --sarif +echo "Polystat (EO) analysis has finished"o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" +echo "Finished running" + +echo "Check polystat-eo-out.txt" +cat polystat-eo-out.txt diff --git a/polystat.sh b/polystat.sh deleted file mode 100644 index 7101acc..0000000 --- a/polystat.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# Run Polystat (EO) and save reports to "results" folder -curl -L -o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" -echo "Polystat (EO) analysis has started" -touch polystat-eo-out.txt -java -jar polystat.jar eo --in out --to file=polystat-eo-out.txt --sarif -echo "Polystat (EO) analysis has finished"o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" \ No newline at end of file From 2e47f1e06c6598eb47f311a0c8a3eddc3d41c121 Mon Sep 17 00:00:00 2001 From: graur Date: Mon, 5 Dec 2022 15:32:12 +0300 Subject: [PATCH 07/10] #35 - added on push trigger --- .github/workflows/validate.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 17727fb..b002be7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -3,8 +3,12 @@ name: С++ division by zero validation on: push: branches: [ "master" ] + paths: + - examples/** pull_request: branches: [ "master" ] + paths: + - examples/** jobs: validate: From 7e47fb0afeb9dca080aeb3d2ace9c20f9d8d8618 Mon Sep 17 00:00:00 2001 From: graur Date: Tue, 6 Dec 2022 11:13:01 +0300 Subject: [PATCH 08/10] #35 - create intermediate EO representation --- examples/org.eolang/global.eo | 6 ++++++ examples/run.sh | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 examples/org.eolang/global.eo diff --git a/examples/org.eolang/global.eo b/examples/org.eolang/global.eo new file mode 100644 index 0000000..9303401 --- /dev/null +++ b/examples/org.eolang/global.eo @@ -0,0 +1,6 @@ +package examples.org.eolang + +[x] > global + div. > @ + 42 + x diff --git a/examples/run.sh b/examples/run.sh index b61126c..22aa50e 100644 --- a/examples/run.sh +++ b/examples/run.sh @@ -38,7 +38,8 @@ echo "Run Polystat Jar" curl -L -o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" echo "Polystat (EO) analysis has started" touch polystat-eo-out.txt -java -jar polystat.jar eo --in out/generated --to file=polystat-eo-out.txt --sarif +java -jar polystat.jar eo --in examples/org/eolang --to file=polystat-eo-out.txt --sarif +#java -jar polystat.jar eo --in out/generated --to file=polystat-eo-out.txt --sarif echo "Polystat (EO) analysis has finished"o polystat.jar "https://github.com/polystat/polystat-cli/releases/download/v0.1.11/polystat.jar" echo "Finished running" From fffbde5e8cb54eff2424a3e665da091013a99e93 Mon Sep 17 00:00:00 2001 From: graur Date: Tue, 6 Dec 2022 11:17:06 +0300 Subject: [PATCH 09/10] #35 - change path --- examples/{org.eolang => org/eolang}/global.eo | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{org.eolang => org/eolang}/global.eo (100%) diff --git a/examples/org.eolang/global.eo b/examples/org/eolang/global.eo similarity index 100% rename from examples/org.eolang/global.eo rename to examples/org/eolang/global.eo From 1c20d7651e63f5e39f0cb81314af31220e3a0092 Mon Sep 17 00:00:00 2001 From: graur Date: Tue, 6 Dec 2022 17:05:29 +0300 Subject: [PATCH 10/10] #35 - added strict mode to run.sh --- examples/run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/run.sh b/examples/run.sh index 22aa50e..cf5cdaf 100644 --- a/examples/run.sh +++ b/examples/run.sh @@ -1,5 +1,6 @@ #!/bin/bash +set -euox pipefail file=$1 echo "Pull c2eo Docker image"