Skip to content

Commit

Permalink
Merge pull request #3 from ErSoul/fix/actions
Browse files Browse the repository at this point in the history
Replace sonarcloud workflow.
  • Loading branch information
ErSoul authored Jul 14, 2024
2 parents cbc02d7 + 8b8fe58 commit 1f6553e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Build and Test

on:
workflow_dispatch:
push:
branches: [ "main" ]
pull_request:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: Deploy

on:
workflow_dispatch:
push:
Expand All @@ -6,7 +8,6 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Setup .NET
Expand All @@ -15,8 +16,8 @@ jobs:
dotnet-version: 8.0.x
- name: Publish
run: dotnet publish dotpaste/dotpaste.csproj -c Release -o build
- name: SCP Uploader
uses: ersoul/scp_uploader@v0.1
- name: Upload to server
uses: ErSoul/scp_uploader@v1.0
with:
host: ${{vars.SSH_HOST}}
username: ${{secrets.SSH_USER}}
Expand Down
104 changes: 47 additions & 57 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
@@ -1,63 +1,53 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow helps you trigger a SonarCloud analysis of your code and populates
# GitHub Code Scanning alerts with the vulnerabilities found.
# Free for open source project.

# 1. Login to SonarCloud.io using your GitHub account

# 2. Import your project on SonarCloud
# * Add your GitHub organization first, then add your repository as a new project.
# * Please note that many languages are eligible for automatic analysis,
# which means that the analysis will start automatically without the need to set up GitHub Actions.
# * This behavior can be changed in Administration > Analysis Method.
#
# 3. Follow the SonarCloud in-product tutorial
# * a. Copy/paste the Project Key and the Organization Key into the args parameter below
# (You'll find this information in SonarCloud. Click on "Information" at the bottom left)
#
# * b. Generate a new token and add it to your Github repository's secrets using the name SONAR_TOKEN
# (On SonarCloud, click on your avatar on top-right > My account > Security
# or go directly to https://sonarcloud.io/account/security/)

# Feel free to take a look at our documentation (https://docs.sonarcloud.io/getting-started/github/)
# or reach out to our community forum if you need some help (https://community.sonarsource.com/c/help/sc/9)

name: SonarCloud analysis

name: SonarCloud
on:
push:
branches: [ "main" ]
branches:
- main
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
pull-requests: read # allows SonarCloud to decorate PRs with analysis results

types: [opened, synchronize, reopened]
jobs:
Analysis:
runs-on: ubuntu-latest

build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Analyze with SonarCloud

# You can pin the exact commit or the version.
# uses: SonarSource/[email protected]
uses: SonarSource/sonarcloud-github-action@4006f663ecaf1f8093e8e4abb9227f6041f52216
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} # Generate a token on Sonarcloud.io, add it to the secrets of this repo with the name SONAR_TOKEN (Settings > Secrets > Actions > add new repository secret)
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
# Additional arguments for the SonarScanner CLI
args:
# Unique keys of your project and organization. You can find them in SonarCloud > Information (bottom-left menu)
# mandatory
-Dsonar.projectKey=ErSoul_dotpaste
-Dsonar.organization=ersoul
#-Dsonar.sources=dotpaste
#-Dsonar.tests=dotpaste.Tests
# When you need the analysis to take place in a directory other than the one from which it was launched, default is .
projectBaseDir: .
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Install dotnet-coverage
shell: powershell
run: |
dotnet tool install --global dotnet-coverage
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"ErSoul_dotpaste" /o:"ersoul" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build -c Release
dotnet-coverage collect 'dotnet test dotpaste.Tests/dotpaste.Tests.csproj' -f xml -o coverage.xml
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Repo Size](https://img.shields.io/github/repo-size/ErSoul/dotpaste?logo=github)](https://github.com/ErSoul/dotpaste)
[![Build Status](https://github.com/ErSoul/dotpaste/workflows/dotpaste/badge.svg)](https://github.com/ErSoul/dotpaste/actions)
[![Build Status](https://github.com/ErSoul/dotpaste/workflows/build/badge.svg)](https://github.com/ErSoul/dotpaste/actions)
[![Made By](https://img.shields.io/badge/Made_By-ErSoul-yellow?logo=dotnet&logoColor=yellow)](https://github.com/ErSoul)

# dotpaste
Expand Down
6 changes: 3 additions & 3 deletions dotpaste/Endpoints/Paste.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void MapPastes(this WebApplication app, ThreadSafeCounter fileID)
app.HandleFileDeletion(Props.UPLOADS_PATH + currentFileURL);
return Array.Exists(Props.UserAgents, check => request.Headers.UserAgent.ToString().Contains(check, StringComparison.InvariantCultureIgnoreCase)) ?
Results.Redirect(currentURL + currentFileURL) :
Results.Text(currentURL + currentFileURL);
Results.Text(currentURL + currentFileURL + '\n');
}
if (request.Form.Files.Any() && request.Form.Files[0].Name == "content" && Array.Exists(Props.AcceptedContentTypes, ct => request.Form.Files[0].ContentType == ct))
Expand All @@ -33,7 +33,7 @@ public static void MapPastes(this WebApplication app, ThreadSafeCounter fileID)
app.HandleFileDeletion(Props.UPLOADS_PATH + currentFileURL);
return Array.Exists(Props.UserAgents, check => request.Headers.UserAgent.ToString().Contains(check, StringComparison.InvariantCultureIgnoreCase)) ?
Results.Redirect(currentURL + currentFileURL) :
Results.Text(currentURL + currentFileURL);
Results.Text(currentURL + currentFileURL + '\n');
}
}
Expand All @@ -45,7 +45,7 @@ public static void MapPastes(this WebApplication app, ThreadSafeCounter fileID)
app.HandleFileDeletion(Props.UPLOADS_PATH + currentFileURL);
return Array.Exists(Props.UserAgents, check => request.Headers.UserAgent.ToString().Contains(check, StringComparison.InvariantCultureIgnoreCase)) ?
Results.Redirect(currentURL + currentFileURL) :
Results.Text(currentURL + currentFileURL);
Results.Text(currentURL + currentFileURL + '\n');
}
return Results.BadRequest("Unsupported content type.");
Expand Down
6 changes: 3 additions & 3 deletions dotpaste/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
foreach (var file in directory.EnumerateFiles())
{
app.Logger.LogDebug("Deleting file '{}'", file.FullName);
app.Logger.LogDebug("Deleting file '{fileName}'", file.FullName);
file.Delete();
app.Logger.LogDebug("Deleted file '{}'", file.FullName);
app.Logger.LogDebug("Deleted file '{fileName}'", file.FullName);
}
fileID = new ThreadSafeCounter();
Expand All @@ -36,6 +36,6 @@
app.MapIndex();
app.MapPastes(fileID);

app.Run();
await app.RunAsync();

public partial class Program;
2 changes: 1 addition & 1 deletion dotpaste/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace dotpaste
{
public class View
public static class View
{
[ExcludeFromCodeCoverage]
[Obsolete("This method returns inconsistent results. Use View.TemplateHTML()")]
Expand Down
2 changes: 1 addition & 1 deletion dotpaste/wwwroot/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>dotpaste - Terminal friendly pastebin service.</title>
Expand Down

0 comments on commit 1f6553e

Please sign in to comment.