{"id":24374583,"url":"https://github.com/hurricanemark/appllicationversioning","last_synced_at":"2026-04-05T21:03:38.303Z","repository":{"id":272504971,"uuid":"916820981","full_name":"hurricanemark/AppllicationVersioning","owner":"hurricanemark","description":"General integration of versioning to include Git tag, major \u0026 minor number, patch information","archived":false,"fork":false,"pushed_at":"2025-01-31T21:48:48.000Z","size":74,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T11:48:49.822Z","etag":null,"topics":["bash","cpp","cs","java","javascript","python"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hurricanemark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-14T20:25:15.000Z","updated_at":"2025-01-31T21:48:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"ed425ed7-f19f-486f-8ffa-3ed7a32387c8","html_url":"https://github.com/hurricanemark/AppllicationVersioning","commit_stats":null,"previous_names":["hurricanemark/apllicationversioning"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/hurricanemark/AppllicationVersioning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FAppllicationVersioning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FAppllicationVersioning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FAppllicationVersioning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FAppllicationVersioning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hurricanemark","download_url":"https://codeload.github.com/hurricanemark/AppllicationVersioning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hurricanemark%2FAppllicationVersioning/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267368932,"owners_count":24076093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","cpp","cs","java","javascript","python"],"created_at":"2025-01-19T05:40:48.826Z","updated_at":"2025-12-30T21:57:43.203Z","avatar_url":"https://github.com/hurricanemark.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Apllication Versioning\n\nWe assume there is an upstream artifact (e.g Git tag exists with the sematic of `v[Major].[Minor].[path]` on the repository containing build source.\nTo implement versioning using Git tags and the semantic versioning system (major, minor, patch) in multiple programming languages, let's first define the following approach:\n\n1. **Git Tagging**: We will extract the Git tag (e.g., `v1.2.3`) from the Git repository.\n2. **Versioning Scheme**: The version will follow the Semantic Versioning scheme: `major.minor.patch`.\n3. **Implementation**: For simplicity, I'll assume that the program can read the version from a file or Git tag, then parse it and display it.\n\nHere's how you might implement this in C++, C#, Python, Java, Javascript, and Bash:\n\n**Note**: *Execute within the cloned repository to correctly retrieve the version tag*.  *For compilable code, write the versioning tag as a static variable, compile it, and print the variable when queried for version info*.\n\n### 1. **C++ Program**\n\nTo integrate Git tags in C++, we'll use a system call to execute Git commands from within the program.\n\n\n\n```cpp\n#include \u003ciostream\u003e\n#include \u003ccstdlib\u003e\n#include \u003csstream\u003e\n\nstd::string get_git_version() {\n    // Use a system call to get the current Git tag\n    const char* command = \"git describe --tags --abbrev=0\"; \n    char buffer[128];\n    std::string result = \"\";\n    \n    FILE* fp = popen(command, \"r\");\n    if (fp == nullptr) {\n        std::cerr \u003c\u003c \"Error getting Git tag version\" \u003c\u003c std::endl;\n        return \"\";\n    }\n    \n    while (fgets(buffer, sizeof(buffer), fp) != nullptr) {\n        result += buffer;\n    }\n    fclose(fp);\n\n    // Remove the newline character\n    result.erase(result.find_last_not_of(\"\\n\") + 1);\n    return result;\n}\n\nint main() {\n    std::string version = get_git_version();\n    \n    if (!version.empty()) {\n        std::cout \u003c\u003c \"Current Version: \" \u003c\u003c version \u003c\u003c std::endl;\n    } else {\n        std::cerr \u003c\u003c \"Error: Version not found.\" \u003c\u003c std::endl;\n    }\n    \n    return 0;\n}\n```\n\n(*) For actual implementation, I suggest to write variable *VERSION = get_git_version();* in `version.h` file, then insert `std::cout \u003c\u003c \"Current Version: \" \u003c\u003c VERSION \u003c\u003c std::endl;` in `main.cpp`.  Include `version.h` in your compilation.\n\n\n### 2. **C# Program**\n\nIn C#, you can use the `System.Diagnostics` namespace to run Git commands.\n\n```csharp\nusing System;\nusing System.Diagnostics;\n\nclass Program\n{\n    static string GetGitVersion()\n    {\n        ProcessStartInfo startInfo = new ProcessStartInfo\n        {\n            FileName = \"git\",\n            Arguments = \"describe --tags --abbrev=0\",\n            RedirectStandardOutput = true,\n            UseShellExecute = false,\n            CreateNoWindow = true\n        };\n\n        using (Process process = Process.Start(startInfo))\n        using (var reader = process.StandardOutput)\n        {\n            return reader.ReadToEnd().Trim();\n        }\n    }\n\n    static void Main()\n    {\n        string version = GetGitVersion();\n        \n        if (!string.IsNullOrEmpty(version))\n        {\n            Console.WriteLine(\"Current Version: \" + version);\n        }\n        else\n        {\n            Console.WriteLine(\"Error: Version not found.\");\n        }\n    }\n}\n```\n\n### 3. **Python Program**\n\nPython's `subprocess` module allows you to run Git commands.\n\n```python\nimport subprocess\n\ndef get_git_version():\n    try:\n        # Run the Git command to get the version\n        version = subprocess.check_output([\"git\", \"describe\", \"--tags\", \"--abbrev=0\"]).decode(\"utf-8\").strip()\n        return version\n    except subprocess.CalledProcessError as e:\n        print(\"Error getting Git tag version\")\n        return \"\"\n\nif __name__ == \"__main__\":\n    version = get_git_version()\n    \n    if version:\n        print(f\"Current Version: {version}\")\n    else:\n        print(\"Error: Version not found.\")\n```\n\n### 4. **Java Program**\n\nIn Java, you can use `Runtime.getRuntime().exec()` to run external commands.\n\n```java\nimport java.io.BufferedReader;\nimport java.io.InputStreamReader;\n\npublic class version {\n\n    public static String getGitVersion() {\n        try {\n            // Execute the Git command to get the version\n            ProcessBuilder processBuilder = new ProcessBuilder(\"git\", \"describe\", \"--tags\", \"--abbrev=0\");\n            processBuilder.redirectErrorStream(true);  // Combine standard and error output streams\n            Process process = processBuilder.start();\n\n            // Read the output of the command\n            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));\n            String version = reader.readLine();\n            \n            // Wait for the process to exit and check the exit value\n            int exitCode = process.waitFor();\n            \n            if (exitCode == 0) {\n                return version != null ? version.trim() : \"\";\n            } else {\n                System.out.println(\"Git command failed with exit code: \" + exitCode);\n                return \"\";\n            }\n\n        } catch (Exception e) {\n            System.out.println(\"Error getting Git tag version: \" + e.getMessage());\n            return \"\";\n        }\n    }\n\n    public static void main(String[] args) {\n        String version = getGitVersion();\n        \n        if (version != null \u0026\u0026 !version.isEmpty()) {\n            System.out.println(\"Current Version: \" + version);\n        } else {\n            System.out.println(\"Error: Version not found.\");\n        }\n    }\n}\n```\n\n## **Javascript** \nIn Java, you can use process `exec()` to run external commands.\n\n```javascript\nconst { exec } = require('child_process');\n\nfunction getGitVersion() {\n    return new Promise((resolve, reject) =\u003e {\n        // Execute the Git command to get the version\n        exec('git describe --tags --abbrev=0', (error, stdout, stderr) =\u003e {\n            if (error) {\n                reject(`Error executing Git command: ${error.message}`);\n                return;\n            }\n            if (stderr) {\n                reject(`Error: ${stderr}`);\n                return;\n            }\n            // Trim the output to get the version\n            const version = stdout.trim();\n            if (version) {\n                resolve(version);\n            } else {\n                reject('Error: Version not found.');\n            }\n        });\n    });\n}\n\ngetGitVersion()\n    .then(version =\u003e {\n        console.log(`Current Version: ${version}`);\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n## **Bash script**\n\n```bash\n#!/bin/bash\n\nget_git_version() {\n    # Execute the Git command to get the version\n    version=$(git describe --tags --abbrev=0 2\u003e/dev/null)\n    \n    if [ $? -eq 0 ]; then\n        # If git command succeeded, print the version\n        echo \"Current Version: $version\"\n    else\n        # If git command failed, print an error message\n        echo \"Error: Version not found or git command failed.\"\n    fi\n}\n\nget_git_version\n```\n\n\n### Explanation:\n\n- **Git Command**: All programs execute `git describe --tags --abbrev=0` to fetch the most recent Git tag.\n- **Version Format**: The Git tag should be in the format `v\u003cmajor\u003e.\u003cminor\u003e.\u003cpatch\u003e` (e.g., `v1.2.3`).\n- **Error Handling**: If the Git tag is not found, the programs will display an error message.\n\n### Notes:\n\n- These programs assume that Git is installed on the system and that the program is executed inside a Git repository.\n- The programs display the version retrieved from the Git tag, which is typically managed by the developer during the release process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fappllicationversioning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhurricanemark%2Fappllicationversioning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhurricanemark%2Fappllicationversioning/lists"}