Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only format on forks #205

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ on:
jobs:
build:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
needs: [code-formatting]
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -38,7 +37,6 @@ jobs:

playwright:
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
needs: [code-formatting]
name: "Playwright Tests"
runs-on: ubuntu-latest
defaults:
Expand Down Expand Up @@ -95,104 +93,3 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
build-args: |
Build_Version: ${{ steps.date.outputs.date }}.${{ github.run_attempt }}

code-formatting:
# Because the other jobs depend on this one, we need to make sure it runs on the same conditions,
# but we only actually want the steps to run on PR open/sync/reopen.
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest

steps:
- name: Setup checkout
if: github.event_name == 'pull_request' && github.event.action != 'closed'
uses: actions/checkout@v3
with:
repository: ${{ github.actor }}/TagzApp
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Get git diff
if: github.event_name == 'pull_request' && github.event.action != 'closed'
id: diff
run: |
git remote add upstream https://github.com/FritzAndFriends/TagzApp.git
git fetch upstream main
{
echo 'files<<EOF'
git diff upstream/main --name-only --diff-filter=d -- "*.css" "*.js" "*.cs"
echo EOF
} >> "$GITHUB_OUTPUT"

- name: Get changed C# files
if: github.event_name == 'pull_request' && github.event.action != 'closed'
id: changed_cs
run: |
{
echo 'files<<EOF'
echo "${{ steps.diff.outputs.files }}" | grep -E "\.cs$" | paste -sd " "
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Add formatting rules to .editorconfig
if: (github.event_name == 'pull_request' && github.event.action != 'closed') && steps.changed_cs.outputs.files != ''
run: |
echo "" >> src/.editorconfig
echo "[*.cs]" >> src/.editorconfig
echo "dotnet_diagnostic.IDE0005.severity = error" >> src/.editorconfig # Remove unnecessary using directives
echo "dotnet_diagnostic.IDE0090.severity = error" >> src/.editorconfig # Simplify new expression
echo "dotnet_diagnostic.IDE0003.severity = error" >> src/.editorconfig # this and Me preferences
echo "dotnet_diagnostic.IDE0009.severity = error" >> src/.editorconfig # this and Me preferences
- name: Setup .NET
if: (github.event_name == 'pull_request' && github.event.action != 'closed') && steps.changed_cs.outputs.files != ''
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Run dotnet format
if: (github.event_name == 'pull_request' && github.event.action != 'closed') && steps.changed_cs.outputs.files != ''
id: dotnet-format
run: |
echo "Running dotnet format on: ${{ steps.changed_cs.outputs.files }}"
result=$(dotnet format src/TagzApp.sln --verbosity normal --exclude src/TagzApp.Web/Migrations --include ${{ steps.changed_cs.outputs.files }})
echo "Format result:"
echo "$result"
count=$(echo "$result" | grep -c "Formatted code file" || true)
echo "Number of files Format formatted: $count"
echo "count=$count" >> "$GITHUB_OUTPUT"

- name: Get changed JS/CSS files
if: github.event_name == 'pull_request' && github.event.action != 'closed'
id: changed_js_css
run: |
{
echo 'files<<EOF'
echo "${{ steps.diff.outputs.files }}" | grep -E "\.(js|css)$" | paste -sd " "
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Setup Node
if: (github.event_name == 'pull_request' && github.event.action != 'closed') && steps.changed_js_css.outputs.files != ''
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Run prettier
if: (github.event_name == 'pull_request' && github.event.action != 'closed') && steps.changed_js_css.outputs.files != ''
id: prettier
run: |
echo "Running prettier on: ${{ steps.changed_js_css.outputs.files }}"
npm install prettier
result=$(npx prettier --write --list-different ${{ steps.changed_js_css.outputs.files }})
echo "Prettier result:"
echo "$result"
count=$(echo "$result" | grep -cE "\.(js|css)$" || true)
echo "Number of files Prettier formatted: $count"
echo "count=$count" >> "$GITHUB_OUTPUT"

- name: Commit if changes
if: (github.event_name == 'pull_request' && github.event.action != 'closed') && steps.prettier.outputs.count > 0 || steps.dotnet-format.outputs.count > 0
continue-on-error: true # fail-safe to make sure the build and tests run.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add *.cs *.js *.css
echo "$(git status)"
git commit -m "Applying formatting changes through GitHub Actions"
git push
95 changes: 95 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Code formatting
on:
push:
paths:
- src/**.cs
- src/**.js
- src/**.css
permissions:
contents: write

jobs:
code-formatting:
if: github.ref != 'refs/heads/main' && github.repository != 'FritzAndFriends/TagzApp'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Get git diff
id: diff
run: |
git remote add upstream https://github.com/FritzAndFriends/TagzApp.git
git fetch upstream main
{
echo 'files<<EOF'
git diff upstream/main --name-only --diff-filter=d -- "*.css" "*.js" "*.cs"
echo EOF
} >> "$GITHUB_OUTPUT"

- name: Get changed C# files
id: changed_cs
run: |
{
echo 'files<<EOF'
echo "${{ steps.diff.outputs.files }}" | grep -E "\.cs$" | paste -sd " "
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Add formatting rules to .editorconfig
if: steps.changed_cs.outputs.files != ''
run: |
echo "" >> src/.editorconfig
echo "[*.cs]" >> src/.editorconfig
echo "dotnet_diagnostic.IDE0005.severity = error" >> src/.editorconfig # Remove unnecessary using directives
echo "dotnet_diagnostic.IDE0090.severity = error" >> src/.editorconfig # Simplify new expression
echo "dotnet_diagnostic.IDE0003.severity = error" >> src/.editorconfig # this and Me preferences
echo "dotnet_diagnostic.IDE0009.severity = error" >> src/.editorconfig # this and Me preferences
- name: Setup .NET
if: steps.changed_cs.outputs.files != ''
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Run dotnet format
if: steps.changed_cs.outputs.files != ''
id: dotnet-format
run: |
echo -e "\033[36mRunning dotnet format on:\033[0m ${{ steps.changed_cs.outputs.files }}"
result=$(dotnet format src/TagzApp.sln --verbosity normal --exclude src/**/Migrations/ --include ${{ steps.changed_cs.outputs.files }})
echo -e "\033[36mdotnet-format result:\033[0m"
echo "$result"
count=$(echo "$result" | grep -c "Formatted code file" || true)
echo -e "\033[36mNumber of files formatted: $count\033[0m"

- name: Get changed JS/CSS files
id: changed_js_css
run: |
{
echo 'files<<EOF'
echo "${{ steps.diff.outputs.files }}" | grep -E "\.(js|css)$" | paste -sd " "
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Setup Node
if: steps.changed_js_css.outputs.files != ''
uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Run prettier
if: steps.changed_js_css.outputs.files != ''
id: prettier
run: |
echo -e "\033[36mRunning prettier on:\033[0m ${{ steps.changed_js_css.outputs.files }}"
npm install prettier
result=$(npx prettier --write --list-different ${{ steps.changed_js_css.outputs.files }})
echo -e "\033[36mprettier result:\033[0m"
echo "$result"
count=$(echo "$result" | grep -cE "\.(js|css)$" || true)
echo -e "\033[36mNumber of files formatted: $count\033[0m"

- name: Commit
continue-on-error: true
run: |
echo -e "\033[33mNote: This step will fail if there are no formatted files, but that's ok.\033[0m"
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add *.cs *.js *.css
git commit -m "Applying formatting changes through GitHub Actions"
git push
82 changes: 41 additions & 41 deletions src/TagzApp.Providers.TwitchChat/StartTwitchChat.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TagzApp.Common.Exceptions;

namespace TagzApp.Providers.TwitchChat;

public class StartTwitchChat : IConfigureProvider
{

private const string ConfigurationKey = "providers:twitchchat";

public IServiceCollection RegisterServices(IServiceCollection services, IConfiguration configuration)
{

IConfiguration config = null;
try
{
config = configuration.GetSection(ConfigurationKey);
services.Configure<TwitchChatConfiguration>(config);
}
catch (Exception ex)
{

// Was not able to configure the provider
throw new InvalidConfigurationException(ex.Message, ConfigurationKey);

}

if (config is null || string.IsNullOrEmpty(config.GetValue<string>("ClientId")))
{
// No configuration provided, no registration to be added
return services;
}

services.AddSingleton<ISocialMediaProvider, TwitchChatProvider>();


return services;

}
}
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TagzApp.Common.Exceptions;
namespace TagzApp.Providers.TwitchChat;
public class StartTwitchChat : IConfigureProvider
{
private const string _ConfigurationKey = "providers:twitchchat";
public IServiceCollection RegisterServices(IServiceCollection services, IConfiguration configuration)
{
IConfiguration config = null;
try
{
config = configuration.GetSection(_ConfigurationKey);
services.Configure<TwitchChatConfiguration>(config);
}
catch (Exception ex)
{
// Was not able to configure the provider
throw new InvalidConfigurationException(ex.Message, _ConfigurationKey);
}
if (config is null || string.IsNullOrEmpty(config.GetValue<string>("ClientId")))
{
// No configuration provided, no registration to be added
return services;
}
services.AddSingleton<ISocialMediaProvider, TwitchChatProvider>();
return services;
}
}
58 changes: 33 additions & 25 deletions src/TagzApp.Web/wwwroot/js/masonry.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
(function () {

const m = {

resizeGridItem: function (item) {
grid = document.getElementById("taggedContent");
rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'));
rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap'));
var imageSize = (item.querySelector('.contentcard')?.getBoundingClientRect().height ?? 0) + (item.querySelector('.contentcard') ? 6 : 0);
rowSpan = Math.ceil((item.querySelector('.content').getBoundingClientRect().height + imageSize + 100 + rowGap) / (rowHeight + rowGap));
item.style.gridRowEnd = "span " + rowSpan;
},

resizeAllGridItems: function () {
allItems = document.querySelectorAll("article");
for (x = 0; x < allItems.length; x++) {
m.resizeGridItem(allItems[x]);
}
}

};

window.Masonry = m;

})();
(function () {
const m = {
resizeGridItem: function (item) {
grid = document.getElementById('taggedContent');
rowHeight = parseInt(
window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'),
);
rowGap = parseInt(
window.getComputedStyle(grid).getPropertyValue('grid-row-gap'),
);
var imageSize =
(item.querySelector('.contentcard')?.getBoundingClientRect().height ??
0) + (item.querySelector('.contentcard') ? 6 : 0);
rowSpan = Math.ceil(
(item.querySelector('.content').getBoundingClientRect().height +
imageSize +
100 +
rowGap) /
(rowHeight + rowGap),
);
item.style.gridRowEnd = 'span ' + rowSpan;
},

resizeAllGridItems: function () {
allItems = document.querySelectorAll('article');
for (x = 0; x < allItems.length; x++) {
m.resizeGridItem(allItems[x]);
}
},
};

window.Masonry = m;
})();