Skip to content

Commit

Permalink
github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Feb 6, 2024
1 parent 6047d95 commit 7399e0b
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 37 deletions.
114 changes: 114 additions & 0 deletions .github/workflows/zzzo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
name: zzzo

on:
push:
branches: ["*"]
tags: ["*"]

jobs:
check-build-script:
name: check-build-script
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Check script syntax
run: bash -n ./resources/scripts/github-actions/build-linux-mac.sh

- name: Show shellcheck version
run: shellcheck --version

- name: Run shellcheck
run: shellcheck --color=always ./resources/scripts/github-actions/build-linux-mac.sh

build-rssguard:
needs: check-build-script
name: "${{ matrix.os }}; no-lite = ${{ matrix.no_lite }}; qt5 = ${{ matrix.use_qt5 }}"
runs-on: "${{ matrix.os }}"
strategy:
matrix:
os: [windows-2019, ubuntu-20.04, macos-11]
no_lite: ["ON", "OFF"]
use_qt5: ["ON", "OFF"]
include:
- os: windows-2019
script_name: .\resources\scripts\github-actions\build-windows.ps1
- os: ubuntu-20.04
script_name: ./resources/scripts/github-actions/build-linux-mac.sh
- os: macos-11
script_name: ./resources/scripts/github-actions/build-linux-mac.sh
exclude:
- os: ubuntu-20.04
use_qt5: "OFF"
- os: macos-11
use_qt5: "ON"
steps:
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true

- name: Prepare environment and compile application
run: ${{ matrix.script_name }} "${{ matrix.os }}" "${{ matrix.no_lite }}" "${{ matrix.use_qt5 }}"
env:
GMAIL_CLIENT_ID: ${{ secrets.GMAIL_CLIENT_ID }}
GMAIL_CLIENT_SECRET: ${{ secrets.GMAIL_CLIENT_SECRET }}
FEEDLY_CLIENT_ID: ${{ secrets.FEEDLY_CLIENT_ID }}
FEEDLY_CLIENT_SECRET: ${{ secrets.FEEDLY_CLIENT_SECRET }}

- name: Upload binaries
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: RSS_Guard-${{ runner.os }}${{ matrix.no_lite == 'ON' && '-' || '-nowebengine-' }}Qt${{ matrix.use_qt5 == 'ON' && '5' || '6' }}
path: |
./rssguard-build/rssguard-*win*.exe
./rssguard-build/rssguard-*win*.7z
./rssguard-build/rssguard-*mac64.dmg
./rssguard-build/rssguard-*linux64.AppImage
dist-binaries:
name: distribute-binaries
needs:
- build-rssguard
runs-on: ubuntu-22.04
permissions:
contents: write

steps:
- name: Download binaries from previous jobs
uses: actions/download-artifact@v3
with:
path: artifacts

- name: Release development binaries
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifactErrorsFailBuild: true
artifacts: artifacts/*/*
name: Development builds
omitBodyDuringUpdate: true
prerelease: true
removeArtifacts: true
tag: devbuild

- name: Update "devbuild" tag
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
uses: richardsimko/update-tag@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: devbuild

- name: Release stable binaries
if: startsWith(github.ref, 'refs/tags/')
uses: ncipollo/release-action@v1
with:
artifactErrorsFailBuild: true
artifacts: artifacts/*/*
draft: true
25 changes: 7 additions & 18 deletions ZZZO/ZZZO.Common/API/Zasedani.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Zasedani : ObservableObject
private int _pocetHostu;
private int _poradi = 1;
private Program _program = new Program();
private bool _spinave;
private string _vystupniSoubor;
private ObservableCollection<Zastupitel> _zastupitele = new ObservableCollection<Zastupitel>();

Expand Down Expand Up @@ -187,22 +186,6 @@ public Program Program
}
}

[JsonIgnore]
public bool Spinave
{
get => _spinave;
set
{
if (value == _spinave)
{
return;
}

_spinave = value;
OnPropertyChanged();
}
}

/// <summary>
/// Výstupní soubor bez přípony.
/// </summary>
Expand Down Expand Up @@ -300,6 +283,12 @@ public void RemoveZastupitel(Zastupitel zast)
}

public void SaveToFile(string file)
{
byte[] json = ToJson();
File.WriteAllBytes(file, json);
}

