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

Add Linux support #3

Merged
merged 7 commits into from
Oct 20, 2024
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
162 changes: 89 additions & 73 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,89 @@
name: Build and Package

on: [push]

permissions:
contents: write

jobs:

# Build artifacts
build:
runs-on: windows-latest

steps:
- name: Checkout
uses: actions/checkout@v4

# We need dotnet
- name: Add dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Setup NuGet
uses: NuGet/setup-nuget@v1

- name: Restore NuGet Packages
run: nuget restore artwork4DMD.sln

# Build artifacts when git tag
- if: startsWith(github.ref, 'refs/tags/')
name: Build
run: |
dotnet publish -r win-x64 --self-contained=false /p:PublishSingleFile=true artwork4dmd.csproj /p:Version=${{ github.ref_name }}

- if: "!startsWith(github.ref, 'refs/tags/')"
name: Build
run: |
dotnet publish -r win-x64 --self-contained=false /p:PublishSingleFile=true artwork4dmd.csproj
tree

# Upload artifacts
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artwork4DMD
path: .\bin\Release\net8.0-windows\win-x64\publish
retention-days: 7

- name: Generate zip bundle
run: |
7z a -tzip artwork4DMD.zip .\bin\Release\net8.0-windows\win-x64\publish\*

- if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
name: Publish latest pre-release
uses: ncipollo/release-action@v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
generateReleaseNotes: true
prerelease: true
artifacts: |
artwork4DMD.zip

- if: startsWith(github.ref, 'refs/tags/')
name: Publish tagged release
uses: ncipollo/release-action@v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
generateReleaseNotes: true
prerelease: false
allowUpdates: true
artifacts: |
artwork4DMD.zip
name: Build and Package

on: [push]

permissions:
contents: write

jobs:
build-windows:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: |
if ('${{ startsWith(github.ref, 'refs/tags/') }}' -eq 'true') {
dotnet publish -r win-x64 -c Release /p:Version=${{ github.ref_name }}
} else {
dotnet publish -r win-x64 -c Release
}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artwork4dmd-windows
path: .\bin\Release\net8.0\win-x64\publish\
retention-days: 7

build-linux:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: |
if [[ ${{ github.ref }} == refs/tags/* ]]; then
dotnet publish -r linux-x64 -c Release /p:Version=${{ github.ref_name }}
else
dotnet publish -r linux-x64 -c Release
fi

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: artwork4dmd-linux
path: ./bin/Release/net8.0/linux-x64/publish/

create-release:
needs: [build-windows, build-linux]
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
steps:
- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: artwork4dmd-windows

- name: Download Linux artifact
uses: actions/download-artifact@v4
with:
name: artwork4dmd-linux

- name: Create Release
uses: ncipollo/release-action@v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
generateReleaseNotes: true
prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }}
allowUpdates: true
artifacts: "artwork4dmd-windows.zip,artwork4dmd-linux.zip"
tag: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', github.sha) }}
14 changes: 11 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
using System.Net;
using System.Threading;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;

class Program
{
Expand Down Expand Up @@ -79,6 +80,12 @@ public sealed class Settings
public static Settings gSettings;
static async Task Main(string[] args)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
// Set the MAGICK_HOME environment variable to the directory containing ImageMagick libraries
Environment.SetEnvironmentVariable("MAGICK_HOME", AppDomain.CurrentDomain.BaseDirectory);
}

string iniPath = Path.Combine(Environment.CurrentDirectory, "settings.ini");
IConfigurationRoot config = new ConfigurationBuilder()
.AddIniFile(iniPath)
Expand Down Expand Up @@ -124,9 +131,10 @@ static async Task DownloadPicture(GameInfo game)
{
Directory.CreateDirectory($"{gSettings.OutputFolder}/orig/{game.Platform}");
// If overwrite config is false AND file already exist, then don't do anything
if ((gSettings.Overwrite == false) && File.Exists($"{gSettings.OutputFolder}\\orig\\{game.Platform}\\{game.Name}.png"))
string filePath = Path.Combine(gSettings.OutputFolder, "orig", game.Platform, $"{game.Name}.png");
if ((gSettings.Overwrite == false) && File.Exists(filePath))
{
Console.WriteLine($"Skipping download of {gSettings.OutputFolder}\\orig\\{game.Platform}\\{game.Name}.png because it already exists");
Console.WriteLine($"Skipping download of {filePath} because it already exists");
return;
}
if (game.Name.Contains(":")) {
Expand Down Expand Up @@ -338,7 +346,7 @@ static void ConvertPicture(string inputPath, bool isGif)
string outputPath = Path.Combine(
gSettings.OutputFolder,
$"{width}x{height}",
Path.GetDirectoryName(inputPath).Split('\\').Last(),
Path.GetFileName(Path.GetDirectoryName(inputPath)),
$"{Path.GetFileNameWithoutExtension(inputPath)}{outputExtension}"
);
//Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {Path.GetFileName(outputPath)}");
Expand Down
3 changes: 2 additions & 1 deletion artwork4dmd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<DebugType Condition=" '$(Configuration)' == 'Release' ">None</DebugType>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down