Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add files #1

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
7 changes: 7 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>cognitedata/renovate-config",
":automergeMinor"
]
}
37 changes: 37 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: .NET build and test

on:
pull_request:
branches: [ main ]

jobs:
common:
uses: ./.github/workflows/common.yml
secrets: inherit

build-installer:
runs-on: ubuntu-latest
needs:
- common
steps:
- run: echo "Yep, the installer is built"

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal /p:Exclude="[*.Test]*" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=TestResults/

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
86 changes: 86 additions & 0 deletions .github/workflows/build-installer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Release connector

on:
push:
branches: [ main ]

jobs:
common:
uses: ./.github/workflows/common.yml
secrets: inherit

publish-installer:
runs-on: windows-latest
environment: CD
if: ${{ needs.common.outputs.should-release == 0 }}
needs:
- common
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- name: Install markdown-pdf
run: npm install -g [email protected]

- name: Convert Markdown to PDF
run: markdown-pdf Documentation.md

- name: download-artifact
uses: actions/download-artifact@v4
with:
name: windows artifacts
path: ./

- name: create release
uses: actions/create-release@v1
id: github-release
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ needs.common.outputs.version }}
release_name: DWSIM Connector ${{ needs.common.outputs.version }}

draft: false
prerelease: true

- name: upload release msi
uses: actions/upload-release-asset@v1
id: github-release-msi
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.github-release.outputs.upload_url }}
asset_path: .\DwsimConnectorInstaller-${{needs.common.outputs.version }}.msi
asset_name: DwsimConnectorInstaller-${{ needs.common.outputs.version }}.msi
asset_content_type: application/octet-stream

- name: upload release binary
uses: actions/upload-release-asset@v1
id: github-release-binary
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.github-release.outputs.upload_url }}
asset_path: .\Service.exe
asset_name: Service.exe
asset_content_type: application/octet-stream

- name: Install publisher
shell: bash
run: pip install cognite-extractor-publisher --extra-index-url "https://${{ secrets.ARTIFACTORY_READONLY_TOKEN_USER }}:${{ secrets.ARTIFACTORY_READONLY_TOKEN }}@cognite.jfrog.io/cognite/api/pypi/snakepit/simple"

- name: publish connector
env:
EXTRACTOR_DOWNLOAD_API_ADMIN_SECRET: ${{ secrets.EXTRACTOR_DOWNLOAD_ADMIN_SECRET }}
run: publish-extractor publish --manifest manifest.yml --version ${{ needs.common.outputs.version }}
130 changes: 130 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Build and test connector

on:
workflow_call:
outputs:
version:
description: Release version
value: ${{ jobs.prerequisites.outputs.version }}
should-release:
description: Checks if release would occur
value: ${{ jobs.prerequisites.outputs.should-release }}
branch:
description: Branch
value: ${{ jobs.prerequisites.outputs.branch }}
secrets:
ARTIFACTORY_READONLY_TOKEN:
required: true
ARTIFACTORY_READONLY_TOKEN_USER:
required: true

jobs:
prerequisites:
runs-on: ubuntu-latest
outputs:
should-release: ${{ steps.confirm-release.outputs.test }}
branch: ${{ steps.current-branch.outputs.branch }}
version: ${{ steps.get-version.outputs.version }}
steps:
- name: checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: update pip
run: pip install --upgrade pip

- name: install shyaml
run: pip install shyaml

- name: get-version
id: get-version
run: echo "version=$(cat manifest.yml | shyaml keys-0 versions | xargs -0 | cut -d\ -f1)" >> "$GITHUB_OUTPUT"

- name: debug-version
run: echo ${{ steps.get-version.outputs.version }}

- name: confirm release
id: confirm-release
run: echo "test=$(git tag --list '${{ steps.get-version.outputs.version }}' | wc -l | sed s/\ //g)" >> $GITHUB_OUTPUT

