Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Oct 6, 2020
2 parents efede14 + 2570965 commit 8ef716e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 44 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,7 @@ typings/
src/*.js
src/*.js.map
dist/

output/

coverage/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to **antlr-calculator** are documented here.

## v2.0.4:
- The internal check for null or empty formulas was changed for better compatibility with Node

## v2.0.3:
- Automatic creation of GitHub releases was added

Expand Down
15 changes: 5 additions & 10 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ pipeline {
label 'master'
}
}
environment {
KeyVaultBaseUrl = credentials('AzureCiKeyVaultBaseUrl')
KeyVaultClientId = credentials('AzureCiKeyVaultClientId')
KeyVaultClientSecret = credentials('AzureCiKeyVaultClientSecret')
}
stages {
stage ('Test') {
steps {
Expand All @@ -24,26 +29,16 @@ pipeline {
steps {
powershell './build.cmd Publish'
}

}
stage ('Deploy Demo') {
environment {
WebDeployPublishUrl = credentials('Danglserver3DeployEndpoint')
WebDeployUsername = credentials('Danglserver3WebDeployUsername')
WebDeployPassword = credentials('Danglserver3WebDeployPassword')
}
steps {
powershell './build.cmd DeployDemo'
}
}
stage ('Publish GitHub Release') {
environment {
GitHubAuthenticationToken = credentials('GeorgDanglGitHubAccessToken')
}
steps {
powershell './build.cmd PublishGitHubRelease'
}

}
}
post {
Expand Down
84 changes: 63 additions & 21 deletions build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Nuke.Common;
using Nuke.Common.Execution;
using Nuke.Common.Tools.GitVersion;
using Nuke.WebDeploy;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.Tools.Npm.NpmTasks;
using static Nuke.WebDeploy.WebDeployTasks;
using static Nuke.Common.ChangeLog.ChangelogTasks;
using static Nuke.Common.IO.TextTasks;
using static Nuke.GitHub.GitHubTasks;
Expand All @@ -13,6 +11,14 @@
using System;
using System.Linq;
using Nuke.Common.IO;
using System.IO.Compression;
using System.Text;
using System.Net.Http;
using Nuke.Common.Tools.AzureKeyVault.Attributes;
using Nuke.Common.Tools.AzureKeyVault;
using static Nuke.Common.Tools.Slack.SlackTasks;
using Nuke.Common.Tools.Slack;
using System.IO;

[UnsetVisualStudioEnvironmentVariables]
class Build : NukeBuild
Expand All @@ -31,12 +37,23 @@ class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository;

AbsolutePath ChangeLogFile => RootDirectory / "CHANGELOG.md";

[Parameter] string WebDeployUsername;
[Parameter] string WebDeployPassword;
[Parameter] string WebDeploySiteName = "AntlrCalculatorDemo";
[Parameter] string WebDeployPublishUrl;
[Parameter] string GitHubAuthenticationToken;
AbsolutePath OutputDirectory => RootDirectory / "output";

[KeyVaultSettings(
BaseUrlParameterName = nameof(KeyVaultBaseUrl),
ClientIdParameterName = nameof(KeyVaultClientId),
ClientSecretParameterName = nameof(KeyVaultClientSecret))]
readonly KeyVaultSettings KeyVaultSettings;
[Parameter] string KeyVaultBaseUrl;
[Parameter] string KeyVaultClientId;
[Parameter] string KeyVaultClientSecret;
[KeyVault] KeyVault KeyVault;

[KeyVaultSecret] string DanglCiCdSlackWebhookUrl;
[KeyVaultSecret("AntlrCalculatorDemo-WebDeployUsername")] string WebDeployUsername;
[KeyVaultSecret("AntlrCalculatorDemo-WebDeployPassword")] string WebDeployPassword;
[KeyVaultSecret] string GitHubAuthenticationToken;
[Parameter] string AppServiceName = "antlr-calculator-demo";

Target Clean => _ => _
.Executes(() =>
Expand All @@ -45,6 +62,7 @@ class Build : NukeBuild
DeleteDirectory(RootDirectory / "demo" / "dist");
DeleteDirectory(RootDirectory / "coverage");
DeleteFile(RootDirectory / "karma-results.xml");
EnsureCleanDirectory(OutputDirectory);
});

Target Test => _ => _
Expand Down Expand Up @@ -79,26 +97,50 @@ class Build : NukeBuild
.DependsOn(Clean)
.Requires(() => WebDeployUsername)
.Requires(() => WebDeployPassword)
.Requires(() => WebDeploySiteName)
.Requires(() => WebDeployPublishUrl)
.Executes(() =>
.Requires(() => AppServiceName)
.Requires(() => DanglCiCdSlackWebhookUrl)
.Executes(async () =>
{
Npm("ci", RootDirectory);
Npm("run build", RootDirectory);
CopyDirectoryRecursively(RootDirectory / "dist", RootDirectory / "demo" / "dist");
WriteAllText(RootDirectory / "demo" / "index.html", ReadAllText(RootDirectory / "demo" / "index.html")
.Replace("@@APP_VERSION@@", GitVersion.NuGetVersion));
WebDeploy(s => s
.SetSourcePath(RootDirectory / "demo")
.SetUsername(WebDeployUsername)
.SetPassword(WebDeployPassword)
.SetEnableAppOfflineRule(true)
.SetPublishUrl(WebDeployPublishUrl.TrimEnd('/') + "/msdeploy.axd?site=" + WebDeploySiteName)
.SetSiteName(WebDeploySiteName)
.SetEnableDoNotDeleteRule(false)
.SetRetryAttempts(5)
.SetWrapAppOffline(false));
var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{WebDeployUsername}:{WebDeployPassword}"));
ZipFile.CreateFromDirectory(RootDirectory / "demo", OutputDirectory / "deployment.zip");
using (var memStream = new MemoryStream(ReadAllBytes(OutputDirectory / "deployment.zip")))
{
memStream.Position = 0;
var content = new StreamContent(memStream);
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64Auth);
var requestUrl = $"https://{AppServiceName}.scm.azurewebsites.net/api/zipdeploy";
var response = await httpClient.PostAsync(requestUrl, content);
var responseString = await response.Content.ReadAsStringAsync();
Logger.Normal(responseString);
Logger.Normal("Deployment finished");
if (!response.IsSuccessStatusCode)
{
ControlFlow.Fail("Deployment returned status code: " + response.StatusCode);
}
else
{
await SendSlackMessageAsync(c => c
.SetUsername("Dangl CI Build")
.SetAttachments(new SlackMessageAttachment()
.SetText($"A new version was deployed for antlr-calculator")
.SetColor("good")
.SetFields(new[]
{
new SlackMessageField
()
.SetTitle("Version")
.SetValue(GitVersion.NuGetVersion)
})),
DanglCiCdSlackWebhookUrl);
}
}
});

Target PublishGitHubRelease => _ => _
Expand Down
5 changes: 2 additions & 3 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169</NoWarn>
<NukeRootDirectory>..</NukeRootDirectory>
Expand All @@ -11,9 +11,8 @@

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="0.24.11" />
<PackageReference Include="Nuke.WebDeploy" Version="1.3.0" />
<PackageDownload Include="GitVersion.Tool" Version="[5.1.3]" />
<PackageReference Include="Nuke.GitHub" Version="1.6.2-beta0004" />
<PackageReference Include="Nuke.GitHub" Version="1.6.2" />
</ItemGroup>

</Project>
16 changes: 6 additions & 10 deletions src/Calculator.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { CalculationResult } from './CalculationResult';
import { FormulaErrorListener } from './FormulaErrorListener';
import { FormulaVisitor } from './FormulaVisitor';
import { ANTLRInputStream, CommonTokenStream } from 'antlr4ts';

import { CalculationResult } from './CalculationResult';
import { CalculatorLexer } from './GeneratedAntlr/CalculatorLexer';
import { CalculatorParser } from './GeneratedAntlr/CalculatorParser';
import { ANTLRInputStream, CommonTokenStream } from 'antlr4ts';

// var antlr4 = require('antlr4');
// var calculatorLexer = require('./GeneratedAntlr/CalculatorLexer');
// var calculatorParser = require('./GeneratedAntlr/CalculatorParser');
// var formulaVisitor = require('./FormulaVisitor.js');
import { FormulaErrorListener } from './FormulaErrorListener';
import { FormulaVisitor } from './FormulaVisitor';

export class Calculator {
public static calculate(formula: string): CalculationResult {
var result = new CalculationResult();
if (formula === null || formula.match(/^\s*$/) !== null) {
if (formula == null || /^\s*$/.test(formula)) {
result.result = 0;
result.isValid = true;
return result;
Expand Down

0 comments on commit 8ef716e

Please sign in to comment.