Skip to content

Commit

Permalink
feat: conventional commits semantic release
Browse files Browse the repository at this point in the history
Feat/conventional commits semantic release
  • Loading branch information
brunobritodev authored Aug 12, 2021
2 parents 4222d38 + 10893f3 commit 07d1acc
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 10 deletions.
37 changes: 37 additions & 0 deletions .github/hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
#
# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
# To enable this hook, rename this file to "commit-msg".

# Uncomment the below to add a Signed-off-by line to the message.
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
# hook is more suited to it.
#
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

# This example catches duplicate Signed-off-by lines.

test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
echo >&2 Duplicate Signed-off-by lines.
exit 1
}
if ! head -1 "$1" | grep -qE "^(feat|fix|ci|chore|docs|test|style|refactor|chk)(\(.+?\))?: .{1,}$"; then
echo "Aborting commit. Your commit message is invalid. See some examples below:" >&2
echo "feat(logging): added logs for failed signups" >&2
echo "fix(homepage): fixed image gallery" >&2
echo "test(homepage): updated tests" >&2
echo "docs(readme): added new logging table information" >&2
echo "For more information check https://www.conventionalcommits.org/en/v1.0.0/ for more details" >&2
exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,50}$"; then
echo "Aborting commit. Your commit message is too long." >&2
exit 1
fi
51 changes: 51 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: NetDevPack Brasil - MASTER Deploy
on:
push:
branches: [ master ]
pull_request:
types: [closed]
branches: [ master ]

env:
REPOSITORY_URL: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
CURRENT_REPO_URL: https://github.com/${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test

- name: Semantic Release
id: semantic
uses: cycjimmy/semantic-release-action@v2
with:
semantic_version: 17.4.4
extra_plugins: |
@semantic-release/changelog
@semantic-release/github
@semantic-release/git
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Generate Package
run: dotnet pack -c Release -o out -p:PackageVersion=${{ steps.semantic.outputs.new_release_version }} -p:RepositoryUrl=${{env.CURRENT_REPO_URL}}

- name: Publish the package to nuget.org
run: dotnet nuget push ./out/*.nupkg --skip-duplicate --no-symbols true -k ${{ secrets.NUGET_AUTH_TOKEN}} -s https://api.nuget.org/v3/index.json
24 changes: 24 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: NetDevPack Brasil - MASTER PR
on:
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal
11 changes: 11 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"branches": ["master"],

"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github",
"@semantic-release/git"
]
}
6 changes: 3 additions & 3 deletions src/NetDevPack.Brasil/Documentos/CNPJ.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using NetDevPack.Brasil.Documentos.Validacao;
using NetDevPack.Domain;
using NetDevPack.Utilities;
using NetDevPack.Brasil.Documentos.Validacao;
using System;

namespace NetDevPack.Brasil.Documentos
{
Expand All @@ -12,7 +12,7 @@ public class Cnpj
public Cnpj(string numero)
{
Numero = numero.OnlyNumbers(numero);
if (!EstaValido()) throw new DomainException("CNPJ Inválido");
if (!EstaValido()) throw new DomainException("CNPJ Invalido");
}

public override string ToString() => SemMascara();
Expand Down
6 changes: 3 additions & 3 deletions src/NetDevPack.Brasil/Documentos/Cpf.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using NetDevPack.Brasil.Documentos.Validacao;
using NetDevPack.Domain;
using NetDevPack.Utilities;
using NetDevPack.Brasil.Documentos.Validacao;
using System;

namespace NetDevPack.Brasil.Documentos
{
Expand All @@ -12,7 +12,7 @@ public class Cpf
public Cpf(string numero)
{
Numero = numero.OnlyNumbers(numero);
if (!EstaValido()) throw new DomainException("CPF Inválido");
if (!EstaValido()) throw new DomainException("CPF Invalido");
}

public override string ToString() => SemMascara();
Expand Down
7 changes: 7 additions & 0 deletions src/NetDevPack.Brasil/NetDevPack.Brasil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@
</None>
</ItemGroup>

<Target Name="CopyHook" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Debug' ">
<ItemGroup>
<_CustomFiles Include="../../.github/hooks/commit-msg" />
</ItemGroup>
<Copy SourceFiles="@(_CustomFiles)" DestinationFolder="../../../.git/hooks" />
</Target>

</Project>
4 changes: 2 additions & 2 deletions tests/NetDevPack.Brasil.Tests/Documentos/CnpjValidadorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Cnpj_PossuiDigitosRepetidos_ShouldReturnDomainException(string value
Action act = () => new Cnpj(value);

// Assert
act.Should().ThrowExactly<DomainException>().WithMessage("CNPJ Inválido");
act.Should().ThrowExactly<DomainException>().WithMessage("CNPJ Invalido");
}

[Fact(DisplayName = "Cnpj ReturnTrue")]
Expand All @@ -38,7 +38,7 @@ public void Cnpj_NewCnpj_ShouldReturnNewCnpj()
var cnpj = new Cnpj("30.221.805/0001-26");

// Act
var result = new CnpjValidador(cnpj.Numero).EstaValido();
var result = new CnpjValidador(cnpj.Numero).EstaValido();

// Assert
result.Should().BeTrue();
Expand Down
4 changes: 2 additions & 2 deletions tests/NetDevPack.Brasil.Tests/Documentos/CpfValidadorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Cpf_PossuiDigitosRepetidos_ShouldReturnDomainException(string value)
Action act = () => new Cpf(value);

// Assert
act.Should().ThrowExactly<DomainException>().WithMessage("CPF Inválido");
act.Should().ThrowExactly<DomainException>().WithMessage("CPF Invalido");
}

[Fact(DisplayName = "Cpf ReturnTrue")]
Expand All @@ -38,7 +38,7 @@ public void Cpf_NewCpf_ShouldReturnNewCpf()
var cpf = new Cpf("915.212.540-87");

// Act
var result = new CpfValidador(cpf.Numero).EstaValido();
var result = new CpfValidador(cpf.Numero).EstaValido();

// Assert
result.Should().BeTrue();
Expand Down

0 comments on commit 07d1acc

Please sign in to comment.