- name: Get branch name
id: current-branch
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_OUTPUT"

- name: Message about build
uses: actions/github-script@v7
with:
script: |
if (${{ steps.confirm-release.outputs.test }} == 0) {
core.notice('Will release version ${{ steps.get-version.outputs.version }}...')
} else {
core.warning('Will not create release for version ${{ steps.get-version.outputs.version }} because it already exists.')
}

build-installer:
runs-on: windows-latest
environment: ${{ needs.prerequisites.outputs.branch == 'main' && 'CD' || 'CI' }}
needs:
- prerequisites
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x

- name: Restore tools
run: dotnet tool restore

- name: Add msbuild to path
uses: microsoft/[email protected]

- name: Build and Publish Service binary
working-directory: .\Service
run: dotnet publish -c Release -r win-x64 --no-self-contained -p:PublishSingleFile=true -p:Version=${{ needs.prerequisites.outputs.version }} -p:InformationalVersion="${{ needs.prerequisites.outputs.version }}" -p:DebugType=none -p:DebugSymbols=false -o ./bin/portable
shell: bash

- name: Sign service binary
if: ${{ needs.prerequisites.outputs.branch == 'main' }}
env:
CERTIFICATE_HOST: ${{ secrets.CODE_SIGNING_CERT_HOST }}
CERTIFICATE_HOST_API_KEY: ${{ secrets.CODE_SIGNING_CERT_HOST_API_KEY }}
CERTIFICATE_SHA1_HASH: ${{ secrets.CODE_SIGNING_CERT_SHA1_HASH }}
CLIENT_CERTIFICATE: ${{ secrets.CODE_SIGNING_CLIENT_CERT }}
CLIENT_CERTIFICATE_PASSWORD: ${{ secrets.CODE_SIGNING_CLIENT_CERT_PASSWORD }}
KEYPAIR_ALIAS: ${{ secrets.CODE_SIGNING_KEYPAIR_ALIAS }}
uses: cognitedata/code-sign-action/@v3
with:
path-to-binary: .\Service\bin\portable\Service.exe

- name: Build Installer
working-directory: .\Installer
run: .\build.ps1 -b msbuild -v ${{ needs.prerequisites.outputs.version }} -d "DWSIM connector Installer" -c .\setup-config.json
shell: powershell

- name: Sign Installer
if: ${{ needs.prerequisites.outputs.branch == 'main' }}
env:
CERTIFICATE_HOST: ${{ secrets.CODE_SIGNING_CERT_HOST }}
CERTIFICATE_HOST_API_KEY: ${{ secrets.CODE_SIGNING_CERT_HOST_API_KEY }}
CERTIFICATE_SHA1_HASH: ${{ secrets.CODE_SIGNING_CERT_SHA1_HASH }}
CLIENT_CERTIFICATE: ${{ secrets.CODE_SIGNING_CLIENT_CERT }}
CLIENT_CERTIFICATE_PASSWORD: ${{ secrets.CODE_SIGNING_CLIENT_CERT_PASSWORD }}
KEYPAIR_ALIAS: ${{ secrets.CODE_SIGNING_KEYPAIR_ALIAS }}
uses: cognitedata/code-sign-action/@v3
with:
path-to-binary: '.\Installer\bin\Release\DwsimConnectorInstaller-${{ needs.prerequisites.outputs.version }}.msi'

