diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index ff22d80..a8c062c 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -1,42 +1,165 @@ -name: 🪟 Windows Build +name: Automated Builds on: - workflow_call: + workflow_dispatch: + pull_request: + branches: + - main + paths-ignore: + - '**.md' + - '.github/ISSUE_TEMPLATE/*' + - '.docs/changelog' + push: + branches: + - main + paths-ignore: + - '**.md' + - '.github/ISSUE_TEMPLATE/*' + - '.docs/changelog' jobs: - windows-loader: - name: "Build" - runs-on: ubuntu-latest - timeout-minutes: 60 + prepare-source: + name: ⚙️ Prepare Source + runs-on: ubuntu-22.04 + outputs: + release_version: ${{ steps.get_version.outputs.RELEASE_VERSION }} + release_tag: ${{ steps.get_version.outputs.RELEASE_TAG }} steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Download version.h artifact - uses: actions/download-artifact@v4 - with: - name: version-file - path: src/lindbergh/ + - name: Extract Version and Update version.h + id: get_version + run: | + CHANGELOG_FILE="./docs/changelog" + VERSION_FILE="src/loader/version.h" + if [[ ! -f "$CHANGELOG_FILE" ]]; then + echo "Error: Changelog file '$CHANGELOG_FILE' not found." + exit 1 + fi + VERSION=$(awk '/^## \[/ { match($0, /\[([^]]+)\]/, arr); print arr[1]; exit }' "$CHANGELOG_FILE") + if [[ -z "$VERSION" ]]; then + echo "Error: Could not find version in '$CHANGELOG_FILE'. Expected format like '## [X.Y.Z]' near the top." + exit 1 + fi + echo "Found version: $VERSION" + MAJOR=$(echo $VERSION | cut -d. -f1) + MINOR=$(echo $VERSION | cut -d. -f2) + UPDATE=$(echo $VERSION | cut -d. -f3) + if [ -z "$UPDATE" ]; then + UPDATE=0 + fi + if [[ ! -f "$VERSION_FILE" ]]; then + echo "Error: Version file '$VERSION_FILE' not found." + exit 1 + fi + sed -i "s/\(#define MAJOR_VERSION \).*/\1$MAJOR/" "$VERSION_FILE" + sed -i "s/\(#define MINOR_VERSION \).*/\1$MINOR/" "$VERSION_FILE" + sed -i "s/\(#define UPDATE_VERSION \).*/\1$UPDATE/" "$VERSION_FILE" + echo "Updated $VERSION_FILE with version $MAJOR.$MINOR.$UPDATE" + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "RELEASE_TAG=v$VERSION" >> $GITHUB_OUTPUT - - name: Cache APT packages - uses: actions/cache@v4 - with: - path: /var/cache/apt/archives - key: ${{ runner.os }}-apt-${{ hashFiles('**/install-packages.sh') }} - restore-keys: | - ${{ runner.os }}-apt- + - name: Upload version.h artifact + uses: actions/upload-artifact@v4 + with: + name: version-file + path: src/loader/version.h - - name: Install Packages - run: scripts/windows/install-packages.sh + linux-build: + name: 🐧 Linux Build + needs: prepare-source + uses: "./.github/workflows/linux-build.yml" - - name: Compile Build for Windows - shell: bash - run: scripts/windows/windows-build.sh + windows-build: + name: 🪟 Windows Build + needs: prepare-source + uses: "./.github/workflows/windows-build.yml" - - name: Upload linuxloader-win32.zip artifact - uses: actions/upload-artifact@v4 - with: - name: "windows-build" - path: "linuxloader-win32.zip" + create-release: + name: 📤 Create Release and Notify + needs: [linux-build, windows-build, prepare-source] + runs-on: ubuntu-22.04 + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: ./artifacts/ + + - name: Display Downloaded Artifacts + run: find ./artifacts/ + + - name: Parse Changelog and Save to File + id: changelog + run: | + VERSION='${{ needs.prepare-source.outputs.release_version }}' + awk -v version="$VERSION" ' + $0 ~ "^## \\[" version "\\]" { in_section=1; next } + /^## / && in_section { exit } + in_section { print } + ' ./docs/changelog > RELEASENOTES.md + echo "notes_file=RELEASENOTES.md" >> $GITHUB_OUTPUT + + - name: Install GitHub CLI + if: env.ACT == 'true' + run: | + type -p curl >/dev/null || (sudo apt-get update && sudo apt-get install curl -y) + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ + && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ + && sudo apt-get update \ + && sudo apt-get install gh -y + - name: Create Release with GitHub CLI + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create ${{ needs.prepare-source.outputs.release_tag }} \ + --title "Build ${{ needs.prepare-source.outputs.release_tag }}" \ + --notes-file ${{ steps.changelog.outputs.notes_file }} \ + ./artifacts/linux-build/linuxloader-linux.tar.gz \ + ./artifacts/linux-appimage/linuxloader.AppImage \ + ./artifacts/windows-build/linuxloader-win32.zip + - name: Notify Discord of New Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Fetch the asset details + ASSETS_JSON=$(gh release view ${{ needs.prepare-source.outputs.release_tag }} --json assets) + + # Extract each URL + ZIP_URL=$(echo "$ASSETS_JSON" | jq -r '.assets[] | select(.name=="linuxloader-win32.zip") | .url') + APPIMAGE_URL=$(echo "$ASSETS_JSON" | jq -r '.assets[] | select(.name=="linuxloader.AppImage") | .url') + TAR_URL=$(echo "$ASSETS_JSON" | jq -r '.assets[] | select(.name=="linuxloader-linux.tar.gz") | .url') + + # Get the changelog body (no need to escape it for jq) + CHANGELOG_BODY=$(cat ${{ steps.changelog.outputs.notes_file }} | head -c 2000) + + # Use jq to build the JSON payload and pipe it to curl + jq -n \ + --arg content "A new LinuxLoader build **v${{ needs.prepare-source.outputs.release_version }}** has been released!" \ + --arg changelog "$CHANGELOG_BODY" \ + --arg zip_url "$ZIP_URL" \ + --arg appimage_url "$APPIMAGE_URL" \ + --arg tar_url "$TAR_URL" \ + '{ + "username": "Build Bot", + "content": $content, + "embeds": [{ + "description": $changelog, + "color": 5814783, + "fields": [ + { + "name": "Downloads", + "value": "[Windows Build Download](\($zip_url))\n[AppImage Download](\($appimage_url))\n[Linux Build Download](\($tar_url))" + } + ] + }] + }' | curl -X POST -H "Content-Type: application/json" -d @- "${{ secrets.DISCORD_WEBHOOK_URL }}" diff --git a/src/loader/config/config.c b/src/loader/config/config.c index cfed5e5..e0514ad 100644 --- a/src/loader/config/config.c +++ b/src/loader/config/config.c @@ -314,8 +314,8 @@ void applyIniConfig(EmulatorConfig *config, const IniConfig *ini) config->boostRenderRes = getInt(ini, "Display", "BOOST_RENDER_RES", config->boostRenderRes); config->fullscreen = getInt(ini, "Display", "FULLSCREEN", config->fullscreen); config->borderEnabled = getInt(ini, "Display", "BORDER_ENABLED", config->borderEnabled); - config->whiteBorderPercentage = getInt(ini, "Display", "WHITE_BORDER_PERCENTAGE", config->whiteBorderPercentage * 100) / 100.0f; - config->blackBorderPercentage = getInt(ini, "Display", "BLACK_BORDER_PERCENTAGE", config->blackBorderPercentage * 100) / 100.0f; + config->whiteBorderPercentage = getFloat(ini, "Display", "WHITE_BORDER_PERCENTAGE", config->whiteBorderPercentage * 100.0f) / 100.0f; + config->blackBorderPercentage = getFloat(ini, "Display", "BLACK_BORDER_PERCENTAGE", config->blackBorderPercentage * 100.0f) / 100.0f; config->keepAspectRatio = getInt(ini, "Display", "KEEP_ASPECT_RATIO", config->keepAspectRatio); config->hideCursor = getInt(ini, "Display", "HIDE_CURSOR", config->hideCursor); diff --git a/src/loader/config/configIni.c b/src/loader/config/configIni.c index c0ad5a8..d418e22 100644 --- a/src/loader/config/configIni.c +++ b/src/loader/config/configIni.c @@ -30,10 +30,10 @@ int createDefaultIni(const char *filePath) fprintf(file, "# Set to true if you\'d like to add a border for optical light gun tracking\n"); fprintf(file, "BORDER_ENABLED = %s\n\n", defaults.borderEnabled ? "true" : "false"); fprintf(file, "# Set the thickness of the white border as a percentage of the width of the screen\n"); - fprintf(file, "WHITE_BORDER_PERCENTAGE = %.0f\n\n", defaults.whiteBorderPercentage * 100); + fprintf(file, "WHITE_BORDER_PERCENTAGE = %.1f\n\n", defaults.whiteBorderPercentage * 100.0f); fprintf(file, "# Set the thickness of the black border which sits around the\n"); fprintf(file, "# white border as a percentage of the width of the screen\n"); - fprintf(file, "BLACK_BORDER_PERCENTAGE = %.0f\n\n", defaults.blackBorderPercentage * 100); + fprintf(file, "BLACK_BORDER_PERCENTAGE = %.1f\n\n", defaults.blackBorderPercentage * 100.0f); fprintf(file, "# Set to keep the aspect ratio in games like Sega Race TV Primeval Hunt and LGJ-SP\n"); fprintf(file, "KEEP_ASPECT_RATIO = %s\n\n", defaults.keepAspectRatio ? "true" : "false"); fprintf(file, "# Set to true to enable the mouse pointer/Cursor\nHIDE_CURSOR = %s\n\n", defaults.hideCursor ? "true" : "false");