Skip to content

Commit

Permalink
feat: add github flows
Browse files Browse the repository at this point in the history
  • Loading branch information
lpcouto committed Feb 2, 2024
1 parent 9e677bc commit 38abc69
Show file tree
Hide file tree
Showing 29 changed files with 237 additions and 17 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Test

on:
pull_request:

push:
branches: [ main ]

jobs:
build-test:

runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: GITHUB CONTEXT
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- name: Commit Lint
uses: wagoid/commitlint-github-action@master
with:
failOnWarnings: true

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

- name: Build Framework
run: |
dotnet build LoadShedding.sln -c Release
- name: UnitTests
run: |
dotnet test LoadShedding.sln --filter Category=Unit -c Release --logger "console;verbosity=detailed"
- name: IntegrationTests
run: |
dotnet test LoadShedding.sln --filter Category=Integration -c Release --logger "console;verbosity=detailed"
89 changes: 89 additions & 0 deletions .github/workflows/metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Monthly Metrics
on:
workflow_dispatch:
inputs:
dates:
required: false
schedule:
- cron: '3 2 1 * *'

permissions:
issues: write
pull-requests: read

jobs:
run:
name: Calculate Metrics
runs-on: ubuntu-latest
steps:

- name: Get dates for last month
id: get-dates
shell: bash
run: |
# Calculate the first day of the previous month
first_day=$(date -d "last month" +%Y-%m-01)
# Calculate the last day of the previous month
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
#Set an environment variable with the date range
echo "$first_day..$last_day"
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
- name: Use input dates
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dates != '' }}
shell: bash
run: |
echo "${{github.event.inputs.dates}}"
echo "last_month=${{github.event.inputs.dates}}" >> "$GITHUB_ENV"
- name: Run issue-metrics tool for items opened last month
id: opened-metrics
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:farfetch/loadshedding created:${{ env.last_month }} -reason:"not planned"'

- name: Upload for opened items
uses: actions/upload-artifact@v3
with:
name: items-opened
path: ./issue_metrics.md

- name: Run issue-metrics tool for items closed last month
id: closed-metrics
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:farfetch/loadshedding closed:${{ env.last_month }} -reason:"not planned"'

- name: Upload for closed items
uses: actions/upload-artifact@v3
with:
name: items-closed
path: ./issue_metrics.md

- name: Run issue-metrics tool for discussions opened last month
id: opened-discussions-metrics
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:farfetch/loadshedding type:discussions created:${{ env.last_month }} -reason:"not planned"'

- name: Upload for opened discussions
uses: actions/upload-artifact@v3
with:
name: discussions-opened
path: ./issue_metrics.md

- name: Run issue-metrics tool for discussions closed last month
id: closed-discussions-metrics
uses: github/issue-metrics@v2
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SEARCH_QUERY: 'repo:farfetch/loadshedding type:discussions closed:${{ env.last_month }} -reason:"not planned"'

- name: Upload for closed discussions
uses: actions/upload-artifact@v3
with:
name: discussions-closed
path: ./issue_metrics.md
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish

on:
release:
types: [ published ]

jobs:
release:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

- name: Pack
run: dotnet pack ./LoadShedding.sln -c Release /p:Version=${{ github.event.release.tag_name }} -o ./drop

