initial commit
Some checks failed
Rename the project from template / rename-project (push) Has been skipped
SonarQube Scan / SonarQube Trigger (push) Has been skipped
CI / linter (9.0.X, ubuntu-latest) (push) Failing after 54s
CI / tests_linux (9.0.X, ubuntu-latest) (push) Has been skipped

This commit is contained in:
Simon Diesenreiter 2024-11-27 20:44:34 +01:00
commit bbfabb2eee
25 changed files with 659 additions and 0 deletions

View File

@ -0,0 +1,15 @@
### Summary :memo:
_Write an overview about it._
### Details
_Describe more what you did on changes._
1. (...)
2. (...)
### Bugfixes :bug: (delete if dind't have any)
-
### Checks
- [ ] Closed #798
- [ ] Tested Changes
- [ ] Stakeholder Approval

3
.gitea/release_message.sh Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
previous_tag=$(git tag --sort=-creatordate | sed -n 2p)
git shortlog "${previous_tag}.." | sed 's/^./ &/'

40
.gitea/rename_project.sh Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env bash
while getopts a:n:u:d: flag
do
case "${flag}" in
a) author=${OPTARG};;
n) name=${OPTARG};;
u) urlname=${OPTARG};;
d) description=${OPTARG};;
esac
done
echo "Author: $author";
echo "Project Name: $name";
echo "Project URL name: $urlname";
echo "Description: $description";
echo "Renaming project..."
original_author="author_name"
original_name="project_name"
original_urlname="project_urlname"
original_description="project_description"
# for filename in $(find . -name "*.*")
for filename in $(git ls-files)
do
sed -i "s/$original_author/$author/g" $filename
sed -i "s/$original_name/$name/g" $filename
sed -i "s/$original_urlname/$urlname/g" $filename
sed -i "s/$original_description/$description/g" $filename
echo "Renamed $filename"
done
mv project_name $name
mv project_name.Tests $name.Tests
mv project_name.sln $name.sln
mv $name/project_name.csproj $name/$name.csproj
mv $name.Tests/project_name.Tests.csproj $name.Tests/$name.Tests.csproj
# This command runs only once on GHA!
rm -rf .gitea/template.yml

1
.gitea/template.yml Normal file
View File

@ -0,0 +1 @@
author: rochacbruno

84
.gitea/workflows/main.yml Normal file
View File

@ -0,0 +1,84 @@
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
linter:
strategy:
fail-fast: false
matrix:
dotnet-version: [9.0.X]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Run linter
run: make lint
tests_linux:
needs: linter
strategy:
fail-fast: false
matrix:
dotnet-version: [9.0.X]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Run tests
run: make test
# tests_mac:
# needs: linter
# strategy:
# fail-fast: false
# matrix:
# dotnet-version: [9.0.X]
# os: [macos-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-dotnet@v4
# with:
# dotnet-version: ${{ matrix.dotnet-version }}
# - name: Install project
# run: make install
# - name: Run tests
# run: make test
# tests_win:
# needs: linter
# strategy:
# fail-fast: false
# matrix:
# dotnet-version: [9.0.X]
# os: [windows-latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-dotnet@v4
# with:
# dotnet-version: ${{ matrix.dotnet-version }}
# - name: Install Pip
# run: pip install --user --upgrade pip
# - name: Install project
# run: pip install -e .[test]
# - name: run tests
# run: pytest -s -vvvv -l --tb=long tests

View File

