Skip to content

Commit

Permalink
fix: 修复 current_zone 崩溃问题,ci 新增 win-dbg 包 (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO authored Dec 7, 2024
1 parent 5021aac commit 11a71a2
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 53 deletions.
140 changes: 110 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ name: build
on:
push:
tags:
- 'v*'
- "v*"
branches:
- '**'
- "**"
paths:
- '.github/workflows/build.yml'
- '3rdparty/**'
- 'cmake/**'
- 'include/**'
- 'source/**'
- 'CMakeLists.txt'
- ".github/workflows/build.yml"
- "3rdparty/**"
- "cmake/**"
- "include/**"
- "source/**"
- "CMakeLists.txt"

pull_request:
branches:
- '**'
- "**"
paths:
- '.github/workflows/build.yml'
- '3rdparty/**'
- 'cmake/**'
- 'include/**'
- 'source/**'
- 'CMakeLists.txt'
- ".github/workflows/build.yml"
- "3rdparty/**"
- "cmake/**"
- "include/**"
- "source/**"
- "CMakeLists.txt"
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
with:
minimum-size: 16GB
maximum-size: 16GB
disk-root: 'D:'
disk-root: "D:"

- uses: actions/checkout@v4
with:
Expand All @@ -64,7 +64,7 @@ jobs:
- name: Setup Windows 10 SDK
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2.2
with:
sdk-version: 22621
sdk-version: 26100

- name: Bootstrap MaaDeps
env:
Expand All @@ -89,7 +89,7 @@ jobs:
- name: Build MAA
run: |
cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DCMAKE_SYSTEM_VERSION="10.0.22621.0" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON
cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DCMAKE_SYSTEM_VERSION="10.0.26100.0" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON
cmake --build build --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }} - Release" -j 16
Expand All @@ -111,7 +111,74 @@ jobs:
if: always()
with:
name: MAA-win-${{ matrix.arch }}
path: 'install'
path: "install"

windows_debug:
needs: meta
runs-on: windows-latest
strategy:
matrix:
arch: [x86_64]
fail-fast: false

steps:
- name: Windows runner hack
shell: cmd
run: |
dir d:\a
cd ..
mkdir C:\MaaFramework
rmdir MaaFramework
mklink /j MaaFramework C:\MaaFramework
dism /Online /Disable-Feature /FeatureName:Windows-Defender /Remove /NoRestart /Quiet
cd .
- name: Windows runner hack (2)
uses: al-cheb/configure-pagefile-action@v1.4
with:
minimum-size: 16GB
maximum-size: 16GB
disk-root: "D:"

- uses: actions/checkout@v4
with:
submodules: true

- name: Setup Windows 10 SDK
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2.2
with:
sdk-version: 26100

- name: Bootstrap MaaDeps
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 tools/maadeps-download.py x64-windows
- name: Build MAA
run: |
cmake --preset 'MSVC 2022' -DCMAKE_SYSTEM_VERSION="10.0.26100.0" -DMAADEPS_TRIPLET="maa-x64-windows" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}-dbg'
cmake --build build --preset 'MSVC 2022 - Debug' -j 16 --config Debug
- name: Install
shell: bash
if: always()
run: |
cmake --install build --prefix install --config Debug
cp -r docs install
cp README*.md install
cp -r sample install
cp -r LICENSE.md install
- uses: actions/upload-artifact@v4
if: always()
with:
name: MAA-win-dbg-${{ matrix.arch }}
path: "install"

ubuntu:
needs: meta
Expand Down Expand Up @@ -199,7 +266,7 @@ jobs:
if: always()
with:
name: MAA-linux-${{ matrix.arch }}
path: 'install'
path: "install"

macos:
needs: meta
Expand Down Expand Up @@ -281,7 +348,7 @@ jobs:
if: always()
with:
name: MAA-macos-${{ matrix.arch }}
path: 'install'
path: "install"

android:
needs: meta
Expand Down Expand Up @@ -347,7 +414,7 @@ jobs:
if: always()
with:
name: MAA-android-${{ matrix.arch }}
path: 'install'
path: "install"

nuget_pack:
needs: [meta, windows, ubuntu, macos, android]
Expand Down Expand Up @@ -377,7 +444,7 @@ jobs:
if: always()
with:
name: MAA-nupkgs
path: 'tools/nupkgs/*.nupkg'
path: "tools/nupkgs/*.nupkg"

