From 0b661411ff8b2922bcac388eeeb493938253c6d8 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Tue, 12 Mar 2024 13:16:05 +0100 Subject: [PATCH 1/3] Add Semver as a top-level package aliasing Semantic_Versioning --- src/semver.ads | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/semver.ads diff --git a/src/semver.ads b/src/semver.ads new file mode 100644 index 0000000..67a4fe1 --- /dev/null +++ b/src/semver.ads @@ -0,0 +1,3 @@ +with Semantic_Versioning; + +package Semver renames Semantic_Versioning; From 021a2761eaa0a03b76f1681d556ca4b2255c9552 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Thu, 20 Jun 2024 18:23:20 +0200 Subject: [PATCH 2/3] Do not fail relaxed parsing on empty minor/patch numbers --- src/semantic_versioning-demo.adb | 4 ++++ src/semantic_versioning-parser.adb | 6 +++-- src/semantic_versioning.adb | 36 +++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/semantic_versioning-demo.adb b/src/semantic_versioning-demo.adb index 94b7c96..6e8076c 100644 --- a/src/semantic_versioning-demo.adb +++ b/src/semantic_versioning-demo.adb @@ -197,5 +197,9 @@ begin pragma Assert (not X.Is_In (V ("1"), X.Value ("!(1|3)"))); pragma Assert (not X.Is_In (V ("3"), X.Value ("!(1|3)"))); + -- Relaxed parsing, instead of failing we should dump the first strange thing into the build part + pragma Assert (Parse ("1.dfsg-3.1ubuntu2", Relaxed => True) = V ("1+.dfsg-3.1ubuntu2")); + pragma Assert (Parse ("1.3.dfsg-3.1ubuntu2", Relaxed => True) = V ("1.3+.dfsg-3.1ubuntu2")); + Put_Line ("OK"); end Semantic_Versioning.Demo; diff --git a/src/semantic_versioning-parser.adb b/src/semantic_versioning-parser.adb index b569b33..5e7409c 100644 --- a/src/semantic_versioning-parser.adb +++ b/src/semantic_versioning-parser.adb @@ -1,4 +1,5 @@ with Ada.Command_Line; use Ada.Command_Line; +with Ada.Exceptions; with Ada.Strings.UTF_Encoding.Wide_Wide_Strings; with Ada.Wide_Wide_Text_IO; use Ada.Wide_Wide_Text_IO; @@ -19,7 +20,8 @@ begin Put_Line (Decode (Image (V))); exception - when Malformed_Input => - Put_Line ("Uh oh... that was not a nice version!"); + when E : Malformed_Input => + Put_Line ("Uh oh... that was not a nice version: " + & Decode (Ada.Exceptions.Exception_Message (E))); end; end Semantic_Versioning.Parser; diff --git a/src/semantic_versioning.adb b/src/semantic_versioning.adb index 33c3c75..d45bdf0 100644 --- a/src/semantic_versioning.adb +++ b/src/semantic_versioning.adb @@ -70,14 +70,16 @@ package body Semantic_Versioning is function Eat_Number return Point is Last : Natural := Next + 1; begin + if Next <= Description'Last and then Next_Token (Next) /= Number then + raise Malformed_Input with "Empty point number: " & Description (Next); + elsif Next > Description'Last then + raise Malformed_Input with "Empty point number (EOF)"; + end if; + while Last <= Description'Last and then Next_Token (Last) = Number loop Last := Last + 1; end loop; - if Next > Description'Last or else Last = Next then - raise Malformed_Input with "Empty point number"; - end if; - return Number : constant Point := Point'Value (Description (Next .. Last - 1)) do Next := Last; end return; @@ -138,8 +140,30 @@ package body Semantic_Versioning is begin case To_See is when Major => V.Major := Eat_Number; - when Minor => V.Minor := Eat_Number; - when Patch => V.Patch := Eat_Number; + when Minor => + begin + V.Minor := Eat_Number; + exception + when Malformed_Input => + if Relaxed then + Next := Next - 1; -- We need to re-eat the '.' + Accept_Build; + else + raise; + end if; + end; + when Patch => + begin + V.Patch := Eat_Number; + exception + when Malformed_Input => + if Relaxed then + Next := Next - 1; -- We need to re-eat the '.' + Accept_Build; + else + raise; + end if; + end; when others => raise Malformed_Input with "All foreseeable points already seen"; end case; To_See := Foreseeable'Succ (To_See); From bbc9ac08a91ef94d5220fdf5fc40a4e64cf7e713 Mon Sep 17 00:00:00 2001 From: "Alejandro R. Mosteo" Date: Thu, 20 Jun 2024 18:31:10 +0200 Subject: [PATCH 3/3] Update workflow to recent practices --- .github/workflows/build.yml | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17b625d..77eb5e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,9 @@ name: build on: push: + branches: + - main + - master pull_request: paths-ignore: - 'doc/**' @@ -10,17 +13,18 @@ on: jobs: build: - name: ${{ matrix.os }} - + name: ${{ matrix.os }} / GNAT ${{ matrix.gnat }} + runs-on: ${{ matrix.os }} - + strategy: matrix: os: - - macos-latest + - macos-12 - ubuntu-latest - windows-latest - + gnat: [10, 11, 12, 13, 14] + steps: - name: Check out repository uses: actions/checkout@v1 @@ -29,22 +33,9 @@ jobs: run: git submodule update --init --recursive - name: Set up GNAT toolchain (FSF) - if: matrix.os == 'ubuntu-latest' - uses: ada-actions/toolchain@ce2021 - with: - distrib: fsf - - - name: Set up GNAT toolchain (Community 2021) - if: matrix.os == 'windows-latest' - uses: ada-actions/toolchain@ce2021 - with: - distrib: community - - - name: Set up GNAT toolchain (Community 2020) - if: matrix.os == 'macos-latest' - uses: ada-actions/toolchain@ce2020 + uses: alire-project/alr-install@v1 with: - distrib: community + crates: gnat_native^${{matrix.gnat}} gprbuild - name: Build on demand run: gprbuild -j0 -p -XSEMVER_BUILD_MODE=On_Demand