@ -0,0 +1,65 @@
name: Upload Python Package
permissions:
contents: write
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
# by default, it uses a depth of 1
# this fetches all history so that we can read each commit
fetch-depth: 0
- name: Generate Changelog
run: .gitea/release_message.sh > release_message.md
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: release_message.md
deploy:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Check version match
run: |
REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_'')
if [ "$(cat $REPOSITORY_NAME/VERSION)" = "${GITHUB_REF_NAME:1}" ] ; then
echo "Version matches successfully!"
else
echo "Version must match!"
exit -1
fi
- name: Build and publish
env:
GITEA_USERNAME: gitearobot
GITEA_PASSWORD: ${{ secrets.PACKAGE_GITEA_PAT }}
run: |
REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $1}')
REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_'')
dotnet nuget add source --name gitea --username $GITEA_USERNAME --password $GITEA_PASSWORD https://git.disi.dev/api/packages/$REPOSITORY_OWNER/nuget/index.json
dotnet pack --include-symbols --include-source -p:PackageVersion=$(cat $REPOSITORY_NAME/VERSION) project_name.sln
dotnet nuget push --source gitea $REPOSITORY_NAME/bin/Release/$REPOSITORY_NAME.$(cat $REPOSITORY_NAME/VERSION).nupkg
dotnet nuget push --source gitea $REPOSITORY_NAME/bin/Release/$REPOSITORY_NAME.$(cat $REPOSITORY_NAME/VERSION).symbols.nupkg

View File

