Skip to content

Commit

Permalink
chore: adding version generation to the project and release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
xeekworx committed Nov 25, 2024
1 parent 2fd28d7 commit 5cf641a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:

env:
APP_NAME: WindowTool
VER_FILE: ./source/version.h

jobs:
release:
Expand All @@ -29,6 +30,18 @@ jobs:
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
release-type: simple

- name: Generate & Commit Version Header
if: ${{ steps.release.outputs.release_created }}
run: |
echo "// Do not modify this file, it is overwritten by release-please.yml!" > ${{ env.VER_FILE }}
echo "#pragma once" >> ${{ env.VER_FILE }}
echo "constexpr const wchar_t APP_VERSION[] = L\"${{ steps.release.outputs.tag_name }}\"" >> ${{ env.VER_FILE }}
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add ${{ env.VER_FILE }}
git commit -m "chore: update version header to ${{ steps.release.outputs.tag_name }}"
git push
build-x64:
name: Build x64 Release
needs: release
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,7 @@ AkavacheSqliteLinkerOverride.cs
NuGetBuild
WiX.Toolset.DummyFile.txt
GitHubVS.sln.DotSettings

# Ignore version.h except in the release branch
/source/version.h
!release-branch-*
1 change: 1 addition & 0 deletions WindowTool.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="source\text_compare_type.h" />
<ClInclude Include="source\version.h" />
<ClInclude Include="source\window.h" />
<ClInclude Include="source\window_actions.h" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions WindowTool.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ClInclude Include="source\window_actions.h">
<Filter>source</Filter>
</ClInclude>
<ClInclude Include="source\version.h">
<Filter>source</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include=".github\workflows\build.yml">
Expand Down
23 changes: 20 additions & 3 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// WindowTool.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include "version.h"
#include "window_actions.h"
#include <iostream>
#include <unordered_set>
#include <vector>
#include <functional>

bool should_show_help(const std::vector<std::wstring>& arguments, std::function<void()> display_func);
bool should_show_version(const std::vector<std::wstring>& arguments);

int wmain(int argc, wchar_t* argv[])
{
Expand All @@ -17,6 +16,9 @@ int wmain(int argc, wchar_t* argv[])

window_tool::window_actions actions(arguments);

if (should_show_version(arguments))
return 0;

if (should_show_help(arguments, [actions]() { actions.display_usage(); }))
return 0;

Expand All @@ -37,3 +39,18 @@ bool should_show_help(const std::vector<std::wstring>& arguments, std::function<

return false;
}

bool should_show_version(const std::vector<std::wstring>& arguments)
{
std::unordered_set<std::wstring> possibleVersionOptions = {
L"--version", L"-v"
};

if (arguments.size() > 1 && possibleVersionOptions.find(arguments[1]) != possibleVersionOptions.end())
{
std::wcout << L"v" << APP_VERSION << std::endl;
return true;
}

return false;
}
2 changes: 2 additions & 0 deletions source/window_actions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "window_actions.h"
#include "version.h"
#include <filesystem>
#include <iostream>
#include <locale>
Expand Down Expand Up @@ -80,6 +81,7 @@ int window_actions::run()

void window_actions::display_usage() const
{
std::wcout << L"Window Tool Version " << APP_VERSION << std::endl;
std::wcout << L"Usage: " << _app_name << L" \"Window Title\" \"Action\" [ButtonName]" << std::endl
<< std::endl
<< L"Options surrounded by [] are optional, but do not include the brackets." << std::endl
Expand Down

0 comments on commit 5cf641a

Please sign in to comment.