pip_pack:
needs: [meta, windows, ubuntu, macos, android]
Expand All @@ -399,7 +466,7 @@ jobs:
if: always()
with:
name: MAA-pip-pkgs
path: 'tools/pip_pack/wheel/*.whl'
path: "tools/pip_pack/wheel/*.whl"

nodejs_pack:
needs: [meta, windows, ubuntu, macos, android]
Expand Down Expand Up @@ -436,11 +503,21 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: MAA-nodejs-package
path: 'source/binding/NodeJS/release'
path: "source/binding/NodeJS/release"

release:
if: ${{ needs.meta.outputs.is_release == 'true' && github.repository_id == '632024122' }}
needs: [meta, windows, ubuntu, macos, android, nuget_pack, pip_pack, nodejs_pack]
needs:
[
meta,
windows,
ubuntu,
macos,
android,
nuget_pack,
pip_pack,
nodejs_pack,
]
runs-on: ubuntu-latest
env:
OUTPUT_PUBLISH_FAILED: 'echo "failed=true" >> $GITHUB_OUTPUT && echo "::error::Failed to publish packages"'
Expand Down Expand Up @@ -518,6 +595,10 @@ jobs:
run: |
rm -r assets/MAA-nodejs-package
- name: Remove win-dbg package
run: |
rm -r assets/MAA-win-dbg*
- run: |
cd assets
for f in *; do
Expand All @@ -531,13 +612,12 @@ jobs:
prerelease: ${{ needs.meta.outputs.is_pre_release == 'true' }}

- name: Create issue if failed to publish packages
if: steps.nuget.outputs.failed || steps.pip.outputs.failed || steps.nodejs.outputs.failed
if: steps.nuget.outputs.failed || steps.pip.outputs.failed
uses: actions-cool/issues-helper@v3
with:
actions: 'create-issue'
title: '${{ needs.meta.outputs.tag }} failed to publish packages'
actions: "create-issue"
title: "${{ needs.meta.outputs.tag }} failed to publish packages"
body: |
Please manually publish the following packages:
${{ steps.nuget.outputs.failed && '- nuget @moomiji' || '' }}
${{ steps.pip.outputs.failed && '- pip @MistEO' || '' }}
${{ steps.nodejs.outputs.failed && '- nodejs @neko-para' || '' }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Setup Windows 10 SDK
uses: GuillaumeFalourd/setup-windows10-sdk-action@v2.2
with:
sdk-version: 22621
sdk-version: 26100

- name: Setup Python
uses: actions/setup-python@v5.2.0
Expand Down Expand Up @@ -97,7 +97,7 @@ jobs:
- name: Build MAA
run: |
cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DCMAKE_SYSTEM_VERSION="10.0.22621.0" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON -DBUILD_PIPELINE_TESTING=ON -DBUILD_DLOPEN_TESTING=ON
cmake --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }}" -DMAADEPS_TRIPLET="maa-${{ matrix.arch == 'x86_64' && 'x64' || 'arm64' }}-windows" -DCMAKE_SYSTEM_VERSION="10.0.26100.0" -DMAA_HASH_VERSION='${{ needs.meta.outputs.tag }}' -DBUILD_NODEJS_BINDING=ON -DBUILD_PIPELINE_TESTING=ON -DBUILD_DLOPEN_TESTING=ON
cmake --build build --preset "${{ matrix.arch == 'x86_64' && 'MSVC 2022' || 'MSVC 2022 ARM' }} - Release" -j 16
Expand Down
5 changes: 4 additions & 1 deletion source/MaaFramework/Controller/ControllerAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,10 @@ bool ControllerAgent::recording() const
void ControllerAgent::init_recording()
{
auto recording_dir = GlobalOptionMgr::get_instance().log_dir() / "recording";
std::filesystem::create_directories(recording_dir);
if (std::error_code ec; !std::filesystem::create_directories(recording_dir, ec)) {
LogError << "failed to create_directories" << VAR(recording_dir) << VAR(ec.message());
return;
}
recording_path_ = recording_dir / std::format("maa_recording_{}.txt", format_now_for_filename());
}

