diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..2f8654e --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,87 @@ +name: CI/CD Workflow + +env: + PRERELEASE_BRANCHES: '' # Comma separated list of prerelease branch names. 'alpha,rc, ...' + CASCADES: '' # Comma separated list of cascading repos. 'dolittle/DotNet.SDK,...' + NUGET_OUTPUT: Artifacts/NuGet + +on: + push: + branches: + - '**' + pull_request: + types: [closed] + +jobs: + context: + name: Establish Context + runs-on: ubuntu-latest + outputs: + version: ${{ steps.context.outputs.current-version }} + should-publish: ${{ steps.context.outputs.should-publish }} + release-type: ${{ steps.context.outputs.release-type }} + steps: + - uses: actions/checkout@v2 + - name: Establish context + id: context + uses: dolittle/establish-context-action@v2 + with: + prerelease-branches: ${{ env.PRERELEASE_BRANCHES }} + + dot-net-ci: + name: .NET CI + runs-on: ubuntu-latest + needs: context + + steps: + - uses: actions/checkout@v2 + - name: Setup .Net + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + - name: Build + run: dotnet build --configuration Release + + create-release: + name: Create GitHub Release + runs-on: ubuntu-latest + needs: [context, dot-net-ci] + + if: ${{ needs.context.outputs.should-publish == 'true' }} + + outputs: + version: ${{ steps.increment-version.outputs.next-version }} + + steps: + - uses: actions/checkout@v2 + - name: Increment version + id: increment-version + uses: dolittle/increment-version-action@v2 + with: + version: ${{ needs.context.outputs.version }} + release-type: ${{ needs.context.outputs.release-type }} + + - name: Create GitHub Release + uses: dolittle/github-release-action@v1 + with: + cascading-release: false + version: ${{ steps.increment-version.outputs.next-version }} + + dot-net-cd: + name: .NET CD + runs-on: ubuntu-latest + needs: [context, dot-net-ci, create-release] + + if: ${{ needs.context.outputs.should-publish == 'true' }} + + steps: + - uses: actions/checkout@v2 + - name: Setup .Net + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + - name: Create packages + run: dotnet pack --configuration Release -o ${{ env.NUGET_OUTPUT }} /p:PackageVersion=${{ needs.create-release.outputs.version }} -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg + + - name: Push NuGet packages + run: dotnet nuget push --skip-duplicate '${{ env.NUGET_OUTPUT }}/*.nupkg' --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8a90d30..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "Build"] - path = Build - url = https://github.com/dolittle-tools/DotNET.Build.git diff --git a/.vscode b/.vscode deleted file mode 120000 index 680d005..0000000 --- a/.vscode +++ /dev/null @@ -1 +0,0 @@ -./Build/.vscode \ No newline at end of file diff --git a/LICENSE b/LICENSE index bc29b33..1cd7eb6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,25 +1,21 @@ -Copyright (c) Dolittle, http://www.dolittle.com +MIT License -This software consists of voluntary contributions made by many -individuals (Authors.txt in the repository) For exact -contribution history, see the revision history and logs, available -at http://github.com/dolittle/DotNET.Core +Copyright (c) 2019 dolittle -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Protobuf.sln b/Protobuf.sln new file mode 100644 index 0000000..04fa071 --- /dev/null +++ b/Protobuf.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{B76DB529-B6EA-4128-98DF-8E23EBA06A9B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Protobuf.MSBuild", "Source\MSBuild\Protobuf.MSBuild.csproj", "{FB560E93-C095-4968-9E07-9E5DD67B9447}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Debug|x64.ActiveCfg = Debug|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Debug|x64.Build.0 = Debug|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Debug|x86.ActiveCfg = Debug|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Debug|x86.Build.0 = Debug|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Release|Any CPU.Build.0 = Release|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Release|x64.ActiveCfg = Release|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Release|x64.Build.0 = Release|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Release|x86.ActiveCfg = Release|Any CPU + {FB560E93-C095-4968-9E07-9E5DD67B9447}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {FB560E93-C095-4968-9E07-9E5DD67B9447} = {B76DB529-B6EA-4128-98DF-8E23EBA06A9B} + EndGlobalSection +EndGlobal diff --git a/Source/JavaScript/build.js b/Source/JavaScript/build.js new file mode 100755 index 0000000..4660644 --- /dev/null +++ b/Source/JavaScript/build.js @@ -0,0 +1,112 @@ +#!/usr/bin/env node + +let toolsPath = require.resolve('grpc-tools'); +let nodeModulesRoot = toolsPath.substr(0, toolsPath.indexOf('/grpc-tools')); + +console.log(`Using tooling from ${nodeModulesRoot}`); + +const path = require('path'); +const glob = require('glob'); +const del = require('del'); +const fs = require('fs'); + +const { exec, execSync } = require('child_process'); + +if (process.argv.length < 4) { + console.log('Usage:\n') + console.log('dolittle_proto_build grpc-node|grpc-web -I[include path] [source path(s)]') + console.log('\n'); + console.log('The ordering of the arguments is important.') + console.log('You can have more than one include path, just add multiple `-I` options.'); + process.exit(0); + return; +} + +console.log('Delete existing declaration files'); +del('./*.d.ts', '**/*.d.ts', '!node_modules/**/*', 'lib'); + +let args = ''; +if (process.argv[2] == 'grpc-web') { + args = `--plugin=protoc-gen-grpc-web=${path.join(__dirname, './grpc-web/macOS/protoc-gen-grpc-web')} `; + args += '--grpc-web_out=import_style=commonjs,mode=grpcwebtext:. ' +} else { + args = `--plugin=protoc-gen-grpc=$nodemodules'/.bin/grpc_tools_node_protoc_plugin' `; + args += `--grpc_out=./ `; +} +let subFolder = process.argv[3]; +let hasSubFolder = subFolder !== '.'; + +let patterns = ['*.proto', '**/*.proto']; +let ignorePatterns = ['', '*.proto']; + +const getAllFiles = function (dirPath, containing, arrayOfFiles) { + files = fs.readdirSync(dirPath) + + arrayOfFiles = arrayOfFiles || [] + + if (dirPath.indexOf('node_modules') < 0) { + + files.forEach(function (file) { + + if (fs.statSync(dirPath + "/" + file).isDirectory()) { + arrayOfFiles = getAllFiles(dirPath + "/" + file, containing, arrayOfFiles) + } else { + if (file.indexOf(containing) >= 0 || containing == '') { + arrayOfFiles.push(path.join(dirPath, file)); + } + } + }); + } + + + return arrayOfFiles +} + +for (var i = 3; i < process.argv.length; i++) { + let arg = process.argv[i]; + if (arg.indexOf('-') == 0) { + args += `${arg} `; + continue; + } + + let folder = path.join(process.cwd(), arg); + patterns.forEach((pattern, patternIndex) => { + let files = glob.sync(pattern, { + cwd: folder, + ignore: ignorePatterns[patternIndex] + }); + if (files.length > 0) { + args += `${path.join(arg, pattern)} `; + } + }); +} + +console.log(`Looking for .proto files in '${args.trim()}'`); + +process.env.nodemodules = nodeModulesRoot; + +let scriptPath = path.join(__dirname, `generate_proxies.sh`); +scriptPath = `${scriptPath} ${args.trim()}`; +console.log(`Generate ${scriptPath}`) +const generate = exec(`${scriptPath}`, (error, stdout, stderr) => { + console.log(stdout); + console.log(stderr); + + if (error == null) { + console.log('Transpile any TypeScript files'); + execSync(`npx tsc --declaration false`, { stdio: 'inherit' }); + + if (process.argv[2] == 'grpc-web') { + console.log('Rename for web') + + console.log(process.cwd()); + + const allFiles = getAllFiles(process.cwd(), 'grpc_pb.d.ts'); + allFiles.forEach(_ => fs.renameSync(_, _.replace('grpc_pb','grpc_web_pb'))); + } + + console.log('Copy declaration files to lib') + execSync(`find . -name '*.d.ts' -not -path './node_modules/*' -not -path './lib/*' | cpio -pdm ./lib`, { stdio: 'inherit' }); + } +}); + diff --git a/Source/JavaScript/generate_proxies.sh b/Source/JavaScript/generate_proxies.sh new file mode 100755 index 0000000..9cf4fde --- /dev/null +++ b/Source/JavaScript/generate_proxies.sh @@ -0,0 +1,11 @@ +#!/bin/bash +echo "Generate Proxies" +find . -type f -iname '*.ts' ! -iname "index.*" -not -path './node_modules/*' -delete +find . -type f -iname '*.js' ! -iname "index.*" -not -path './node_modules/*' -delete + +echo $* + +npx protoc --js_out=import_style=commonjs,binary:./ \ + --ts_out=service=grpc-node:./ \ + --plugin=protoc-gen-ts=$nodemodules'/.bin/protoc-gen-ts' \ + $* \ No newline at end of file diff --git a/Source/JavaScript/grpc-web/macOS/protoc-gen-grpc-web b/Source/JavaScript/grpc-web/macOS/protoc-gen-grpc-web new file mode 100755 index 0000000..f4fbd91 Binary files /dev/null and b/Source/JavaScript/grpc-web/macOS/protoc-gen-grpc-web differ diff --git a/Source/JavaScript/package.json b/Source/JavaScript/package.json new file mode 100644 index 0000000..592f8f2 --- /dev/null +++ b/Source/JavaScript/package.json @@ -0,0 +1,33 @@ +{ + "name": "@dolittle/protobuf.build", + "version": "1.1.2", + "description": "", + "publishConfig": { + "access": "public" + }, + "bin": { + "dolittle_proto_build": "./build.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/dolittle-tools/JavaScript.Protobuf.git" + }, + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/dolittle-tools/JavaScript.Protobuf/issues" + }, + "homepage": "https://github.com/dolittle-tools/JavaScript.Protobuf#readme", + "dependencies": { + "@types/google-protobuf": "^3.7.2", + "@types/node": "^13.13.5", + "del-cli": "^3.0.0", + "glob": "^7.1.6", + "grpc": "^1.24.2", + "grpc-tools": "^1.8.1", + "grpc-web": "^1.0.7", + "ts-protoc-gen": "^0.12.0", + "typescript": "^3.8.3" + }, + "devDependencies": {} +} diff --git a/Source/MSBuild/Dolittle.Protobuf.MSBuild.props b/Source/MSBuild/Dolittle.Protobuf.MSBuild.props new file mode 100644 index 0000000..3381616 --- /dev/null +++ b/Source/MSBuild/Dolittle.Protobuf.MSBuild.props @@ -0,0 +1,6 @@ + + + NotSet + ../ + + \ No newline at end of file diff --git a/Source/MSBuild/Dolittle.Protobuf.MSBuild.targets b/Source/MSBuild/Dolittle.Protobuf.MSBuild.targets new file mode 100644 index 0000000..00cb476 --- /dev/null +++ b/Source/MSBuild/Dolittle.Protobuf.MSBuild.targets @@ -0,0 +1,25 @@ + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + True + true + + + + + + + + + + + + + + + + diff --git a/Source/MSBuild/Protobuf.MSBuild.csproj b/Source/MSBuild/Protobuf.MSBuild.csproj new file mode 100644 index 0000000..eea12c7 --- /dev/null +++ b/Source/MSBuild/Protobuf.MSBuild.csproj @@ -0,0 +1,30 @@ + + + + + netstandard2.0 + Dolittle.Protobuf.MSBuild + true + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Source/MSBuild/README.md b/Source/MSBuild/README.md new file mode 100644 index 0000000..6c647e3 --- /dev/null +++ b/Source/MSBuild/README.md @@ -0,0 +1,22 @@ +# Protobuf MSBuild Suppport + +This package is meant to make it more consistent for projects that generate code (proxies) +from `.proto` definitions. + +By just adding a reference to this package, you'll get all the tooling set up correctly + +The system is preconfigured, but you need to provide the path to where the main folder that +holds the `.proto` files. In addition, you can override the root for include files. +This is set to default `../`. + +```xml + + ../[your folder] + ../ + +``` + +## Upgrading Grpc.Tools + +If one wants to change the version of the `Grpc.Tools` reference in the `.csproj`. It is vital +to also update the `Dolittle.Protobuf.MSBuild.targets` file to use the same version. \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 6b124be..0000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,12 +0,0 @@ -trigger: -- master - -resources: - repositories: - - repository: templates - type: github - name: dolittle-tools/AzureDevOps - endpoint: dolittle-tools - -jobs: -- template: Source/DotNet/framework.yml@templates diff --git a/default.props b/default.props new file mode 100644 index 0000000..b83a925 --- /dev/null +++ b/default.props @@ -0,0 +1,11 @@ + + + + + netstandard2.1 + + + + + + \ No newline at end of file diff --git a/specs.props b/specs.props new file mode 100644 index 0000000..a4ca827 --- /dev/null +++ b/specs.props @@ -0,0 +1,15 @@ + + + + + netcoreapp3.1 + true + + + + + + + + + \ No newline at end of file diff --git a/versions.props b/versions.props new file mode 100644 index 0000000..cb8845a --- /dev/null +++ b/versions.props @@ -0,0 +1,4 @@ + + + + \ No newline at end of file