From d854510aa117e7a3ea7b4969b218c56a0b615b07 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 8 Mar 2024 19:09:13 +0100 Subject: [PATCH] Add github actions and update Dockerfile --- .clang-format | 4 +-- .github/workflows/ci.yml | 59 ++++++++++++++++++++++++++++++++++ .github/workflows/pr.yml | 43 +++++++++++++++++++++++++ Dockerfile | 4 +-- README.md | 2 +- source/log.cpp | 2 +- source/wiiu/platform.cpp | 68 +++++++++++++++++++++++++--------------- source/wiiu/version.h | 2 ++ 8 files changed, 151 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/pr.yml create mode 100644 source/wiiu/version.h diff --git a/.clang-format b/.clang-format index 7a4e54f..cba56ee 100644 --- a/.clang-format +++ b/.clang-format @@ -7,9 +7,7 @@ AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: false AlignEscapedNewlinesLeft: false AlignOperands: true -AlignTrailingComments: - Kind: Always - OverEmptyLines: 0 +AlignTrailingComments: true AllowAllParametersOfDeclarationOnNextLine: false AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..078845b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,59 @@ +name: CI-Release + +on: + push: + branches: + - main + +jobs: + clang-format: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source ./include + build-binary: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v3 + - name: create version.h + run: | + git_hash=$(git rev-parse --short "$GITHUB_SHA") + cat < ./source/wiiu/version.h + #pragma once + #define VERSION_EXTRA " (nightly-$git_hash)" + EOF + - name: build binary + run: | + docker build . -t builder + docker run --rm -v ${PWD}:/project builder make + - uses: actions/upload-artifact@master + with: + name: binary + path: "*.wps" + deploy-binary: + needs: build-binary + runs-on: ubuntu-22.04 + steps: + - name: Get environment variables + id: get_repository_name + run: | + echo REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//") >> $GITHUB_ENV + echo DATETIME=$(echo $(date '+%Y%m%d-%H%M%S')) >> $GITHUB_ENV + - uses: actions/download-artifact@master + with: + name: binary + - name: zip artifact + run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip *.wps + - name: Create Release + uses: "softprops/action-gh-release@v1" + with: + tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} + draft: false + prerelease: true + generate_release_notes: true + name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }} + files: | + ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..afb38d9 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,43 @@ +name: CI-PR + +on: [pull_request] + +jobs: + clang-format: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source ./include + check-build-with-logging: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v2 + - name: build binary with logging + run: | + docker build . -t builder + docker run --rm -v ${PWD}:/project builder make DEBUG=VERBOSE + docker run --rm -v ${PWD}:/project builder make clean + docker run --rm -v ${PWD}:/project builder make DEBUG=1 + build-binary: + runs-on: ubuntu-22.04 + needs: clang-format + steps: + - uses: actions/checkout@v3 + - name: create version.h + run: | + git_hash=$(git rev-parse --short "${{ github.event.pull_request.head.sha }}") + cat < ./source/wiiu/version.h + #pragma once + #define VERSION_EXTRA " (nightly-$git_hash)" + EOF + - name: build binary + run: | + docker build . -t builder + docker run --rm -v ${PWD}:/project builder make + - uses: actions/upload-artifact@master + with: + name: binary + path: "*.wps" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0b000a9..8cfa4b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ghcr.io/wiiu-env/devkitppc:20231112 -COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:20230719 /artifacts $DEVKITPRO -COPY --from=ghcr.io/wiiu-env/libmocha:20230621 /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/wiiupluginsystem:0.8.0-dev-20240302-3b5cc2f /artifacts $DEVKITPRO +COPY --from=ghcr.io/wiiu-env/libmocha:20231127 /artifacts $DEVKITPRO WORKDIR project \ No newline at end of file diff --git a/README.md b/README.md index 3317ffc..d0b737f 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ docker run -it --rm -v ${PWD}:/project ftpiiuplugin-builder make clean ## Format the code via docker -`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src -i` +`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./source ./include -i` ## Credits diff --git a/source/log.cpp b/source/log.cpp index e79a6bf..00c2e1d 100644 --- a/source/log.cpp +++ b/source/log.cpp @@ -124,7 +124,7 @@ void drawLog () #ifdef __WIIU__ for (auto &cur : s_messages) { - OSReport ("%s %s\x1b[0m", s_colors[cur.level], cur.message.c_str ()); + OSReport ("ftpiiu plugin: %s %s\x1b[0m", s_colors[cur.level], cur.message.c_str ()); } #else auto it = std::begin (s_messages); diff --git a/source/wiiu/platform.cpp b/source/wiiu/platform.cpp index af63dd5..f329400 100644 --- a/source/wiiu/platform.cpp +++ b/source/wiiu/platform.cpp @@ -19,6 +19,7 @@ // along with this program. If not, see . #include "platform.h" +#include "version.h" #include "IOAbstraction.h" #include "ftpServer.h" @@ -39,16 +40,20 @@ #ifndef CLASSIC #error "Wii U must be built in classic mode" #endif -#define VERSION_FULL "0.1" +#define VERSION "v0.4.1" +#define VERSION_FULL VERSION VERSION_EXTRA -WUPS_PLUGIN_NAME ("ftpd"); -WUPS_PLUGIN_DESCRIPTION ("FTP Server"); +WUPS_PLUGIN_NAME ("ftpiiu"); +WUPS_PLUGIN_DESCRIPTION ("FTP Server based on ftpd"); WUPS_PLUGIN_VERSION (VERSION_FULL); WUPS_PLUGIN_AUTHOR ("mtheall, Maschell"); -WUPS_PLUGIN_LICENSE ("GPL"); +WUPS_PLUGIN_LICENSE ("GPL3"); WUPS_USE_WUT_DEVOPTAB (); -WUPS_USE_STORAGE ("ftpd"); // Unqiue id for the storage api +WUPS_USE_STORAGE ("ftpiiu"); // Unique id for the storage api + +#define DEFAULT_FTPIIU_ENABLED_VALUE true +#define DEFAULT_SYSTEM_FILES_ALLOWED_VALUE false #define FTPIIU_ENABLED_STRING "enabled" #define SYSTEM_FILES_ALLOWED_STRING "systemFilesAllowed" @@ -60,8 +65,8 @@ bool platform::networkVisible () bool platform::networkAddress (SockAddr &addr_) { - struct sockaddr_in addr; - addr.sin_family = AF_INET; + struct sockaddr_in addr = {}; + addr.sin_family = AF_INET; nn::ac::GetAssignedAddress (&addr.sin_addr.s_addr); addr_ = addr; return true; @@ -86,10 +91,10 @@ MochaUtilsStatus MountWrapper (const char *mount, const char *dev, const char *m return res; } -UniqueFtpServer server = nullptr; -bool sSystemFilesAllowed = false; -bool sMochaPathsWereMounted = false; -bool sFTPServerEnabled = true; +UniqueFtpServer server = nullptr; +static bool sSystemFilesAllowed = DEFAULT_SYSTEM_FILES_ALLOWED_VALUE; +static bool sMochaPathsWereMounted = false; +static bool sFTPServerEnabled = DEFAULT_FTPIIU_ENABLED_VALUE; void start_server () { @@ -189,7 +194,7 @@ void stop_server () IOAbstraction::clear (); } -void gFTPServerRunningChanged (ConfigItemBoolean *item, bool newValue) +static void gFTPServerRunningChanged (ConfigItemBoolean *item, bool newValue) { sFTPServerEnabled = newValue; if (!sFTPServerEnabled) @@ -210,7 +215,7 @@ void gFTPServerRunningChanged (ConfigItemBoolean *item, bool newValue) } } -void gSystemFilesAllowedChanged (ConfigItemBoolean *item, bool newValue) +static void gSystemFilesAllowedChanged (ConfigItemBoolean *item, bool newValue) { // DEBUG_FUNCTION_LINE("New value in gFTPServerEnabled: %d", newValue); if (server != nullptr) @@ -264,7 +269,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback (WUPSConfigCategoryHandle r (hostIpAddress >> 16) & 0xFF, (hostIpAddress >> 8) & 0xFF, (hostIpAddress >> 0) & 0xFF, - 5000); + 21); } else { @@ -277,7 +282,7 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback (WUPSConfigCategoryHandle r } catch (std::exception &e) { - OSReport ("Exception T_T : %s\n", e.what ()); + OSReport ("fptiiu plugin: Exception: %s\n", e.what ()); return WUPSCONFIG_API_CALLBACK_RESULT_ERROR; } @@ -286,32 +291,43 @@ WUPSConfigAPICallbackStatus ConfigMenuOpenedCallback (WUPSConfigCategoryHandle r void ConfigMenuClosedCallback () { - OSReport ("ConfigMenuClosedCallback\n"); WUPSStorageAPI::SaveStorage (); } INITIALIZE_PLUGIN () { - WUPSConfigAPIOptionsV1 configOptions = {.name = "ftpd"}; + WUPSConfigAPIOptionsV1 configOptions = {.name = "ftpiiu"}; if (WUPSConfigAPI_Init (configOptions, ConfigMenuOpenedCallback, ConfigMenuClosedCallback) != WUPSCONFIG_API_RESULT_SUCCESS) { - OSFatal ("Failed to init config api"); + OSFatal ("ftpiiu plugin: Failed to init config api"); } - if (WUPSStorageAPI::GetOrStoreDefault (FTPIIU_ENABLED_STRING, sFTPServerEnabled, true) != + WUPSStorageError err; + if ((err = WUPSStorageAPI::GetOrStoreDefault ( + FTPIIU_ENABLED_STRING, sFTPServerEnabled, DEFAULT_FTPIIU_ENABLED_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) { - OSReport ("Failed\n"); + OSReport ("ftpiiu plugin: Failed to get or create item \"%s\": %s (%d)\n", + FTPIIU_ENABLED_STRING, + WUPSStorageAPI_GetStatusStr (err), + err); } - if (WUPSStorageAPI::GetOrStoreDefault ( - SYSTEM_FILES_ALLOWED_STRING, sSystemFilesAllowed, false) != WUPS_STORAGE_ERROR_SUCCESS) + if ((err = WUPSStorageAPI::GetOrStoreDefault (SYSTEM_FILES_ALLOWED_STRING, + sSystemFilesAllowed, + DEFAULT_SYSTEM_FILES_ALLOWED_VALUE)) != WUPS_STORAGE_ERROR_SUCCESS) { - OSReport ("Failed\n"); + OSReport ("ftpiiu plugin: Failed to get or create item \"%s\": %s (%d)\n", + SYSTEM_FILES_ALLOWED_STRING, + WUPSStorageAPI_GetStatusStr (err), + err); } - if (WUPSStorageAPI::SaveStorage () != WUPS_STORAGE_ERROR_SUCCESS) + + if ((err = WUPSStorageAPI::SaveStorage ()) != WUPS_STORAGE_ERROR_SUCCESS) { - OSReport ("Failed\n"); + OSReport ("ftpiiu plugin: Failed to save storage: %s (%d)\n", + WUPSStorageAPI_GetStatusStr (err), + err); } } @@ -372,7 +388,7 @@ public: explicit privateData_t (std::function &&func_) : thread (std::move (func_)) { auto nativeHandle = (OSThread *)thread.native_handle (); - OSSetThreadName (nativeHandle, "ftpd"); + OSSetThreadName (nativeHandle, "ftpiiu"); while (!OSSetThreadAffinity (nativeHandle, OS_THREAD_ATTRIB_AFFINITY_CPU2)) { OSSleepTicks (OSMillisecondsToTicks (16)); diff --git a/source/wiiu/version.h b/source/wiiu/version.h new file mode 100644 index 0000000..66a2c7e --- /dev/null +++ b/source/wiiu/version.h @@ -0,0 +1,2 @@ +#pragma once +#define VERSION_EXTRA "" \ No newline at end of file