Skip to content

Commit a4b2ffc

Browse files
committed
chore: refactor project structure, add github actions
Signed-off-by: Chawye Hsu <[email protected]>
1 parent ffeab2b commit a4b2ffc

18 files changed

+203
-127
lines changed

.editorconfig

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*.cs]
4+
indent_size = 4
5+
indent_style = space
6+
tab_width = 4
7+
end_of_line = crlf

.github/workflows/ci.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Setup dotnet
15+
uses: actions/setup-dotnet@v4
16+
- name: Build
17+
run: dotnet build
18+
- name: Test
19+
run: dotnet test

.github/workflows/release.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
build:
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Setup dotnet
15+
uses: actions/setup-dotnet@v4
16+
- name: Build
17+
run: .\release-build.ps1
18+
- name: Release
19+
uses: softprops/action-gh-release@v2
20+
if: startsWith(github.ref, 'refs/tags/')
21+
with:
22+
files: dist/shim*.zip*

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
packages/
1+
dist/
2+
bin/
3+
obj/
4+
.vs/

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"ms-dotnettools.csdevkit",
4+
"ms-vscode.powershell",
5+
"editorconfig.editorconfig"
6+
]
7+
}

build.ps1

-22
This file was deleted.

install.ps1

-8
This file was deleted.

packages.config

-5
This file was deleted.

release-build.ps1

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#Requires -Version 7
2+
3+
Push-Location $PSScriptRoot
4+
5+
New-Item -ItemType Directory -Force -Path "$PSScriptRoot\dist" | Out-Null
6+
Remove-Item "$PSScriptRoot\dist\*" -Recurse -Force
7+
8+
Write-Host 'Compiling...' -ForegroundColor DarkCyan
9+
10+
dotnet build --configuration Release
11+
Copy-Item -Path "$PSScriptRoot\src\bin\Release\net45\shim.exe" -Destination "$PSScriptRoot\dist" -Force
12+
13+
Write-Host 'Computing checksums...' -ForegroundColor DarkCyan
14+
15+
Get-ChildItem "$PSScriptRoot\dist\*" -Include *.exe | ForEach-Object {
16+
"$((Get-FileHash -Path $_ -Algorithm SHA256).Hash.ToLower()) *$($_.Name)" | Out-File "$PSScriptRoot\dist\checksum.sha256" -Append -Encoding utf8
17+
"$((Get-FileHash -Path $_ -Algorithm SHA512).Hash.ToLower()) *$($_.Name)" | Out-File "$PSScriptRoot\dist\checksum.sha512" -Append -Encoding utf8
18+
}
19+
20+
Write-Host 'Packaging...' -ForegroundColor DarkCyan
21+
22+
$version = ([xml](Get-Content "$PSScriptRoot\src\shim.csproj")).Project.PropertyGroup.Version
23+
24+
"$version" | Out-File "$PSScriptRoot\dist\version.txt" -Encoding utf8
25+
26+
Compress-Archive -Path "$PSScriptRoot\dist\*" -DestinationPath "$PSScriptRoot\dist\shim-$version.zip"
27+
"$((Get-FileHash -Path "$PSScriptRoot\dist\shim-$version.zip" -Algorithm SHA256).Hash.ToLower()) *$("shim-$version.zip")" | Out-File "$PSScriptRoot\dist\shim-$version.zip.sha256" -Append -Encoding utf8
28+
29+
Pop-Location

release.ps1

-35
This file was deleted.

shim.csproj

-43
This file was deleted.