@ -0,0 +1,49 @@
name: Rename the project from template
on: [push]
permissions: write-all
jobs:
rename-project:
if: ${{ !endsWith (gitea.repository, 'Templates/Dotnet_Library') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# by default, it uses a depth of 1
# this fetches all history so that we can read each commit
fetch-depth: 0
ref: ${{ gitea.head_ref }}
- run: echo "REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_')" >> $GITHUB_ENV
shell: bash
- run: echo "REPOSITORY_URLNAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}')" >> $GITHUB_ENV
shell: bash
- run: echo "REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $1}')" >> $GITHUB_ENV
shell: bash
- name: Is this still a template
id: is_template
run: echo "::set-output name=is_template::$(ls .gitea/template.yml &> /dev/null && echo true || echo false)"
- name: Rename the project
if: steps.is_template.outputs.is_template == 'true'
run: |
echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}"
.gitea/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n ${{ env.REPOSITORY_NAME }} -u ${{ env.REPOSITORY_URLNAME }} -d "Awesome ${{ env.REPOSITORY_NAME }} created by ${{ env.REPOSITORY_OWNER }}"
- name: Remove renaming workflow
if: steps.is_template.outputs.is_template == 'true'
run: |
rm .gitea/template.yml
rm .gitea/workflows/rename_project.yml
rm .gitea/rename_project.sh
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "✅ Ready to clone and code."
# commit_options: '--amend --no-edit'
push_options: --force

View File

@ -0,0 +1,27 @@
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
name: SonarQube Scan
jobs:
sonarqube:
name: SonarQube Trigger
runs-on: ubuntu-latest
if: ${{ !contains ('project_name', format('{0}_{1}', 'project', 'name')) }}
steps:
- name: Checking out
uses: actions/checkout@v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
with:
args: >
-Dsonar.projectKey=project_name

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
**/bin
**/obj

95
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,95 @@
# How to develop on this project
project_name welcomes contributions from the community.
**You need Dotnet 9!**
This instructions are for linux base systems. (Linux, MacOS, BSD, etc.)
## Setting up your own fork of this repo.
- On gitea interface click on `Fork` button.
- Clone your fork of this repo. `git clone git@git.disi.dev:YOUR_GIT_USERNAME/project_urlname.git`
- Enter the directory `cd project_urlname`
- Add upstream repo `git remote add upstream https://git.disi.dev/author_name/project_urlname`
## Run the tests to ensure everything is working
Run `make test` to run the tests.
## Create a new branch to work on your contribution
Run `git checkout -b my_contribution`
## Make your changes
Edit the files using your preferred editor. (we recommend VIM or VSCode)
## Format the code
Run `make fmt` to format the code.
## Lint the code
Run `make lint` to lint the code.
## Test your changes
Run `make test` to run the tests.
Ensure code coverage report shows `100%` coverage, add tests to your PR.
## Build the docs locally
Run `make docs` to build the docs.
Ensure your new changes are documented.
## Commit your changes
This project uses [conventional git commit messages](https://www.conventionalcommits.org/en/v1.0.0/).
Example: `fix(package): update setup.py arguments 🎉` (emojis are fine too)
## Push your changes to your fork
Run `git push origin my_contribution`
## Submit a pull request
On gitea interface, click on `Pull Request` button.
Wait CI to run and one of the developers will review your PR.
## Makefile utilities
This project comes with a `Makefile` that contains a number of useful utility.
```bash
make
Usage: make <target>
Targets:
help: ## Show the help.
fmt: ## Format code using black & isort.
test: lint ## Run tests and generate coverage report.
clean: ## Clean unused files.
release: ## Create a new tag for release.
docs: ## Build the documentation.
```
## Making a new release
This project uses [semantic versioning](https://semver.org/) and tags releases with `X.Y.Z`
Every time a new tag is created and pushed to the remote repo, gitea actions will
automatically create a new release on gitea.
To trigger a new release all you need to do is.
1. If you have changes to add to the repo
* Make your changes following the steps described above.
* Commit your changes following the [conventional git commit messages](https://www.conventionalcommits.org/en/v1.0.0/).
2. Run the tests to ensure everything is working.
4. Run `make release` to create a new tag and push it to the remote repo.
the `make release` will ask you the version number to create the tag, ex: type `0.1.1` when you are asked.
> **CAUTION**: The make release will change local changelog files and commit all the unstaged changes you have.

4
Containerfile Normal file
View File

@ -0,0 +1,4 @@
FROM mcr.microsoft.com/dotnet/runtime:9.0
COPY ./project_name/bin/Release/net9.0/ /app
WORKDIR /app
CMD ["project_name"]

13
HISTORY.md Normal file
View File

@ -0,0 +1,13 @@
Changelog
=========
0.1.2 (2021-08-14)
------------------
- Fix release, README and windows CI. [Bruno Rocha]
- Release: version 0.1.0. [Bruno Rocha]
0.1.0 (2021-08-14)
------------------
- Add release command. [Bruno Rocha]

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
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 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.
For more information, please refer to <https://unlicense.org>

5
MANIFEST.in Normal file
View File

@ -0,0 +1,5 @@
include LICENSE
include HISTORY.md
include Containerfile
graft tests
graft project_name

58
Makefile Normal file
View File

@ -0,0 +1,58 @@
.PHONY: help
help: ## Show the help.
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@fgrep "##" Makefile | fgrep -v fgrep
.PHONY: buildrel
buildrel: ## Format code.
dotnet build -c Release project_name.sln
.PHONY: build
build: ## Format code.
dotnet build project_name.sln
.PHONY: publish
publish: ## Format code.
dotnet publish -c Release project_name.sln
.PHONY: fmt
fmt: ## Format code.
dotnet format project_name.sln
.PHONY: lint
lint: ## Lint code.
dotnet format --verify-no-changes --verbosity diagnostic project_name.sln
.PHONY: test
test: ## Run tests and generate coverage report.
dotnet test project_name.sln
.PHONY: clean
clean: ## Clean unused files.
dotnet clean project_name.sln
.PHONY: release
release: ## Create a new tag for release.
@echo "WARNING: This operation will create a version tag and push to gitea"
@read -p "Version? (provide the next x.y.z semver) : " TAG
@echo "$${TAG}" > project_name/VERSION
@$(ENV_PREFIX)gitchangelog > HISTORY.md
@git add project_name/VERSION HISTORY.md
@git commit -m "release: version $${TAG} 🚀"
@echo "creating git tag : $${TAG}"
@git tag $${TAG}
@git push -u origin HEAD --tags
@echo "Gitea Actions will detect the new tag and release the new version."
.PHONY: docs
docs: ## Build the documentation.
@echo "building documentation ..."
@$(ENV_PREFIX)mkdocs build
URL="site/index.html"; xdg-open $$URL || sensible-browser $$URL || x-www-browser $$URL || gnome-open $$URL || open $$URL
# This project has been generated from rochacbruno/python-project-template
# __author__ = 'rochacbruno'
# __repo__ = https://github.com/rochacbruno/python-project-template
# __sponsor__ = https://github.com/sponsors/rochacbruno/

46
README.md Normal file
View File

@ -0,0 +1,46 @@
# Dotnet Project Template
A low dependency and really simple to start project template for Python Projects.
See also
- [Dotnet-Executable-Template](https://git.disi.dev/Templates/Dotnet_Executable/) for a library template.
### HOW TO USE THIS TEMPLATE
1. Create a new repository from this template and choose a name for your project
(e.g. `my_awesome_project` - recommendation is to use underscores separation for repo names.)
2. Wait until the first run of CI finishes (Gitea Actions will process the template and commit to your new repo)
3. Read the file [CONTRIBUTING.md](CONTRIBUTING.md)
4. Then clone your new project and happy coding!
> **NOTE**: **WAIT** until first CI run on gitea actions before cloning your new project.
### What is included on this template?
- 🖼️ Templates for starting multiple application types:
**Run `make init` after cloning to generate a new project based on a template.**
- 🤖 A [Makefile](Makefile) with the most useful commands to install, test, lint, format and release your project.
- 📃 Documentation structure using [mkdocs](http://www.mkdocs.org)
- 💬 Auto generation of change log using **gitchangelog** to keep a HISTORY.md file automatically based on your commit history on every release.
- 🐋 A simple [Containerfile](Containerfile) to build a container image for your project.
`Containerfile` is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file.
- 🧪 Testing structure
- ✅ Code linting
- 🎯 Entry points to execute your program with basic CLI argument parsing.
- 🔄 Continuous integration using [Gitea Actions](.gitea/workflows/) with jobs to lint, test and release your project on Linux, Mac and Windows environments.
<!-- DELETE THE LINES ABOVE THIS AND WRITE YOUR PROJECT README BELOW -->
---
# project_name
project_description
## Usage
TODO: dotnet sample code on usage
## Development
Read the [CONTRIBUTING.md](CONTRIBUTING.md) file.

17
docs/index.md Normal file
View File

@ -0,0 +1,17 @@
# Welcome to MkDocs
For full documentation visit [mkdocs.org](https://www.mkdocs.org).
## Commands
* `mkdocs new [dir-name]` - Create a new project.
* `mkdocs serve` - Start the live-reloading docs server.
* `mkdocs build` - Build the documentation site.
* `mkdocs -h` - Print help message and exit.
## Project layout
mkdocs.yml # The configuration file.
docs/
index.md # The documentation homepage.
... # Other markdown pages, images and other files.

2
mkdocs.yml Normal file
View File

@ -0,0 +1,2 @@
site_name: project_name
theme: readthedocs

11
nuget.config Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="gitea-projects" value="https://git.disi.dev/api/packages/Projects/nuget/index.json" />
<add key="gitea-homelab" value="https://git.disi.dev/api/packages/Homelab/nuget/index.json" />
<add key="gitea-artifacts" value="https://git.disi.dev/api/packages/Artifacts/nuget/index.json" />
</packageSources>
</configuration>

View File

@ -0,0 +1,14 @@
namespace project_name.Tests;
using project_name;
public class UnitTest1
{
[Fact]
public void Test1()
{
var hwp = new HelloWorldProvider();
Assert.Equal("Hello, Simon!", hwp.GetHelloWorld("Simon"));
Assert.Equal("Hello world!", hwp.GetHelloWorld());
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../project_name/project_name.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
</Project>

32
project_name.sln Normal file
View File

@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "project_name", "project_name\project_name.csproj", "{5AF6E15A-7BFC-49EB-AC97-A2AA1B131608}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "project_name.Tests", "project_name.Tests\project_name.Tests.csproj", "{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B25F5E39-D0A6-4548-A3B6-428275AB154D}.Release|Any CPU.Build.0 = Release|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD1B8A2E-3BA7-4FDD-96FB-18551A15A5F3}.Release|Any CPU.Build.0 = Release|Any CPU
{5AF6E15A-7BFC-49EB-AC97-A2AA1B131608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5AF6E15A-7BFC-49EB-AC97-A2AA1B131608}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AF6E15A-7BFC-49EB-AC97-A2AA1B131608}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AF6E15A-7BFC-49EB-AC97-A2AA1B131608}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,16 @@
namespace project_name;
public class HelloWorldProvider
{
public string GetHelloWorld(string name = null)
{
if(string.IsNullOrEmpty(name))
{
return "Hello world!";
}
else
{
return $"Hello, {name}!";
}
}
}

1
project_name/VERSION Normal file
View File

@ -0,0 +1 @@
0.1.0

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>