public byte[] ToJson()
{
string json = JsonConvert.SerializeObject(this, new JsonSerializerSettings
{
Expand All @@ -308,7 +297,7 @@ public void SaveToFile(string file)
Formatting = Formatting.Indented
});

File.WriteAllText(file, json, Encoding.UTF8);
return Encoding.UTF8.GetBytes(json);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion ZZZO/ZZZO/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public App()

public void SetDataContexts(MainWindow window)
{
window.DataContext = new MainWindowViewModel(Current, Core);
window.DataContext = new MainWindowViewModel(window, Current, Core);
window.UcBasicInfo.DataContext = new BasicInfoViewModel(Core);
window.UcProgram.DataContext = new ProgramViewModel(Core);
window.UcGenerator.DataContext = new GeneratorViewModel(window.UcGenerator, Core);
Expand Down
67 changes: 58 additions & 9 deletions ZZZO/ZZZO/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Windows;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using ZZZO.Commands;
using ZZZO.Common.API;
using ZZZO.Windows;

namespace ZZZO.ViewModels;

Expand All @@ -19,14 +21,12 @@ public ZzzoCore Core
get;
}

#endregion

public ICommand NewZasedaniCmd
public ICommand LoadZasedaniCmd
{
get;
}

public ICommand LoadZasedaniCmd
public ICommand NewZasedaniCmd
{
get;
}
Expand All @@ -36,14 +36,19 @@ public ICommand SaveZasedaniCmd
get;
}

#endregion

#region Konstruktory

public MainWindowViewModel()
{
}

public MainWindowViewModel(App app, ZzzoCore core)
public MainWindowViewModel(MainWindow window, App app, ZzzoCore core)
{
// View is only used to bind necessary events.
window.Closing += OnAppClosing;

App = app;
Core = core;

Expand All @@ -58,11 +63,21 @@ public MainWindowViewModel(App app, ZzzoCore core)

private void LoadZasedani()
{
if (!SaveIfDirtyAndContinue())
{
return;
}

Core.LoadZasedani();
}

private void NewZasedani()
{
if (!SaveIfDirtyAndContinue())
{
return;
}

Zasedani zas = new Zasedani();

zas.AddZastupitel(new Zastupitel
Expand Down Expand Up @@ -165,12 +180,46 @@ private void NewZasedani()
JePodbod = true
});

Core.Zasedani = zas;
Core.NewZaseDani(zas);
}

private void OnAppClosing(object sender, CancelEventArgs e)
{
if (!SaveIfDirtyAndContinue())
{
e.Cancel = true;
}
}

private bool SaveIfDirtyAndContinue()
{
if (Core.ZasedaniIsDirty)
{
if (MessageBox.Show(
"Máte nějaké neuložené změny, chcete nejdříve uložit vaši současnou práci?",
"Neuložené změny",
MessageBoxButton.YesNo,
MessageBoxImage.Question,
MessageBoxResult.Yes) == MessageBoxResult.Yes)
{
if (!SaveZasedani())
{
// User did not save his unsaved work, abort.
return false;
}
}
else
{
// User does not need to save changes.
}
}

return true;
}

private void SaveZasedani()
private bool SaveZasedani()
{
Core.SaveZasedani();
return Core.SaveZasedani();
}

#endregion
Expand Down
5 changes: 0 additions & 5 deletions ZZZO/ZZZO/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public MainWindow()

#region Metody

protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
}

private void QuitApp(object sender, RoutedEventArgs e)
{
Close();
Expand Down
42 changes: 38 additions & 4 deletions ZZZO/ZZZO/ZzzoCore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Win32;
using System.Linq;
using Microsoft.Win32;
using ZZZO.Common;
using ZZZO.Common.API;

Expand All @@ -25,21 +26,38 @@ public Zasedani Zasedani
}

_zasedani = value;

ZasedaniOriginalData = _zasedani.ToJson();

OnPropertyChanged();
OnPropertyChanged(nameof(ZasedaniLoaded));
}
}

public bool ZasedaniIsDirty
{
get => ZasedaniLoaded && ZasedaniOriginalData != null && !Zasedani.ToJson().SequenceEqual(ZasedaniOriginalData);
}

public bool ZasedaniLoaded
{
get => Zasedani != null;
}

/// <summary>
/// Is used to determine if there is any change or not.
/// </summary>
private byte[] ZasedaniOriginalData
{
get;
set;
}

#endregion

#region Metody

public void LoadZasedani()
public bool LoadZasedani()
{
OpenFileDialog d = new OpenFileDialog();

Expand All @@ -51,14 +69,24 @@ public void LoadZasedani()
if (d.ShowDialog().GetValueOrDefault())
{
Zasedani = Zasedani.LoadFromFile(d.FileName);
return true;
}
else
{
return false;
}
}

public void SaveZasedani()
public void NewZaseDani(Zasedani zas)
{
Zasedani = zas;
}

public bool SaveZasedani()
{
if (Zasedani == null)
{
return;
return false;
}

SaveFileDialog d = new SaveFileDialog();
Expand All @@ -72,6 +100,12 @@ public void SaveZasedani()
if (d.ShowDialog().GetValueOrDefault())
{
Zasedani.SaveToFile(d.FileName);
ZasedaniOriginalData = Zasedani.ToJson();
return true;
}
else
{
return false;
}
}

Expand Down

0 comments on commit 7399e0b

Please sign in to comment.