shim.sln

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.5.002.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "shim", "src\shim.csproj", "{D85B01A6-F5DC-44DD-934A-CFE067DB42F0}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test\test.csproj", "{038DE1C9-050B-473D-98EA-BEC7CF96533D}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0E7E0C8E-AF1C-42D3-BCC7-27497E329C6C}"
11+
ProjectSection(SolutionItems) = preProject
12+
LICENSE = LICENSE
13+
README.md = README.md
14+
EndProjectSection
15+
EndProject
16+
Global
17+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18+
Debug|Any CPU = Debug|Any CPU
19+
Release|Any CPU = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
22+
{D85B01A6-F5DC-44DD-934A-CFE067DB42F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{D85B01A6-F5DC-44DD-934A-CFE067DB42F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{D85B01A6-F5DC-44DD-934A-CFE067DB42F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{D85B01A6-F5DC-44DD-934A-CFE067DB42F0}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{038DE1C9-050B-473D-98EA-BEC7CF96533D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{038DE1C9-050B-473D-98EA-BEC7CF96533D}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{038DE1C9-050B-473D-98EA-BEC7CF96533D}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{038DE1C9-050B-473D-98EA-BEC7CF96533D}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {6483F3D4-AE70-45C4-A180-BE5BCB6463BE}
36+
EndGlobalSection
37+
EndGlobal

shim.cs src/shim.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Scoop {
1313

14-
class Program {
14+
public class Program {
1515
[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
1616
static extern bool CreateProcess(string lpApplicationName,
1717
string lpCommandLine, IntPtr lpProcessAttributes,
@@ -159,13 +159,13 @@ static string GetArgs(string cmdLine) {
159159
return cmdLine.Substring(space + 1);
160160
}
161161

162-
static string Get(Dictionary<string, string> dic, string key) {
162+
public static string Get(Dictionary<string, string> dic, string key) {
163163
string value = null;
164164
dic.TryGetValue(key, out value);
165165
return value;
166166
}
167167

168-
static Dictionary<string, string> Config(string path) {
168+
public static Dictionary<string, string> Config(string path) {
169169
var config = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
170170
foreach(var line in File.ReadAllLines(path)) {
171171
var m = Regex.Match(line, @"([^=]+)=(.*)");

src/shim.csproj

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net45</TargetFramework>
6+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
7+
<AssemblyName>shim</AssemblyName>
8+
<Version>1.1.0</Version>
9+
<Description>Scoop helper program for shimming executables.</Description>
10+
<Authors>Scoop contributors</Authors>
11+
<Copyright>Copyright (c) 2013-2024 Scoop contributors</Copyright>
12+
<ImplicitUsings>enable</ImplicitUsings>
13+
<LangVersion>10</LangVersion>
14+
<Nullable>enable</Nullable>
15+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
16+
<PackageProjectUrl>https://github.com/ScoopInstaller/Shim</PackageProjectUrl>
17+
<RepositoryUrl>https://github.com/ScoopInstaller/Shim</RepositoryUrl>
18+
<PackageReadmeFile>README.md</PackageReadmeFile>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<None Include="..\LICENSE" Pack="true" Visible="false" PackagePath="" />
23+
<None Include="..\README.md" Pack="true" Visible="false" PackagePath="" />
24+
</ItemGroup>
25+
26+
</Project>

test/UnitTest.cs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Reflection;
2+
3+
namespace Scoop.Tests
4+
{
5+
public class ShimTests
6+
{
7+
[Fact]
8+
public void TestShimFileParser()
9+
{
10+
var workingDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
11+
Assert.NotNull(workingDir);
12+
13+
var path = Path.Combine(workingDir, @"fixtures\test.shim");
14+
15+
var config = Program.Config(path);
16+
Assert.Equal("\"C:\\Users\\test\\scoop\\apps\\test\\current\\test.exe\"", Program.Get(config, "path"));
17+
Assert.Equal("x", Program.Get(config, "args"));
18+
}
19+
}
20+
}

test/fixtures/test.shim

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
path = "C:\Users\test\scoop\apps\test\current\test.exe"
2+
args = x

test/test.csproj

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
14+
<PackageReference Include="xunit" Version="2.5.3" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\src\shim.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<Using Include="Xunit" />
24+
<None Include="fixtures\**" CopyToOutputDirectory="PreserveNewest" LinkBase="fixtures" />
25+
</ItemGroup>
26+
27+
</Project>

update.ps1

-10
This file was deleted.

0 commit comments

Comments
 (0)