Skip to content

Commit

Permalink
Merge pull request ScottPlot#2254 from ScottPlot/2022-11-10c
Browse files Browse the repository at this point in the history
SP5 cookbook: build and deploy using CI system
  • Loading branch information
swharden authored Nov 11, 2022
2 parents 6ad1d7d + ef0d968 commit a7c16a7
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 24 deletions.
33 changes: 23 additions & 10 deletions .github/workflows/cookbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ on:
paths:
- "src/ScottPlot5/ScottPlot5 Cookbook/**"

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: true

jobs:
publish:
runs-on: ubuntu-latest
name: Cookbook
runs-on: ubuntu-latest
environment:
name: Cookbook
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: 🛒 Checkout
uses: actions/checkout@v2
Expand All @@ -26,12 +38,13 @@ jobs:
run: dotnet build "src/ScottPlot5/ScottPlot5 Cookbook" --no-restore
- name: 🧑‍🍳 Generate Cookbook
run: dotnet test "src/ScottPlot5/ScottPlot5 Cookbook" --no-restore --verbosity minimal
- name: 🔑 Install SSH Key
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.PRIVATE_SSH_KEY }}" > ~/.ssh/id_rsa
echo "${{ secrets.KNOWN_HOSTS }}" > ~/.ssh/known_hosts
- name: 🚀 Deploy
run: rsync --archive --stats -e 'ssh -p 18765' 'src/ScottPlot5/ScottPlot5 Cookbook/bin/Debug/net6.0/cookbook-output' ${{ secrets.REMOTE_DEST_COOKBOOK50 }} # [email protected]:/scottplot.net/public_html/cookbook/5.0/
- name: 🧹 Purge Cache
run: curl --user deploy:${{ secrets.PURGE_PASSWORD }} https://scottplot.net/admin/purge/

- name: 🛠️ Configure Pages
uses: actions/configure-pages@v2
- name: 📦 Upload Artifact
uses: actions/upload-pages-artifact@v1
with:
path: "./dev/www"
- name: 🚀 Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/www
src/ScottPlot4/ScottPlot.Cookbook/CookbookOutput

## Ignore Visual Studio temporary files, build results, and
Expand Down
40 changes: 40 additions & 0 deletions dev/www/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ScottPlot Developer Website</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<style>
a {
text-decoration: none;
}

a:hover {
text-decoration: underline;
}
</style>
</head>

<body>
<main class="container my-5">
<h1 class="my-4">ScottPlot Developer Website</h1>
<div class="fs-5">
<ul>
<li class="my-4">
<a href='cookbook/5.0'>ScottPlot 5.0 Cookbook</a> - Automatically deployed cookbook that
demonstrates features available in the latest commit to the main branch of ScottPlot's source code
on GitHub. Features may be present that are not yet available in ScottPlot on NuGet.
</li>
<li class="my-4">
<a href='https://scottplot.net/cookbook/4.1/'>ScottPlot 4.1 Cookbook</a> - Manually deployed
cookbook that demonstrates features available in the latest version of ScottPlot available on NuGet.
</li>
</ul>
</div>
</main>
</body>

</html>
24 changes: 22 additions & 2 deletions src/ScottPlot5/ScottPlot5 Cookbook/Cookbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,28 @@ namespace ScottPlotCookbook;
/// </summary>
public static class Cookbook
{
public static readonly string OutputFolder =
Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, "cookbook-output"));
public static readonly string OutputFolder = GetCookbookFolder();

private static string GetCookbookFolder()
{
string defaultFolder = Path.GetFullPath(TestContext.CurrentContext.TestDirectory);
string cookbookOutputSubFolder = "dev/www/cookbook/5.0";

string? repoFolder = defaultFolder;
while (repoFolder is not null)
{
if (File.Exists(Path.Combine(repoFolder, "LICENSE")))
{
return Path.Combine(repoFolder, cookbookOutputSubFolder);
}
else
{
repoFolder = Path.GetDirectoryName(repoFolder);
}
}

return Path.Combine(defaultFolder, cookbookOutputSubFolder);
}

internal static List<Chapter> GetChapters() => Enum.GetValues<Chapter>().ToList();

Expand Down
4 changes: 2 additions & 2 deletions src/ScottPlot5/ScottPlot5 Cookbook/HtmlPages/HtmlFrontPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void Generate()
chapter.Pages.ForEach(x => AddPage(x));
}

Save(HtmlPageGenerator.OutputFolder, "ScottPlot 5.0 Cookbook");
Save(HtmlPageGenerator.OutputFolder, "ScottPlot 5.0 Cookbook", localFile: true);
Save(Cookbook.OutputFolder, "ScottPlot 5.0 Cookbook");
Save(Cookbook.OutputFolder, "ScottPlot 5.0 Cookbook", localFile: true);
}

private void AddPage(PageInfo page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

internal class HtmlPageGenerator
{
public static readonly string OutputFolder =
Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, "cookbook-output"));

[Test]
public void Generate_Cookbook_Pages()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Generate()
SB.AppendLine($"<a href='{recipe.ImageFilename}'><img src='{recipe.ImageFilename}' /></a>");
}

string outputFolder = Path.Combine(HtmlPageGenerator.OutputFolder, Page.FolderUrl);
string outputFolder = Path.Combine(Cookbook.OutputFolder, Page.FolderUrl);
Save(outputFolder, $"{Page.Name} - ScottPlot 5.0 Cookbook");
}
}
2 changes: 1 addition & 1 deletion src/ScottPlot5/ScottPlot5 Cookbook/RecipeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private RecipePageBase GetPage()
public void SaveRecipeImage()
{
string fileUrl = UrlTools.GetImageUrl(GetPage(), this);
string saveAs = Path.Combine(HtmlPageGenerator.OutputFolder, fileUrl);
string saveAs = Path.Combine(Cookbook.OutputFolder, fileUrl);
MyPlot.SavePng(saveAs, Width, Height);
TestContext.WriteLine($"{saveAs}");
}
Expand Down
10 changes: 5 additions & 5 deletions src/ScottPlot5/ScottPlot5 Cookbook/SetupAndTeardown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ internal class SetupAndTeardown
public void RunBeforeAnyTests()
{
// delete all old cookbook content
if (Directory.Exists(HtmlPageGenerator.OutputFolder))
Directory.Delete(HtmlPageGenerator.OutputFolder, true);
if (Directory.Exists(Cookbook.OutputFolder))
Directory.Delete(Cookbook.OutputFolder, true);

// create a fresh cookbook folder
Directory.CreateDirectory(HtmlPageGenerator.OutputFolder);
Directory.CreateDirectory(Cookbook.OutputFolder);

// create subfolders for every page
foreach (RecipePageBase page in Cookbook.GetPages())
{
string pageFolder = Path.Combine(HtmlPageGenerator.OutputFolder, UrlTools.GetPageUrl(page));
string pageFolder = Path.Combine(Cookbook.OutputFolder, UrlTools.GetPageUrl(page));
Directory.CreateDirectory(pageFolder);
}
}

[OneTimeTearDown]
public void RunAfterAnyTests()
public void RunAfterAllTests()
{

}
Expand Down

0 comments on commit a7c16a7

Please sign in to comment.