- name: Publish
run: dotnet nuget push ./drop/**/*.nupkg -k ${{ secrets.NUGET_PUBLISH_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate

- name: Print Version
run: echo ${{ github.event.release.tag_name }}
33 changes: 33 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project>
<PropertyGroup>
<LangVersion>10.0</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Authors>Farfetch</Authors>
<Company>Farfetch</Company>
<Product>LoadShedding</Product>
<PackageProjectUrl>https://github.com/Farfetch/loadshedding</PackageProjectUrl>
<RepositoryUrl>https://github.com/Farfetch/loadshedding</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<license>https://github.com/Farfetch/loadshedding/blob/master/LICENSE</license>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIconUrl>https://raw.githubusercontent.com/Farfetch/.github/master/images/fuse-logo-128.png</PackageIconUrl>
<PackageTags>loadshedding</PackageTags>
<CodeAnalysisRuleSet>$([MSBuild]::GetPathOfFileAbove('StyleCopAnalyzersDefault.ruleset'))</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="$([MSBuild]::GetPathOfFileAbove('stylecop.json'))" Link="stylecop.json" />
</ItemGroup>

</Project>
File renamed without changes.
2 changes: 1 addition & 1 deletion deploy/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RUN for file in $(ls *.csproj); do mkdir -p tests/unit-tests/${file%.*}/ && mv $
# 1.3 Integration tests
COPY tests/integration-tests/Farfetch.LoadShedding.IntegrationTests/Farfetch.LoadShedding.IntegrationTests.csproj tests/integration-tests/Farfetch.LoadShedding.IntegrationTests/Farfetch.LoadShedding.IntegrationTests.csproj

# 1.4 Perfornance tests
# 1.4 Performance tests
COPY tests/performance-tests/Farfetch.LoadShedding.PerformanceTests/Farfetch.LoadShedding.PerformanceTests.csproj tests/performance-tests/Farfetch.LoadShedding.PerformanceTests/Farfetch.LoadShedding.PerformanceTests.csproj

# 1.5 - Restore nuget packages
Expand Down
2 changes: 2 additions & 0 deletions src/Farfetch.LoadShedding/Farfetch.LoadShedding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>LoadShedding</PackageId>
<Description>LoadShedding main package</Description>
</PropertyGroup>

<ItemGroup>
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../src'))" />

<ItemGroup>
<Compile Include="$(MSBuildProjectDirectory)/../Traits.cs" Link="Properties/Traits.cs"/>
<AdditionalFiles Include="..\..\..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<ProjectReference Include="..\..\..\src\Farfetch.LoadShedding\Farfetch.LoadShedding.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Remove="$(MSBuildProjectDirectory)/../Traits.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Net;
using Farfetch.LoadShedding.AspNetCore.Options;
using Farfetch.LoadShedding.Configurations;
Expand Down
3 changes: 3 additions & 0 deletions tests/integration-tests/Traits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xunit;

[assembly: AssemblyTrait("Category", "Integration")]
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
</None>
</ItemGroup>

<ItemGroup>
<Compile Remove="$(MSBuildProjectDirectory)/../Traits.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.AspNetCore.Configurators;
using Farfetch.LoadShedding.AspNetCore.Configurators;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.AspNetCore.Middlewares;
using Farfetch.LoadShedding.AspNetCore.Middlewares;
using Farfetch.LoadShedding.AspNetCore.Options;
using Farfetch.LoadShedding.Exceptions;
using Farfetch.LoadShedding.Limiters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.AspNetCore.Resolvers;
using Farfetch.LoadShedding.AspNetCore.Resolvers;
using Farfetch.LoadShedding.Tasks;
using Microsoft.AspNetCore.Http;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.AspNetCore.Attributes;
using Farfetch.LoadShedding.AspNetCore.Attributes;
using Farfetch.LoadShedding.AspNetCore.Resolvers;
using Farfetch.LoadShedding.Tasks;
using Microsoft.AspNetCore.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.AspNetCore.Resolvers;
using Farfetch.LoadShedding.AspNetCore.Resolvers;
using Farfetch.LoadShedding.Tasks;
using Microsoft.AspNetCore.Http;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Builders;
using Farfetch.LoadShedding.Builders;
using Xunit;

namespace Farfetch.LoadShedding.Tests.Builders
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Calculators;
using Farfetch.LoadShedding.Calculators;
using Farfetch.LoadShedding.Configurations;
using Moq;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Calculators;
using Farfetch.LoadShedding.Calculators;
using Farfetch.LoadShedding.Configurations;
using Moq;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Configurations;
using Farfetch.LoadShedding.Configurations;
using Farfetch.LoadShedding.Events;
using Farfetch.LoadShedding.Measures;
using Farfetch.LoadShedding.Tasks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Configurations;
using Farfetch.LoadShedding.Configurations;
using Farfetch.LoadShedding.Exceptions;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Calculators;
using Farfetch.LoadShedding.Calculators;
using Farfetch.LoadShedding.Configurations;
using Farfetch.LoadShedding.Limiters;
using Farfetch.LoadShedding.Events;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Measures;
using Farfetch.LoadShedding.Measures;
using Xunit;

namespace Farfetch.LoadShedding.Tests.Measures
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Tasks;
using Farfetch.LoadShedding.Tasks;
using Xunit;

namespace Farfetch.LoadShedding.Tests.Tasks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Events;
using Farfetch.LoadShedding.Events;
using Farfetch.LoadShedding.Events.Args;
using Farfetch.LoadShedding.Exceptions;
using Farfetch.LoadShedding.Tasks;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Farfetch.LoadShedding.Tasks;
using Farfetch.LoadShedding.Tasks;
using Xunit;

namespace Farfetch.LoadShedding.Tests.Tasks
Expand Down
3 changes: 3 additions & 0 deletions tests/unit-tests/Traits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using Xunit;

[assembly: AssemblyTrait("Category", "Unit")]

0 comments on commit 38abc69

Please sign in to comment.