Expand Down
13 changes: 11 additions & 2 deletions source/MaaProjectInterface/Impl/Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ void Configurator::save(const std::filesystem::path& user_dir)
{
LogInfo << VAR(user_dir);

std::filesystem::create_directories((user_dir / kConfigFilename).parent_path());
const auto config_path = user_dir / kConfigFilename;
if (std::error_code ec; config_path.has_parent_path() && !std::filesystem::create_directories(config_path.parent_path(), ec)) {
LogError << "failed to create_directories" << VAR(config_path.parent_path()) << VAR(ec.message());
return;
}

std::ofstream ofs(config_path);
if (!ofs.is_open()) {
LogError << "failed to open" << VAR(config_path);
return;
}

std::ofstream ofs(user_dir / kConfigFilename);
ofs << config_.to_json();
}

Expand Down
6 changes: 5 additions & 1 deletion source/MaaToolkit/Config/GlobalOptionConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ bool GlobalOptionConfig::save() const
{
LogInfo;

std::filesystem::create_directories(config_path_.parent_path());
if (std::error_code ec; config_path_.has_parent_path() && !std::filesystem::create_directories(config_path_.parent_path(), ec)) {
LogError << "failed to create_directories" << VAR(config_path_.parent_path()) << VAR(ec.message());
return false;
}

std::ofstream ofs(config_path_, std::ios::out);
if (!ofs.is_open()) {
LogError << "Failed to open config file" << config_path_;
Expand Down
4 changes: 3 additions & 1 deletion source/MaaUtils/Logger/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ void Logger::open()
return;
}

std::filesystem::create_directories(log_dir_);
if (std::error_code ec; !std::filesystem::create_directories(log_dir_, ec)) {
return;
}

std::unique_lock trace_lock(trace_mutex_);
if (ofs_.is_open()) {
Expand Down
3 changes: 1 addition & 2 deletions source/include/Utils/ImageIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ inline cv::Mat imread(const std::string& utf8_path, int flags = cv::IMREAD_COLOR

inline bool imwrite(const std::filesystem::path& path, cv::InputArray img)
{
if (path.has_parent_path() && !std::filesystem::exists(path.parent_path())
&& !std::filesystem::create_directories(path.parent_path())) {
if (std::error_code ec; path.has_parent_path() && !std::filesystem::create_directories(path.parent_path(), ec)) {
return false;
}

Expand Down
32 changes: 18 additions & 14 deletions source/include/Utils/Time.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once

#if defined(__APPLE__) || defined(__ANDROID__)
#define MAA_USE_POSIX_TIME
#endif

#ifdef MAA_USE_POSIX_TIME
#ifdef _WIN32
#include "SafeWindows.hpp"
#else
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
Expand All @@ -22,17 +20,19 @@ MAA_NS_BEGIN

inline std::string format_now()
{
#ifndef MAA_USE_POSIX_TIME
return std::format(
"{}",
std::chrono::current_zone()->to_local(std::chrono::floor<std::chrono::milliseconds>(std::chrono::system_clock::now())));
constexpr std::string_view kFormat = "{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}";

#ifdef _WIN32
SYSTEMTIME sys {};
GetLocalTime(&sys);
return std::format(kFormat, sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
#else
timeval tv = {};
gettimeofday(&tv, nullptr);
time_t nowtime = tv.tv_sec;
tm* tm_info = localtime(&nowtime);
return std::format(
"{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
kFormat,
tm_info->tm_year + 1900,
tm_info->tm_mon,
tm_info->tm_mday,
Expand All @@ -45,22 +45,26 @@ inline std::string format_now()

inline std::string format_now_for_filename()
{
#ifndef MAA_USE_POSIX_TIME
return std::format("{:%Y.%m.%d-%H.%M.%S}", std::chrono::current_zone()->to_local(std::chrono::system_clock::now()));
constexpr std::string_view kFormat = "{:0>4}.{:0>2}.{:0>2}-{:0>2}.{:0>2}.{:0>2}.{}";

#ifdef _WIN32
SYSTEMTIME sys {};
GetLocalTime(&sys);
return std::format(kFormat, sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
#else
timeval tv = {};
gettimeofday(&tv, nullptr);
time_t nowtime = tv.tv_sec;
tm* tm_info = localtime(&nowtime);
return std::format(
"{:0>4}.{:0>2}.{:0>2}-{:0>2}.{:0>2}.{:0>2}.{}",
kFormat,
tm_info->tm_year + 1900,
tm_info->tm_mon,
tm_info->tm_mday,
tm_info->tm_hour,
tm_info->tm_min,
tm_info->tm_sec,
tv.tv_usec);
tv.tv_usec / 1000);
#endif
}

Expand Down

0 comments on commit 11a71a2

Please sign in to comment.