Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Combined/README.md
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions Combined/docfx.json
Original file line number Diff line number Diff line change
@@ -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}" ]
}
}
151 changes: 151 additions & 0 deletions Combined/format-csharp-document.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Combined/format-csharp-files.py
Original file line number Diff line number Diff line change
@@ -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")
24 changes: 24 additions & 0 deletions Combined/generate-csharp-pdf.sh
Original file line number Diff line number Diff line change
@@ -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
88 changes: 88 additions & 0 deletions Combined/publish-csharp-docs.sh
Original file line number Diff line number Diff line change
@@ -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="[email protected]"
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*
Loading