navid/veins / commit

975c373dd19a

Navid M <navidmomtahen@gmail.com> · 2026-11-28

parents: 65360acd4617

Browse files at this commit · Download source

all: add tag pushing and releases workflow for this project
--- /dev/null+++ b/.circleci/config.yml@@ -0,0 +1,202 @@+version: 2.1++parameters:+  veinsforge_repository:+    type: string+    default: ""+  veinsforge_bookmark:+    type: string+    default: ""+  veinsforge_tag:+    type: string+    default: ""+  veinsforge_ref:+    type: string+    default: ""+  veinsforge_commit:+    type: string+    default: ""++executors:+  linux-x86_64:+    docker:+      - image: cimg/base:stable+    resource_class: medium+  linux-aarch64:+    machine:+      image: ubuntu-2204:current+    resource_class: arm.medium+  windows-x86_64:+    machine:+      image: windows-server-2022-gui:current+    resource_class: windows.medium++commands:+  install-linux-deps:+    steps:+      - run:+          name: Install build dependencies+          command: |+            sudo apt-get update+            sudo apt-get install -y cmake ninja-build g++ libssl-dev zlib1g-dev libzstd-dev zip jq curl+  build-and-package-linux:+    parameters:+      arch:+        type: string+    steps:+      - install-linux-deps+      - checkout+      - run:+          name: Configure+          command: |+            VERSION="${CIRCLE_TAG#v}"+            if [ -z "$VERSION" ]; then VERSION="0.0.0-dev"; fi+            echo "export VERSION=$VERSION" >> "$BASH_ENV"+            cmake -S xveins -B build -G Ninja \+              -DCMAKE_BUILD_TYPE=Release \+              -DVN_VERSION="$VERSION"+      - run:+          name: Build+          command: cmake --build build -j "$(nproc)"+      - run:+          name: Test+          command: ctest --test-dir build --output-on-failure+      - run:+          name: Package+          command: |+            cmake --install build --prefix stage+            mkdir -p workspace/release workspace/artifacts+            (cd stage && zip -r "../workspace/release/vn-${VERSION}-linux-<< parameters.arch >>.zip" .)+      - store_artifacts:+          path: workspace/release+      - run:+          name: Record artifact links+          command: |+            if [ -n "$CIRCLECI_API_TOKEN" ]; then+              curl -fsS -H "Circle-Token: $CIRCLECI_API_TOKEN" \+                "https://circleci.com/api/v2/job/$CIRCLE_WORKFLOW_JOB_ID/artifacts" \+                > "workspace/artifacts/${CIRCLE_JOB}.json"+            else+              printf '{"items":[]}\n' > "workspace/artifacts/${CIRCLE_JOB}.json"+            fi+      - persist_to_workspace:+          root: .+          paths:+            - workspace/artifacts+            - workspace/release++jobs:+  build-linux-x86_64:+    executor: linux-x86_64+    steps:+      - build-and-package-linux:+          arch: x86_64++  build-linux-aarch64:+    executor: linux-aarch64+    steps:+      - build-and-package-linux:+          arch: aarch64++  build-windows-x86_64:+    executor: windows-x86_64+    steps:+      - checkout+      - run:+          name: Install build dependencies+          shell: powershell+          command: |+            choco install cmake ninja -y --no-progress+            if (-not (Test-Path C:\vcpkg\vcpkg.exe)) {+              git clone --depth 1 https://github.com/microsoft/vcpkg.git C:\vcpkg+              C:\vcpkg\bootstrap-vcpkg.bat+            }+            C:\vcpkg\vcpkg.exe install openssl:x64-windows-static zlib:x64-windows-static zstd:x64-windows-static+      - run:+          name: Configure+          shell: powershell+          command: |+            $version = if ($env:CIRCLE_TAG) { $env:CIRCLE_TAG -replace '^v', '' } else { '0.0.0-dev' }+            "VERSION=$version" | Out-File -FilePath $env:BASH_ENV -Append -Encoding ascii+            cmake -S xveins -B build -G Ninja `+              -DCMAKE_BUILD_TYPE=Release `+              -DVN_VERSION="$version" `+              -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake `+              -DVCPKG_TARGET_TRIPLET=x64-windows-static+      - run:+          name: Build+          shell: powershell+          command: cmake --build build -j 4+      - run:+          name: Test+          shell: powershell+          command: ctest --test-dir build -C Release --output-on-failure+      - run:+          name: Package+          shell: powershell+          command: |+            $version = if ($env:CIRCLE_TAG) { $env:CIRCLE_TAG -replace '^v', '' } else { '0.0.0-dev' }+            cmake --install build --prefix stage+            New-Item -ItemType Directory -Force -Path workspace\release | Out-Null+            Compress-Archive -Path stage\* -DestinationPath "workspace\release\vn-$version-windows-x86_64.zip"+      - store_artifacts:+          path: workspace/release+      - run:+          name: Record artifact links+          shell: powershell+          command: |+            New-Item -ItemType Directory -Force -Path workspace\artifacts | Out-Null+            if ($env:CIRCLECI_API_TOKEN) {+              Invoke-RestMethod -Headers @{ "Circle-Token" = $env:CIRCLECI_API_TOKEN } `+                -Uri "https://circleci.com/api/v2/job/$env:CIRCLE_WORKFLOW_JOB_ID/artifacts" `+                -OutFile "workspace\artifacts\$env:CIRCLE_JOB.json"+            } else {+              '{"items":[]}' | Out-File -FilePath "workspace\artifacts\$env:CIRCLE_JOB.json" -Encoding ascii+            }+      - persist_to_workspace:+          root: .+          paths:+            - workspace/artifacts+            - workspace/release++  release-report:+    executor: linux-x86_64+    steps:+      - install-linux-deps+      - attach_workspace:+          at: /tmp/workspace+      - run:+          name: Report release to Veinsforge+          command: |+            if [ -z "$VEINSFORGE_URL" ] || [ -z "$VEINSFORGE_CI_TOKEN" ]; then+              echo "VEINSFORGE_URL and VEINSFORGE_CI_TOKEN are required to publish a release."+              exit 1+            fi+            artifacts=$(jq -s '[.[] .items[] | {name: .path, url: .url}]' /tmp/workspace/workspace/artifacts/*.json)+            body=$(jq -n \+              --arg tag "$CIRCLE_TAG" \+              --arg commit "$CIRCLE_SHA1" \+              --arg build "$CIRCLE_BUILD_URL" \+              --argjson artifacts "$artifacts" \+              '{tag:$tag, commit:$commit, provider:"circleci", build_url:$build, artifacts:$artifacts}')+            curl -fsS -X POST "${VEINSFORGE_URL%/}/api/v1/ci/release" \+              -H "Authorization: Bearer $VEINSFORGE_CI_TOKEN" \+              -H "Content-Type: application/json" \+              -d "$body"++workflows:+  build:+    jobs:+      - build-linux-x86_64+      - build-linux-aarch64+      - build-windows-x86_64+      - release-report:+          requires:+            - build-linux-x86_64+            - build-linux-aarch64+            - build-windows-x86_64+          filters:+            branches:+              ignore: /.*/+            tags:+              only: /^v.*/--- a/xveins/CMakeLists.txt+++ b/xveins/CMakeLists.txt@@ -150,6 +150,7 @@ )  check_cxx_compiler_flag(-Wconversion VN_HAS_WCONVERSION)+set(VN_VERSION "${PROJECT_VERSION}" CACHE STRING "veins version")  function(vn_configure_target target)     target_include_directories(${target} PRIVATE src)@@ -164,7 +165,7 @@     if(WIN32)         target_link_libraries(${target} PRIVATE bcrypt ws2_32 crypt32)     endif()-    target_compile_definitions(${target} PRIVATE VN_VERSION="0.0.1")+    target_compile_definitions(${target} PRIVATE VN_VERSION="${VN_VERSION}")      if(MSVC)         target_compile_options(${target} PRIVATE /W4 /permissive- /EHsc /Zc:__cplusplus)--- a/xveins/src/cfg.cpp+++ b/xveins/src/cfg.cpp@@ -82,15 +82,9 @@     const std::string pager_default = "less -R"; #endif     std::map<std::string, std::string> defaults = {-        {"core.editor", "(unset)"},-        {"core.pager", "(unset)"},-        {"editor", editor_default},-        {"log.default_amount", "20"},-        {"merge.adjacent", "strict"},-        {"pager", pager_default},-        {"rename.autodetect", "similar"},-        {"user.email", "(unset)"},-        {"user.name", "(unset)"},+        {"core.editor", "(unset)"},       {"core.pager", "(unset)"},    {"editor", editor_default},+        {"log.default_amount", "20"},     {"merge.adjacent", "strict"}, {"pager", pager_default},+        {"rename.autodetect", "similar"}, {"user.email", "(unset)"},    {"user.name", "(unset)"},     };     if (internal) {         defaults["bookmark.current"] = "(unset)";--- a/xveins/src/common.cpp+++ b/xveins/src/common.cpp@@ -1653,7 +1653,8 @@         std::cout << text;         return false;     }-    const std::string command = pager_command(repo_root) + " " + shell_quote_arg(path_to_bytes(file));+    const std::string command =+        pager_command(repo_root) + " " + shell_quote_arg(path_to_bytes(file));     const bool ok = std::system(command.c_str()) == 0;     (void)remove_file(file);     if (!ok)--- a/xveins/src/net_commands.cpp+++ b/xveins/src/net_commands.cpp@@ -885,6 +885,7 @@     std::optional<Id> target;     std::vector<Id> commits;     std::vector<Id> objects;+    std::vector<std::pair<std::string, Id>> tags;     {         Store store = Store::open_all(root);         auto view = current_view(root, store);@@ -896,7 +897,11 @@             std::cout << "unknown bookmark: " << bookmark << "\n";             return 1;         }-        const std::array<Id, 1> roots{*target};+        std::vector<Id> roots{*target};+        for (const auto& tag : current.tags) {+            tags.emplace_back(tag.name, tag.target);+            roots.push_back(tag.target);+        }         commits = collect_commits(store, roots);         objects = objects_for_commits(store, commits);     }@@ -913,10 +918,27 @@     }     std::optional<Id> old;     for (const auto& ref : refs) {-        if (ref.name == bookmark)+        if (ref.kind == 0 && ref.name == bookmark)             old = ref.target;     }-    if (old && same_id(*old, *target)) {+    std::vector<proto::UpdateRef> updates;+    if (!old || !same_id(*old, *target))+        updates.push_back(proto::UpdateRef{bookmark, old, target});+    std::size_t tag_updates = 0;+    for (const auto& [name, tag_target] : tags) {+        std::optional<Id> tag_old;+        for (const auto& ref : refs) {+            if (ref.kind == 1 && ref.name == name) {+                tag_old = ref.target;+                break;+            }+        }+        if (tag_old && same_id(*tag_old, tag_target))+            continue;+        updates.push_back(proto::UpdateRef{"refs/tags/" + name, tag_old, tag_target});+        ++tag_updates;+    }+    if (updates.empty()) {         info_prefix();         std::cout << "nothing to push, everything is up to date\n";         return 0;@@ -925,8 +947,6 @@         report_client_error(*client, "push failed");         return 1;     }-    std::vector<proto::UpdateRef> updates;-    updates.push_back(proto::UpdateRef{bookmark, old, target});     if (!client->update_refs(updates)) {         report_client_error(*client, "ref update rejected");         return 1;@@ -933,6 +953,8 @@     }     info_prefix();     std::cout << "pushed " << bookmark << " to " << remote_name << "\n";+    if (tag_updates > 0)+        std::cout << "pushed " << tag_updates << " tag(s)\n";     return 0; } @@ -1350,6 +1372,7 @@         std::cout << "usage: vn push [-key:<name>] [<remote>] [<bookmark>] [path]\n\n";         std::cout << "push a bookmark to a configured native remote\n\n";         std::cout << "without <bookmark>, the current bookmark is pushed\n";+        std::cout << "tags reachable from the pushed bookmark are pushed too\n";         std::cout << "auth falls back to remote.<name>.key, then 'vn auth use'\n";         return true;     }--- a/xveins/src/server.cpp+++ b/xveins/src/server.cpp@@ -732,11 +732,24 @@     if (targets.adds.empty())         return std::nullopt;     return targets.adds.front();+}++constexpr std::string_view TAG_REF_PREFIX = "refs/tags/";++bool tag_ref(std::string_view name, std::string_view& tag_name) {+    if (!name.starts_with(TAG_REF_PREFIX))+        return false;+    tag_name = name.substr(TAG_REF_PREFIX.size());+    return !tag_name.empty(); }  bool ref_matches(const View& view, std::string_view name, const std::optional<Id>& expected) {     std::optional<Id> current;-    if (auto index = find_bookmark(view, name)) {+    std::string_view tag_name;+    if (tag_ref(name, tag_name)) {+        if (auto index = find_tag(view, tag_name))+            current = view.tags[*index].target;+    } else if (auto index = find_bookmark(view, name)) {         current = first_target(view.bookmarks[*index].targets);     } else if (auto index = find_tag(view, name)) {         current = view.tags[*index].target;@@ -749,6 +762,21 @@ }  void apply_ref(View& view, std::string_view name, const std::optional<Id>& target) {+    std::string_view tag_name;+    if (tag_ref(name, tag_name)) {+        const auto index = find_tag(view, tag_name);+        if (!target) {+            if (index)+                view.tags.erase(view.tags.begin() + static_cast<std::ptrdiff_t>(*index));+            return;+        }+        if (index) {+            view.tags[*index].target = *target;+            return;+        }+        view.tags.push_back(TagRef{std::string(tag_name), *target});+        return;+    }     if (!target) {         if (auto index = find_bookmark(view, name))             view.bookmarks.erase(view.bookmarks.begin() + static_cast<std::ptrdiff_t>(*index));--- a/xveins/tests/integration_tests.cpp+++ b/xveins/tests/integration_tests.cpp@@ -1175,6 +1175,11 @@     t.expect_contains(pushed.out, "pushed master");     t.expect_contains(f.vn({"log"}, source).out, "clone a change");     t.expect_contains(f.vn({"whoami", "origin"}, clone_a).out, "role: write");++    f.vn({"tag", "set", "v0.0.1"}, clone_a);+    const CommandResult tag_pushed = f.vn({"push", "origin", "master"}, clone_a);+    t.expect_contains(tag_pushed.out, "pushed 1 tag(s)");+    t.expect_contains(f.vn({"tag", "ls"}, source).out, "v0.0.1");      const fs::path clone_b = f.root / "clone-b";     f.vn({"clone", "file://" + source.string(), clone_b.string()}, f.root);--- a/xveins/tests/unit_tests.cpp+++ b/xveins/tests/unit_tests.cpp@@ -415,8 +415,8 @@                 false);      const TempDir temp;-    t.expect(write_file(temp.path / ".vnexclude",-                        bytes_of("*.tmp\nbuild/\n**/Testing/Temporary/*\n")));+    t.expect(+        write_file(temp.path / ".vnexclude", bytes_of("*.tmp\nbuild/\n**/Testing/Temporary/*\n")));     t.expect(ignore_path_ignored(temp.path, "note.tmp"));     t.expect(ignore_path_ignored(temp.path, "build/out.bin"));     t.expect(ignore_path_ignored(temp.path, "xveins/tests/Testing/Temporary/CTest.log"));