Skip to content

Commit

Permalink
OPL-12294: Preparing for package publish. (#9)
Browse files Browse the repository at this point in the history
Preparing for package publish
* Refactor existing workflows to one file. 
* Inspired https://www.meziantou.net/publishing-a-nuget-package-following-best-practices-using-github.htm
  • Loading branch information
jakubsemerak committed Mar 6, 2024
1 parent 6529246 commit 15cb9a0
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 81 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# src: https://www.meziantou.net/publishing-a-nuget-package-following-best-practices-using-github.htm

name: publish
on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
push:
branches:
- 'main' # Run the workflow when pushing to the main branch
pull_request:
branches:
- '*' # Run the workflow for all pull requests
release:
types:
- published # Run the workflow when a new GitHub release is published

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget

defaults:
run:
shell: pwsh

jobs:
create-nuget:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4

# Create the NuGet package in the folder from the environment variable NuGetDirectory
- run: dotnet pack dotnet/UneceGenerator --configuration Release --output ${{ env.NuGetDirectory }}

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg

validate-nuget:
runs-on: ubuntu-latest
needs: [ create-nuget ]
steps:
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4

# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Install nuget validator
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global

# Validate metadata and content of the NuGet package
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate package
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg") --excluded-rules Symbols --excluded-rule-ids 52

dotnet-tests:
uses: ./.github/workflows/dotnet-tests.yml
with:
working-directory: "dotnet/UneceGenerator"

python-tests:
uses: ./.github/workflows/python-tests.yml
with:
working-directory: "python"

deploy:
# Publish only when creating a GitHub Release
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [ validate-nuget, dotnet-tests, python-tests ]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
with:
name: nuget
path: ${{ env.NuGetDirectory }}

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET Core
uses: actions/setup-dotnet@v4

# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet package
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
}
16 changes: 9 additions & 7 deletions .github/workflows/dotnet-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ on:
required: true
type: string

dotnet-version:
required: true
configuration:
required: false
default: "Release"
type: string


jobs:
dotnet-tests:
runs-on: "ubuntu-latest"
name: Run .NET tests
steps:
- uses: actions/checkout@v4
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ inputs.dotnet-version }}
uses: actions/setup-dotnet@v4

- name: Build whole solution
working-directory: ${{ inputs.working-directory }}
run: |
dotnet build
dotnet build --configuration ${{ inputs.configuration }}
- name: Test with dotnet test
working-directory: ${{ inputs.working-directory }}
run: |
dotnet test --no-restore
dotnet test --no-restore --configuration ${{ inputs.configuration }}
16 changes: 0 additions & 16 deletions .github/workflows/pull.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/push.yml

This file was deleted.

32 changes: 7 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,18 @@

Units library supporting UNECE rec. 20 and rec. 21 standards

# Development
# Content

- developed on python `3.12.0`
- mainly using `pint` library for linking units
- in the project root folder:
- `cd python`
- create virtual environment `python -m venv venv`
- activate virtual environment, for example on windows run `.\venv\Scripts\Activate.ps1`
- run `pip install -e src/unece_excel_parser` to install dependencies & fix imports
- run `pip install -e src/unece_excel_parser[dev]` to install dev dependencies (for running tests)
- (optional) set python interpreter in dev IDE to point to python.exe in venv folder
This repository contains two main tools:

## Run

From `python/src/unece_excel_parser` folder run:

`python .\unece_excel_parser.py -rec20 files/rec20_Rev17e-2021.xlsx -rec21 files/rec21_Rev12e_Annex-V-VI_2021.xls`
* python UNECE Excel parser that parses input XLXS file into pre-processed JSON output. See
unece_excel_parser's [README](python/src/unece_excel_parser/README.md).
* UNECE units dotnet tools that uses pre-processed JSON to create c# classes for working with UNECE units that are
packed into a NuGet package.

# References

UNECE standards are located on https://unece.org/trade/uncefact/cl-recommendations. Basic description of the UNECE
standard is located on https://unece.org/sites/default/files/2023-10/Rec20_Rev6e_2009.pdf.