- run: mkdir .\uploads
- run: mv .\Installer\bin\Release\DwsimConnectorInstaller-${{ needs.prerequisites.outputs.version }}.msi .\uploads\DwsimConnectorInstaller-${{ needs.prerequisites.outputs.version }}.msi
- run: mv .\Service\bin\portable\Service.exe .\uploads\Service.exe
- name: upload artifact
if: ${{ needs.prerequisites.outputs.branch == 'main' && needs.prerequisites.outputs.should-release == 0 }}
uses: actions/upload-artifact@v4
with:
name: windows artifacts
path: .\uploads\
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*/obj/*
*/bin/*
config.yml
.envrc
.env
.DS_Store
files/*
logs/*
*.db
.vscode/*
configurations/*
.vs/*
*/buildoutput/*
Service/configurations/*
Service/files/*
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@cognitedata/simulator-integration
30 changes: 30 additions & 0 deletions Connector/Connector.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<!-- You may want to uncomment this to debug locally -->
<!-- <PlatformTarget>x64</PlatformTarget>
<Configuration>Debug</Configuration> -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cognite.Simulator.Utils" Version="1.0.0-alpha-054" />
</ItemGroup>

<!-- Uncomment below to use libraries built locally -->
<!-- <ItemGroup>
<PackageReference Include="Cognite.ExtractorUtils" Version="1.18.0" />
<PackageReference Include="Cognite.Extensions" Version="1.18.0" />
<ProjectReference Include="..\..\dotnet-extractor-utils\ExtractorUtils\ExtractorUtils.csproj" />
<ProjectReference Include="..\..\dotnet-extractor-utils\Cognite.Extensions\Cognite.Extensions.csproj" />
</ItemGroup> -->
<!-- <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<ProjectReference Include="..\..\dotnet-simulator-utils\Cognite.DataProcessing\Cognite.DataProcessing.csproj" />
<ProjectReference Include="..\..\dotnet-simulator-utils\Cognite.Simulator.Extensions\Cognite.Simulator.Extensions.csproj" />
<ProjectReference Include="..\..\dotnet-simulator-utils\Cognite.Simulator.Utils\Cognite.Simulator.Utils.csproj" />
</ItemGroup> -->
</Project>
45 changes: 45 additions & 0 deletions Connector/ConnectorRuntime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2024 Cognite AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Cognite.Simulator.Utils;
using CogniteSdk.Alpha;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Connector;
public static class ConnectorRuntime {

public static void Init() {
DefaultConnectorRuntime<DwsimAutomationConfig, DefaultModelFilestate, DefaultModelFileStatePoco>.ConfigureServices = ConfigureServices;
DefaultConnectorRuntime<DwsimAutomationConfig, DefaultModelFilestate, DefaultModelFileStatePoco>.ConnectorName = "DWSIM";
DefaultConnectorRuntime<DwsimAutomationConfig, DefaultModelFilestate, DefaultModelFileStatePoco>.SimulatorDefinition = SimulatorDefinition.Get();
}
static void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ISimulatorClient<DefaultModelFilestate, SimulatorRoutineRevision>, DwsimClient>();
}

public static async Task RunStandalone() {
Init();
await DefaultConnectorRuntime<DwsimAutomationConfig, DefaultModelFilestate, DefaultModelFileStatePoco>.RunStandalone().ConfigureAwait(false);
}

public static async Task Run(ILogger defaultLogger, CancellationToken token) {
Init();
await DefaultConnectorRuntime<DwsimAutomationConfig, DefaultModelFilestate, DefaultModelFileStatePoco>.Run(defaultLogger, token).ConfigureAwait(false);
}
}

29 changes: 29 additions & 0 deletions Connector/Dwsim/AutomationConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright 2024 Cognite AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Cognite.Simulator.Utils.Automation;

namespace Connector;

public class DwsimAutomationConfig : AutomationConfig
{
public string DwsimInstallationPath { get; set; }

public DwsimAutomationConfig()

Check warning on line 25 in Connector/Dwsim/AutomationConfig.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'DwsimInstallationPath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 25 in Connector/Dwsim/AutomationConfig.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Non-nullable property 'DwsimInstallationPath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 25 in Connector/Dwsim/AutomationConfig.cs

View workflow job for this annotation

GitHub Actions / common / build-installer

Non-nullable property 'DwsimInstallationPath' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
{
ProgramId = "DWSIM.Automation.Automation3";
}
}
Loading
Loading