Skip to content

Commit d7ad64a

Browse files
chore: add build script for releases (#29)
1 parent b3973f0 commit d7ad64a

File tree

5 files changed

+146
-3
lines changed

5 files changed

+146
-3
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
name: Build
1+
name: Build and Release
22

33
on:
44
pull_request:
55
types: [opened, reopened, synchronize, closed]
66
branches:
77
- main
8+
workflow_dispatch:
9+
inputs:
10+
prerelease:
11+
description: 'Is this a pre-release?'
12+
required: true
13+
type: boolean
14+
default: false
15+
16+
# Add permissions needed for creating releases
17+
permissions:
18+
contents: write
19+
pull-requests: write
820

921
jobs:
1022
install:
@@ -13,6 +25,8 @@ jobs:
1325
steps:
1426
- name: Checkout repository
1527
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Fetch all history for proper commit counting
1630

1731
- name: Set up Python
1832
uses: actions/setup-python@v4
@@ -63,5 +77,29 @@ jobs:
6377
Start-Process -FilePath "xbox360_sdk.exe" -ArgumentList "/U", "/T full" -Wait
6478
6579
- name: Build Plugin
80+
id: build
6681
run: |
67-
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe "iw3xe.sln"
82+
# Get commit count
83+
$commitCount = git rev-list --count HEAD
84+
echo "BUILD_NUMBER=$commitCount" >> $env:GITHUB_OUTPUT
85+
86+
# Build using build.py which will use the same commit count
87+
python build.py
88+
89+
echo "ZIP_FILE=iw3xe-${commitCount}.zip" >> $env:GITHUB_OUTPUT
90+
shell: pwsh
91+
92+
- name: Create Release
93+
if: github.event_name == 'workflow_dispatch'
94+
id: create_release
95+
uses: softprops/action-gh-release@v1
96+
with:
97+
tag_name: v${{ steps.build.outputs.BUILD_NUMBER }}
98+
name: Release v${{ steps.build.outputs.BUILD_NUMBER }}
99+
draft: false
100+
prerelease: ${{ github.event.inputs.prerelease }}
101+
generate_release_notes: true
102+
files: |
103+
build/${{ steps.build.outputs.ZIP_FILE }}
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bld/
3131
[Oo]bj/
3232
[Ll]og/
3333
[Ll]ogs/
34+
build/
3435

3536
# Visual Studio 2015/2017 cache/options directory
3637
.vs/

build.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import os
2+
import subprocess
3+
import shutil
4+
5+
# Configuration
6+
SOLUTION_FILE = "iw3xe.sln"
7+
MSBUILD_PATH = r"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
8+
BINARY_PATH = r"build\Release\bin\iw3xe.xex"
9+
STAGING_DIR = r"build\staging"
10+
RESOURCES_PATH = r"resources\xenia"
11+
GAME_TITLE_ID = "415607E6"
12+
13+
14+
def count_commits():
15+
try:
16+
result = subprocess.run(
17+
["git", "rev-list", "--count", "HEAD"],
18+
capture_output=True,
19+
text=True,
20+
check=True,
21+
)
22+
23+
# Get the commit count from the command output
24+
commit_count = result.stdout.strip()
25+
26+
print(f"Total number of commits in the current branch: {commit_count}")
27+
return commit_count
28+
except Exception as e:
29+
print(f"An error occurred: {e}")
30+
exit(1)
31+
32+
33+
# Ensure MSBuild exists
34+
if not os.path.exists(MSBUILD_PATH):
35+
print(f"ERROR: MSBuild not found at {MSBUILD_PATH}")
36+
exit(1)
37+
38+
VERSION_HEADER_PATH = r"src\version.h"
39+
BUILD_NUMBER = count_commits()
40+
41+
print("Generating version.h with build metadata...")
42+
with open(VERSION_HEADER_PATH, "w") as version_file:
43+
version_file.write("// Auto-generated version header\n")
44+
version_file.write("#pragma once\n\n")
45+
version_file.write(f"#define BUILD_NUMBER {BUILD_NUMBER}\n")
46+
47+
result = subprocess.run([MSBUILD_PATH, SOLUTION_FILE], stdout=subprocess.DEVNULL)
48+
if result.returncode != 0:
49+
print("ERROR: Build failed.")
50+
exit(result.returncode)
51+
else:
52+
print("Build succeeded.")
53+
54+
print("Creating clean staging directory...")
55+
if os.path.exists(STAGING_DIR):
56+
shutil.rmtree(STAGING_DIR)
57+
os.makedirs(STAGING_DIR, exist_ok=True)
58+
59+
60+
if os.path.exists(RESOURCES_PATH):
61+
# Copy the entire xenia directory and its contents to the staging directory
62+
shutil.copytree(RESOURCES_PATH, os.path.join(STAGING_DIR, "xenia"))
63+
print("Resources copied successfully")
64+
else:
65+
print(f"Resources directory not found at {RESOURCES_PATH}")
66+
exit(1)
67+
68+
print("Copying binary to staging directory...")
69+
shutil.copy2(
70+
BINARY_PATH,
71+
os.path.join(STAGING_DIR, "xenia", "plugins", GAME_TITLE_ID, "iw3xe.xex"),
72+
)
73+
74+
75+
print("Copying mods/codjumper to staging/raw directory...")
76+
MODS_PATH = r"mods\codjumper"
77+
RAW_DIR = os.path.join(STAGING_DIR, "raw")
78+
if os.path.exists(MODS_PATH):
79+
os.makedirs(RAW_DIR, exist_ok=True)
80+
shutil.copytree(MODS_PATH, RAW_DIR, dirs_exist_ok=True)
81+
print("Mods copied successfully to staging/raw")
82+
else:
83+
print(f"Mods directory not found at {MODS_PATH}")
84+
exit(1)
85+
86+
87+
PROJECT_NAME = "iw3xe"
88+
ZIP_FILE_NAME = f"{PROJECT_NAME}-{BUILD_NUMBER}.zip"
89+
STAGING_ZIP_PATH = os.path.join("build", ZIP_FILE_NAME)
90+
91+
print("Zipping the staging folder...")
92+
shutil.make_archive(
93+
base_name=STAGING_ZIP_PATH.replace(".zip", ""), format="zip", root_dir=STAGING_DIR
94+
)
95+
print(f"Staging folder zipped successfully to {STAGING_ZIP_PATH}")

src/game/mp_main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../detour.h"
1616
#include "../filesystem.h"
1717
#include "../xboxkrnl.h"
18+
#include "../version.h"
1819

1920
// Structure to hold data for the active keyboard request
2021
struct KeyboardRequest
@@ -1800,11 +1801,15 @@ namespace mp
18001801
{
18011802
const char *branding = "IW3xe";
18021803
const char *build = __DATE__ " " __TIME__;
1804+
char brandingWithBuild[256];
1805+
1806+
// Combine branding and build number
1807+
_snprintf(brandingWithBuild, sizeof(brandingWithBuild), "%s (Build %d)", branding, BUILD_NUMBER);
18031808

18041809
static Font_s *font = (Font_s *)R_RegisterFont("fonts/consoleFont");
18051810
float color[4] = {1.0, 1.0, 1.0, 0.4};
18061811

1807-
R_AddCmdDrawText(branding, 256, font, 10, 20, 1.0, 1.0, 0.0, color, 0);
1812+
R_AddCmdDrawText(brandingWithBuild, 256, font, 10, 20, 1.0, 1.0, 0.0, color, 0);
18081813
R_AddCmdDrawText(build, 256, font, 10, 40, 1.0, 1.0, 0.0, color, 0);
18091814
}
18101815

src/version.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Auto-generated version header
2+
#pragma once
3+
4+
#define BUILD_NUMBER 0

0 commit comments

Comments
 (0)