Also the Excel files and the PDF explaining the data in the standard are located in the `python/src/files` folder.

# Known issues

The `pint` library does reduce the units and this could cause some unexpected
behaviour where units get reduced, see https://github.com/hgrecco/pint/issues/551. For example `N * m / m` is reduced
to `N`.

The input excel for rec. 20 standard contains a lot of bugs, inconsistencies and typos and we are trying to correct
them, but it could be not perfect.
Also the Excel files and the PDF explaining the data in the standard are located in the `python/src/files` folder.
8 changes: 8 additions & 0 deletions dotnet/UneceGenerator/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
9 changes: 9 additions & 0 deletions dotnet/UneceGenerator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# UNECE units dotnet tools

This solution consists of two projects:

- [UneceGenerator](UneceGenerator/README.md) which can be used to re-generate the C# classes based on
the `parsedUneceUnits.json` file created by the
python [unece_excel_parser](../../python/src/unece_excel_parser/README.md) tool.
- [UneceUnits](UneceUnits/README.md) final output project with generated C# classes which is published as a NuGet
package.
4 changes: 1 addition & 3 deletions dotnet/UneceGenerator/UneceGenerator/UneceGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>UneceUnits</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/UneceGenerator/UneceUnits/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unece Units

Unece Units generated structures for working with UNECE rec. 20 and rec. 21 standards.
UNECE Units generated structures for working with UNECE rec. 20 and rec. 21 standards.

Rec. 21 units have common code prefixed with an "X" to avoid possible conflicts with rec. 20 units.

Expand Down
33 changes: 29 additions & 4 deletions dotnet/UneceGenerator/UneceUnits/UneceUnits.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>UneceUnits</Title>
<PackageId>UneceUnits</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/quadient/unece-units</PackageProjectUrl>
<Copyright>https://www.quadient.com</Copyright>
<RepositoryUrl>https://github.com/quadient/unece-units</RepositoryUrl>
<Authors>Quadient, jakubsemerak, yardee</Authors>
<PackageTags>UNECE; units; rec. 20; rec.21</PackageTags>
<Description>
UNECE Units generated structures for working with UNECE rec. 20 and rec. 21 standards.
</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>https://github.com/quadient/unece-units/releases/</PackageReleaseNotes>

<!-- Generate XML documentation -->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS0618,CS1591</NoWarn>
<PackageIcon>quadient.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\UneceUnits.Contract\UneceUnits.Contract.csproj" />
<ProjectReference Include="..\UneceUnits.Contract\UneceUnits.Contract.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="MinVer" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath=""/>
<None Include="quadient.png" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>
Binary file added dotnet/UneceGenerator/UneceUnits/quadient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions dotnet/UneceGenerator/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"rollForward": "feature",
"version": "8.0.200"
}
}
24 changes: 24 additions & 0 deletions python/src/unece_excel_parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# UNECE units python pre-processing tool

Python based UNECE Excel Parser that parses input UNECE XLXS file into pre-processed JSON output.

This JSON can then used as input to re-generate dotnet UNECE units classes in
the [dotnet UneceGenerator](../../../dotnet/UneceGenerator/README.md).

# Development

- developed using python `3.12.0`
- mainly using `pint` library for linking units
- in the project root folder:
- `cd python`
- create virtual environment `python -m venv venv`
- activate virtual environment, for example on windows run `.\venv\Scripts\Activate.ps1`
- run `pip install -e src/unece_excel_parser` to install dependencies & fix imports
- run `pip install -e src/unece_excel_parser[dev]` to install dev dependencies (for running tests)
- (optional) set python interpreter in dev IDE to point to python.exe in venv folder

## Run

From `python/src/unece_excel_parser` folder run:

`python .\unece_excel_parser.py -rec20 files/rec20_Rev17e-2021.xlsx -rec21 files/rec21_Rev12e_Annex-V-VI_2021.xls`

0 comments on commit 15cb9a0

Please sign in to comment.