Skip to content

Commit 86bd049

Browse files
committed
Simplify Jenkinsfile, support new assets, add version-stamp
1 parent a699d58 commit 86bd049

File tree

5 files changed

+19
-68
lines changed

5 files changed

+19
-68
lines changed

Helpers/Runtime/ConfigurationHelper.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

Startup.cs

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System;
2-
using Microsoft.AspNetCore;
32
using Microsoft.AspNetCore.Hosting;
43
using Microsoft.AspNetCore.Builder;
5-
using Microsoft.AspNetCore.StaticFiles;
64
using Microsoft.Extensions.Logging;
75
using Microsoft.Extensions.Configuration;
86
using Microsoft.Extensions.DependencyInjection;
@@ -11,7 +9,6 @@
119
using Microsoft.AspNetCore.Http;
1210
using System.Threading.Tasks;
1311
using JNCC.Microsite.SAC.Helpers;
14-
using JNCC.Microsite.SAC.Helpers.Runtime;
1512

1613
namespace JNCC.Microsite.SAC
1714
{
@@ -36,55 +33,19 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
3633
{
3734
// Webserver Root is at <root>/output/html
3835
Console.WriteLine("Webserver root is {0}", env.WebRootPath);
39-
// Static files Root is at <root>/docs/[images|styles|frontend]
36+
37+
// Static files Root is at <root>/docs
4038
string staticFilesRoot = FileHelper.GetActualFilePath(env.WebRootPath, Path.Combine("..", "..", "docs"));
4139
Console.WriteLine("Static files root is {0}", staticFilesRoot);
4240

4341
app.UseDefaultFiles()
4442
.UseStaticFiles()
4543
.UseRequestInterceptorMiddleware();
4644

47-
try
48-
{
49-
app.UseStaticFiles(new StaticFileOptions
50-
{
51-
FileProvider = new PhysicalFileProvider(FileHelper.GetActualFilePath(staticFilesRoot, "images")),
52-
RequestPath = "/images"
53-
});
54-
}
55-
catch (DirectoryNotFoundException)
56-
{
57-
58-
throw new DirectoryNotFoundException("Images folder not fouind in <root>/docs. The static images folder must be placed in the <output root>/docs folder before the site can be generated");
59-
}
60-
61-
try
62-
{
63-
app.UseStaticFiles(new StaticFileOptions
64-
{
65-
FileProvider = new PhysicalFileProvider(FileHelper.GetActualFilePath(staticFilesRoot, "frontend")),
66-
RequestPath = "/frontend"
67-
});
68-
}
69-
catch (DirectoryNotFoundException)
70-
{
71-
72-
throw new DirectoryNotFoundException("Frontend folder not found in <root>/docs. The static frontend folder must be placed in the <output root>/docs folder before the site can be generated");
73-
}
74-
75-
try
45+
app.UseStaticFiles(new StaticFileOptions
7646
{
77-
app.UseStaticFiles(new StaticFileOptions
78-
{
79-
FileProvider = new PhysicalFileProvider(FileHelper.GetActualFilePath(staticFilesRoot, "styles")),
80-
RequestPath = "/styles"
81-
});
82-
}
83-
catch (DirectoryNotFoundException)
84-
{
85-
86-
throw new DirectoryNotFoundException("Styles folder not found in <root>/docs. The styles folder must be placed in the <output root>/docs folder before the site can be generated");
87-
}
47+
FileProvider = new PhysicalFileProvider(staticFilesRoot)
48+
});
8849
}
8950
}
9051

Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!DOCTYPE html>
33
<html lang="en">
44
<head>
5+
<meta name="x-version" content="x-version-stamp">
56
@if (! String.IsNullOrEmpty(Model.GeneratorConfig.GoogleAnalyticsId))
67
{
78
<!-- Global site tag (gtag.js) - Google Analytics -->
@@ -42,6 +43,7 @@
4243
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.5.0/js/foundation.min.js"></script>
4344
<script src="/frontend/js/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
4445
<script src="/frontend/js/app.js"></script>
46+
<script src="/scripts/cookie-consent.js"></script>
4547
</head>
4648
<body>
4749
@if (! String.IsNullOrEmpty(Model.GeneratorConfig.GoogleTagMangerId))

deployment/jenkins/deploy-to-live.jenkinsfile

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ pipeline {
2525
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
2626
sh 'git clone https://github.com/jncc/sac-microsite.git . --branch=gh-pages --depth 1'
2727
sh 'git config --local credential.helper "!p() { echo username=\\$GIT_USERNAME; echo password=\\$GIT_PASSWORD; }; p"'
28-
sh 'rm -r ./site/*'
29-
sh 'rm -r ./species/*'
30-
sh 'rm -r ./habitat/*'
31-
sh 'rm -r ./images/*'
32-
sh 'rm -r ./styles/*'
33-
sh 'rm -r ./frontend/*'
28+
sh 'git rm -rf .'
29+
sh 'git clean -fxd'
3430
sh 'cp -r ../master/output/html/* .'
35-
sh 'cp -r ../master/docs/images/* ./images/'
36-
sh 'cp -r ../master/docs/styles/* ./styles/'
37-
sh 'cp -r ../master/docs/frontend/* ./frontend/'
31+
sh 'cp -r ../master/docs/* .'
32+
// Github Pages custom domain configured with a file called 'CNAME'
33+
sh 'echo "sac.jncc.gov.uk" > CNAME'
34+
// add the version stamp (replace the string 'x-version-stamp' in all .html files)
35+
sh 'sed -i "s/x-version-stamp/' + env.BUILD_NUMBER + '.' + env.GIT_COMMIT + '/g" *.html'
36+
sh 'ls -a'
3837
sh 'git add --all'
39-
sh 'git commit -a -m "Jenkins Build ' + env.BUILD_NUMBER + '" --author "Jenkins <jenkins@jncc.gov.uk>" || echo \'Commit failed. There is probably nothing to commit.\''
40-
sh 'git push --force || echo \'Push failed. There is probably nothing to commit.\''
38+
sh 'git commit -a -m "Jenkins Build ' + env.BUILD_NUMBER + '" --author "Jenkins <jenkins@jncc.gov.uk>"'
39+
sh 'git push --force'
4140
}
4241
}
4342
}

docs/scripts/cookie-consent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
// console.log('hello');

0 commit comments

Comments
 (0)