diff --git a/Combined/README.md b/Combined/README.md new file mode 100644 index 0000000..e9b8df5 --- /dev/null +++ b/Combined/README.md @@ -0,0 +1,68 @@ +# Combined Scripts + +This directory contains unified scripts that can work with both single-project and multi-project repository structures. + +## How It Works + +The scripts automatically detect the project structure: + +- **Multi-project**: Looks for `CSHARP_PACKAGE_VERSION.txt` files or `csharp/Platform.$REPOSITORY_NAME/` directory structure +- **Single-project**: Looks for `Platform.$REPOSITORY_NAME.csproj` in the root directory + +## Available Scripts + +### C# Scripts + +1. **publish-csharp-release.sh** + - Creates GitHub releases for C# packages + - Multi-project: Uses version from `CSHARP_PACKAGE_VERSION.txt` + - Single-project: Extracts version from `.csproj` file + +2. **push-csharp-nuget.sh** + - Publishes NuGet packages + - Multi-project: Uses version from `CSHARP_PACKAGE_VERSION.txt` + - Single-project: Extracts version from generated package + +3. **format-csharp-document.sh** + - Formats C# code for LaTeX documentation + - Multi-project: Processes `./csharp/Platform.$REPOSITORY_NAME/` structure + - Single-project: Processes current directory + +4. **generate-csharp-pdf.sh** + - Generates PDF documentation from C# code + - Works with output from `format-csharp-document.sh` + +5. **publish-csharp-docs.sh** + - Publishes documentation to GitHub Pages + - Multi-project: Creates `csharp/` subdirectory structure + - Single-project: Uses root directory + +## Usage + +Simply use these scripts as drop-in replacements for the separate single/multi-project scripts. They will automatically adapt to your repository structure. + +### Requirements + +- `$REPOSITORY_NAME` environment variable must be set +- For GitHub operations: `$GITHUB_TOKEN` environment variable +- For NuGet operations: `$NUGETTOKEN` environment variable + +### Example + +```bash +export REPOSITORY_NAME="MyLibrary" +export GITHUB_TOKEN="your_token_here" +export NUGETTOKEN="your_nuget_token_here" + +# These will work for both single and multi-project repositories +./publish-csharp-release.sh +./push-csharp-nuget.sh +``` + +## Migration + +To migrate from separate scripts: + +1. Replace calls to `MultiProjectRepository/script.sh` or `SingleProjectRepository/script.sh` +2. Use the equivalent `Combined/script.sh` instead +3. No other changes needed - the scripts are compatible with existing workflows \ No newline at end of file diff --git a/Combined/docfx.json b/Combined/docfx.json new file mode 100644 index 0000000..ce1cc13 --- /dev/null +++ b/Combined/docfx.json @@ -0,0 +1,39 @@ +{ + "metadata": [ + { + "src": [ + { + "files": [ "**/*.sln" ], + "exclude": [ "**/bin/**", "**/obj/**" ], + "src": "" + } + ], + "dest": "obj/api", + "filter": "filter.yml", + "properties": { "TargetFramework": "netstandard2.0" } + } + ], + "build": { + "content": [ + { + "files": [ "**/*.yml" ], + "src": "obj/api", + "dest": "api" + }, + { + "files": [ "*.md", "toc.yml" ] + } + ], + "globalMetadata": { + "_appTitle": "LinksPlatform's Platform.$REPOSITORY_NAME Library", + "_enableSearch": true, + "_gitContribute": { + "branch": "master" + }, + "_gitUrlPattern": "github" + }, + "markdownEngineName": "markdig", + "dest": "_site", + "xrefService": [ "https://xref.docs.microsoft.com/query?uid={uid}" ] + } +} diff --git a/Combined/format-csharp-document.sh b/Combined/format-csharp-document.sh new file mode 100755 index 0000000..3048a73 --- /dev/null +++ b/Combined/format-csharp-document.sh @@ -0,0 +1,151 @@ +#!/bin/bash +set -e # Exit with nonzero exit code if anything fails + +# Function to detect project structure +detect_project_structure() { + if [ -d "csharp" ] && [ -d "csharp/Platform.$REPOSITORY_NAME" ]; then + echo "multi" + elif [ -f "Platform.$REPOSITORY_NAME.csproj" ]; then + echo "single" + else + echo "unknown" + fi +} + +# Function to clean up auto-generated files for multi-project +cleanup_multi_project() { + set +e + find "./csharp/Platform.$REPOSITORY_NAME/obj" -type f -iname "*.cs" -delete 2>/dev/null + find "./csharp/Platform.$REPOSITORY_NAME.Tests/obj" -type f -iname "*.cs" -delete 2>/dev/null + set -e +} + +# Function to clean up auto-generated files for single-project +cleanup_single_project() { + find ./obj -type f -iname "*.cs" -delete 2>/dev/null || true +} + +# Function to process files for multi-project +process_multi_project_files() { + # Project files + find "./csharp/Platform.$REPOSITORY_NAME" -type f -iname '*.cs' | sort -b | python format-csharp-files.py + + # Tests files (if they exist) + if [ -d "./csharp/Platform.$REPOSITORY_NAME.Tests" ]; then + find "./csharp/Platform.$REPOSITORY_NAME.Tests" -type f -iname '*.cs' | sort -b | python format-csharp-files.py + fi +} + +# Function to process files for single-project +process_single_project_files() { + # Project files + find . -type f -iname '*.cs' | sort -b | python format-csharp-files.py +} + +# Function to output LaTeX header +output_latex_header() { + printf """ +\\documentclass[11pt,a4paper,fleqn]{report} +\\usepackage[left=5mm,top=5mm,right=5mm,bottom=5mm]{geometry} +\\textwidth=200mm +\\usepackage[utf8]{inputenc} +\\usepackage[T1]{fontenc} +\\usepackage[T2A]{fontenc} +\\usepackage{fvextra} +\\usepackage{minted} +\\usemintedstyle{vs} +\\usepackage{makeidx} +\\usepackage[columns=1]{idxlayout} +\\makeindex +\\renewcommand{\\thesection}{\\arabic{chapter}.\\arabic{section}} +\\setcounter{chapter}{1} +\\setcounter{section}{0} +\\usepackage[tiny]{titlesec} +\\titlespacing\\chapter{0mm}{0mm}{0mm} +\\titlespacing\\section{0mm}{0mm}{0mm} +\\DeclareUnicodeCharacter{221E}{\\ensuremath{\\infty}} +\\DeclareUnicodeCharacter{FFFD}{\\ensuremath{ }} +\\usepackage{fancyhdr} +\\pagestyle{fancy} +\\fancyhf{} +\\fancyfoot[C]{\\thepage} +\\renewcommand{\\headrulewidth}{0mm} +\\renewcommand{\\footrulewidth}{0mm} +\\renewcommand{\\baselinestretch}{0.7} +\\begin{document} +\\sf +\\noindent{\\Large LinksPlatform's Platform.${REPOSITORY_NAME} Class Library} +""" +} + +# Function to output LaTeX footer +output_latex_footer() { + printf """ +\\printindex +\\end{document} +""" +} + +# Ensure format-csharp-files.py exists +ensure_format_script() { + local script_path="" + if [ "$PROJECT_TYPE" = "multi" ] && [ -f "format-csharp-files.py" ]; then + script_path="format-csharp-files.py" + elif [ "$PROJECT_TYPE" = "single" ] && [ -f "format-csharp-files.py" ]; then + script_path="format-csharp-files.py" + elif [ -f "../Utils/format-csharp-files.py" ]; then + cp "../Utils/format-csharp-files.py" . + script_path="format-csharp-files.py" + elif [ -f "MultiProjectRepository/format-csharp-files.py" ]; then + cp "MultiProjectRepository/format-csharp-files.py" . + script_path="format-csharp-files.py" + elif [ -f "SingleProjectRepository/format-csharp-files.py" ]; then + cp "SingleProjectRepository/format-csharp-files.py" . + script_path="format-csharp-files.py" + else + echo "format-csharp-files.py not found. Please ensure it's available." + exit 1 + fi +} + +# Main execution +PROJECT_TYPE=$(detect_project_structure) + +echo "Detected project structure: $PROJECT_TYPE" + +case $PROJECT_TYPE in + "multi") + cleanup_multi_project + ;; + "single") + cleanup_single_project + ;; + "unknown") + echo "Could not detect project structure. Expected either:" + echo " Multi-project: ./csharp/Platform.\$REPOSITORY_NAME/ directory" + echo " Single-project: Platform.\$REPOSITORY_NAME.csproj file" + exit 1 + ;; +esac + +# Download fvextra package +wget https://raw.githubusercontent.com/gpoore/fvextra/cc1c0c5f7b92023cfec67084e2a87bdac520414c/fvextra/fvextra.sty + +# Ensure format script is available +ensure_format_script + +# Output LaTeX header +output_latex_header + +# Process files based on project type +case $PROJECT_TYPE in + "multi") + process_multi_project_files + ;; + "single") + process_single_project_files + ;; +esac + +# Output LaTeX footer +output_latex_footer \ No newline at end of file diff --git a/Combined/format-csharp-files.py b/Combined/format-csharp-files.py new file mode 100644 index 0000000..f751adf --- /dev/null +++ b/Combined/format-csharp-files.py @@ -0,0 +1,19 @@ +#!/usr/bin/python2 +# -*- coding: utf-8 -*- +import sys +reload(sys) +sys.setdefaultencoding('utf-8') +for line in sys.stdin.readlines(): + line = line.strip() + print("\\index{%s}" % (line.replace('_','\\_'))) + print("\\begin{section}{%s}" % (line.replace('_','\\_'))) + #print "\\inputminted[tabsize=2,breaklines,linenos=true]{csharp}{%s}" % (line) + print("\\begin{minted}[tabsize=2,breaklines,breakanywhere,linenos=true,xleftmargin=7mm,framesep=4mm]{csharp}") + f = open(line,"rt") + c = "\n".join([x.strip("\n") for x in f.readlines()]) + f.close() + c = c.replace(u'\ufeff','') + print(c) + print("\\end{minted}") + print("\\end{section}") + print("\n") diff --git a/Combined/generate-csharp-pdf.sh b/Combined/generate-csharp-pdf.sh new file mode 100755 index 0000000..9bc541d --- /dev/null +++ b/Combined/generate-csharp-pdf.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e # Exit with nonzero exit code if anything fails + +sudo apt-get update +sudo apt-get install -y texlive texlive-lang-cyrillic texlive-latex-extra python-pygments ghostscript + +# Generate tex file using the combined format script +bash format-csharp-document.sh > document.tex + +# Generate pdf +latex -shell-escape document.tex +makeindex document +latex -shell-escape document.tex +dvipdf document.dvi document.pdf +dvips document.dvi + +# Copy pdf to publish location (will be used in the next script) +mkdir -p _site +cp document.pdf "_site/Platform.$REPOSITORY_NAME.pdf" + +# Clean up +rm document.tex +rm document.dvi +rm document.pdf \ No newline at end of file diff --git a/Combined/publish-csharp-docs.sh b/Combined/publish-csharp-docs.sh new file mode 100755 index 0000000..6fd35fc --- /dev/null +++ b/Combined/publish-csharp-docs.sh @@ -0,0 +1,88 @@ +#!/bin/bash +set -e # Exit with nonzero exit code if anything fails + +sudo apt-get install nuget + +# Function to detect project structure +detect_project_structure() { + if [ -d "csharp" ] && [ -d "csharp/Platform.$REPOSITORY_NAME" ]; then + echo "multi" + elif [ -f "Platform.$REPOSITORY_NAME.csproj" ]; then + echo "single" + else + echo "unknown" + fi +} + +# Settings +TARGET_BRANCH="gh-pages" +SHA=$(git rev-parse --verify HEAD) +COMMIT_USER_NAME="linksplatform" +COMMIT_USER_EMAIL="linksplatformtechnologies@gmail.com" +REPOSITORY="github.com/linksplatform/$REPOSITORY_NAME" + +# Insert repository name into DocFX's configuration files +sed -i "s/\$REPOSITORY_NAME/$REPOSITORY_NAME/g" toc.yml +sed -i "s/\$REPOSITORY_NAME/$REPOSITORY_NAME/g" docfx.json + +# DocFX installation +PROJECT_TYPE=$(detect_project_structure) + +if [ "$PROJECT_TYPE" = "multi" ]; then + nuget install docfx.console -Version 2.51 +else + nuget install docfx.console +fi + +mono $(echo ./*docfx.console.*)/tools/docfx.exe docfx.json + +# Clone the existing gh-pages for this repo into out/ +# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deploy) +git clone "https://$REPOSITORY" out +cd out || exit +git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH +cd .. + +# Handle different project structures +if [ "$PROJECT_TYPE" = "multi" ]; then + mkdir -p out/csharp + # Clean out existing contents + rm -rf out/csharp/**/* || exit 0 + # Copy generated docs site + cp -r _site/* out/csharp/ + cd out/csharp || exit +else + # Clean out existing contents + rm -rf out/**/* || exit 0 + # Copy generated docs site + cp -r _site/* out + cd out || exit +fi + +# Do not use index.md +cp README.html index.html + +# Enter repository's folder (for multi-project, we're already in csharp subfolder) +if [ "$PROJECT_TYPE" = "multi" ]; then + cd .. +fi + +# Now let's go have some fun with the cloned repo +git config user.name "$COMMIT_USER_NAME" +git config user.email "$COMMIT_USER_EMAIL" +git remote rm origin +git remote add origin "https://linksplatform:$GITHUB_TOKEN@$REPOSITORY.git" + +# Commit the "changes", i.e. the new version. +# The delta will show diffs between new and old versions. +git add --all +git commit -m "Deploy to GitHub Pages: $SHA" + +# Now that we're all set up, we can push. +git push "https://linksplatform:$GITHUB_TOKEN@$REPOSITORY.git" "$TARGET_BRANCH" +cd .. + +# Clean up +rm -rf out +rm -rf _site +rm -rf docfx.console* \ No newline at end of file diff --git a/Combined/publish-csharp-release.sh b/Combined/publish-csharp-release.sh new file mode 100755 index 0000000..d4ac00e --- /dev/null +++ b/Combined/publish-csharp-release.sh @@ -0,0 +1,110 @@ +#!/bin/bash +set -e # Exit with nonzero exit code if anything fails + +# Function to detect project structure +detect_project_structure() { + if [ -f "CSHARP_PACKAGE_VERSION.txt" ] && [ -f "CSHARP_PACKAGE_RELEASE_NOTES.txt" ]; then + echo "multi" + elif [ -f "Platform.$REPOSITORY_NAME.csproj" ]; then + echo "single" + elif [ -d "csharp" ] && [ -f "csharp/Platform.$REPOSITORY_NAME/Platform.$REPOSITORY_NAME.csproj" ]; then + echo "multi" + else + echo "unknown" + fi +} + +# Function to get package info for multi-project structure +get_multi_project_info() { + if [ -f "CSHARP_PACKAGE_VERSION.txt" ]; then + PACKAGE_VERSION=$( CSHARP_PACKAGE_VERSION.txt +echo "Test release" > CSHARP_PACKAGE_RELEASE_NOTES.txt +result=$(detect_project_structure) +echo "Result: $result (expected: multi)" +cd .. + +# Test 2: Single-project +echo "=== Test 2: Single-project ===" +mkdir -p test2 +cd test2 +touch Platform.TestRepo.csproj +result=$(detect_project_structure) +echo "Result: $result (expected: single)" +cd .. + +# Test 3: Multi-project with csharp directory +echo "=== Test 3: Multi-project with csharp directory ===" +mkdir -p test3/csharp/Platform.TestRepo +cd test3 +touch csharp/Platform.TestRepo/Platform.TestRepo.csproj +result=$(detect_project_structure) +echo "Result: $result (expected: multi)" +cd .. + +# Test 4: Unknown structure +echo "=== Test 4: Unknown structure ===" +mkdir -p test4 +cd test4 +result=$(detect_project_structure) +echo "Result: $result (expected: unknown)" +cd .. + +# Clean up +rm -rf test1 test2 test3 test4 + +echo "=== All tests completed ===" \ No newline at end of file diff --git a/experiments/test_structure_detection.sh b/experiments/test_structure_detection.sh new file mode 100755 index 0000000..c031905 --- /dev/null +++ b/experiments/test_structure_detection.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Create test directory structure +mkdir -p experiments/test_multi/csharp/Platform.TestRepo +mkdir -p experiments/test_single + +# Test multi-project detection +cd experiments/test_multi +echo "1.0.0" > CSHARP_PACKAGE_VERSION.txt +echo "Test release notes" > CSHARP_PACKAGE_RELEASE_NOTES.txt +mkdir -p csharp/Platform.TestRepo +touch csharp/Platform.TestRepo/Platform.TestRepo.csproj + +# Extract detection function and test it +source ../../Combined/publish-csharp-release.sh +detect_result=$(detect_project_structure) +echo "Multi-project detection result: $detect_result" + +cd ../test_single +touch Platform.TestRepo.csproj + +# Test single-project detection +detect_result=$(detect_project_structure) +echo "Single-project detection result: $detect_result" + +cd ../.. + +# Clean up +rm -rf experiments/test_multi experiments/test_single \ No newline at end of file