Skip to content

Commit 246c2de

Browse files
authored
workflow probably
1 parent 6655997 commit 246c2de

7 files changed

Lines changed: 446 additions & 9 deletions

File tree

.github/workflows/main.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
buildWindows:
13+
runs-on: windows-latest
14+
15+
steps:
16+
- uses: actions/checkout@main
17+
18+
- uses: krdlab/setup-haxe@master
19+
with:
20+
haxe-version: 4.3.7
21+
22+
- name: Restore Previous Cache
23+
id: cache-build-restore
24+
uses: actions/cache/restore@main
25+
with:
26+
path: |
27+
.haxelib/
28+
export/debug/windows/haxe/
29+
export/debug/windows/obj/
30+
key: cache-windows-debug
31+
32+
- name: Set Cache Status
33+
id: cache-status
34+
run: echo CACHE_HIT=${{ steps.cache-build-restore.outputs.cache-hit }} | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8
35+
shell: powershell
36+
37+
- name: Installing Libraries
38+
run: haxe --interp -cp ./actions/libs-installer -D analyzer-optimize -main Main
39+
40+
- name: Create Version Tag
41+
run: echo "${{github.run_id}}" > VERSION
42+
43+
- name: Compile
44+
run: haxelib run lime build windows -debug
45+
46+
- name: Clear Previous Cache
47+
uses: actions/github-script@main
48+
with:
49+
script: await require('./actions/cache/clear-cache.js')({github, context}, 'cache-windows-debug');
50+
51+
- name: Save Current Cache
52+
uses: actions/cache@main
53+
with:
54+
key: cache-windows-debug
55+
path: |
56+
.haxelib/
57+
export/debug/windows/haxe/
58+
export/debug/windows/obj/
59+
restore-keys: |
60+
cache-windows-debug
61+
62+
- name: Upload Artifact
63+
uses: actions/upload-artifact@main
64+
with:
65+
name: windowsBuild
66+
path: export/debug/windows/bin

.github/workflows/pages.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: github-pages
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
pages: write
14+
id-token: write
15+
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
jobs:
21+
build:
22+
concurrency: ci-${{ github.ref }}
23+
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@main
28+
29+
- uses: krdlab/setup-haxe@master
30+
with:
31+
haxe-version: 4.3.7
32+
33+
- name: Install Haxe Libraries
34+
run: |
35+
haxelib setup ~/haxelib
36+
haxelib install hxcpp > /dev/null
37+
haxelib install lime
38+
haxelib install openfl
39+
haxelib install flixel
40+
haxelib install flixel-addons
41+
haxelib install hscript
42+
haxelib git polymod https://github.com/larsiusprime/polymod scripting-updates
43+
haxelib git thx.core https://github.com/fponticelli/thx.core.git
44+
haxelib install thx.semver
45+
haxelib git jsonpath https://github.com/EliteMasterEric/jsonpath.git
46+
haxelib install jsonpatch
47+
haxelib install hxgamemode
48+
haxelib install hxdiscord_rpc
49+
haxelib install hxcpp-debug-server
50+
haxelib install extension-androidtools
51+
haxelib install dox
52+
haxelib install format
53+
haxelib list
54+
mkdir pages
55+
56+
- name: Create Documentation Site
57+
run: |
58+
chmod +x docs/docs.sh
59+
docs/docs.sh
60+
61+
- name: github-actions deploy
62+
uses: JamesIves/github-pages-deploy-action@v4
63+
with:
64+
folder: pages

actions/cache/clear-cache.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = async ({ github, context }, cacheKey) => {
2+
try {
3+
const caches = await github.rest.actions.getActionsCacheList({
4+
owner: context.repo.owner,
5+
repo: context.repo.repo,
6+
});
7+
8+
let cacheFound = false;
9+
10+
for (const cache of caches.data.actions_caches) {
11+
if (cache.key === cacheKey) {
12+
console.log(`Clearing ${cache.key}...`);
13+
14+
await github.rest.actions.deleteActionsCacheById({
15+
owner: context.repo.owner,
16+
repo: context.repo.repo,
17+
cache_id: cache.id,
18+
});
19+
20+
console.log(`Previous Cache Cleared!`);
21+
cacheFound = true;
22+
break;
23+
}
24+
}
25+
26+
if (!cacheFound) {
27+
console.log(`Cache key not found: ${cacheKey}`);
28+
}
29+
} catch (error) {
30+
console.log(error.message);
31+
}
32+
};

actions/libs-installer/Main.hx

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
import sys.FileSystem;
2+
import sys.io.File;
3+
import haxe.Json;
4+
5+
/**
6+
* Represents the configuration structure for the HMM tool, containing an array of library dependencies.
7+
*/
8+
typedef HmmConfig =
9+
{
10+
dependencies:Array<LibraryConfig>
11+
}
12+
13+
/**
14+
* Represents the configuration for a single library, including its name, type, version, directory, reference, and URL.
15+
*/
16+
typedef LibraryConfig =
17+
{
18+
name:String,
19+
type:String,
20+
?version:String,
21+
?dir:String,
22+
?ref:String,
23+
?url:String
24+
}
25+
26+
/**
27+
* The Main class is designed specifically for use with GitHub Actions.
28+
* Its purpose is to install libraries specified in a configuration file (`haxelibs.json`)
29+
* without their dependencies.
30+
*/
31+
class Main
32+
{
33+
/**
34+
* The main function is the entry point of the program.
35+
* It checks for the existence of the `.haxelib` directory, creating it if it does not exist.
36+
* Then it reads the `haxelibs.json` configuration file, parses it, and installs each library
37+
* according to its specified type, using the appropriate commands while skipping dependencies.
38+
*/
39+
public static function main():Void
40+
{
41+
// Ensure the .haxelib directory exists
42+
if (!FileSystem.exists('.haxelib'))
43+
runCommand(['haxelib', 'newrepo', '--quiet', '--never']);
44+
45+
// Read and parse the hmm.json configuration file
46+
final config:HmmConfig = Json.parse(File.getContent('./haxelibs.json'));
47+
48+
// Options to run with the commands
49+
final options:Array<String> = ['--quiet', '--never', '--skip-dependencies'];
50+
51+
// Iterate over each library dependency in the configuration
52+
for (lib in config.dependencies)
53+
{
54+
switch (lib.type)
55+
{
56+
case 'haxelib':
57+
// Prepare the haxelib install command arguments
58+
final args:Array<String> = ['haxelib', 'install'];
59+
60+
args.push(lib.name);
61+
62+
if (lib.version != null)
63+
args.push(lib.version);
64+
65+
// Execute the haxelib install command
66+
runCommand(args.concat(options));
67+
case 'git':
68+
// Prepare the haxelib git command arguments
69+
final args:Array<String> = ['haxelib', 'git'];
70+
71+
args.push(lib.name);
72+
args.push(lib.url);
73+
74+
if (lib.ref != null)
75+
args.push(lib.ref);
76+
77+
// Execute the haxelib git command
78+
runCommand(args.concat(options));
79+
}
80+
}
81+
82+
// List installed haxelib packages
83+
runCommand(['haxelib', 'list']);
84+
}
85+
86+
/**
87+
* Executes a system command with the provided arguments.
88+
* @param args The command and its arguments to be executed.
89+
*/
90+
public static function runCommand(args:Array<String>):Void
91+
{
92+
final command:String = args.join(' ');
93+
94+
if (command != AnsiColors.yellow(command))
95+
Sys.println(AnsiColors.yellow(command));
96+
97+
Sys.command(args.shift(), args);
98+
}
99+
}
100+
101+
/**
102+
* Utility class for applying ANSI color codes to strings for terminal output.
103+
* @see https://github.com/andywhite37/hmm/blob/master/src/hmm/utils/AnsiColors.hx
104+
*/
105+
class AnsiColors
106+
{
107+
/**
108+
* Colors the input string red.
109+
* @param input The input string.
110+
* @return The colored string.
111+
*/
112+
public static inline function red(input:String):String
113+
{
114+
return color(input, Red);
115+
}
116+
117+
/**
118+
* Colors the input string green.
119+
* @param input The input string.
120+
* @return The colored string.
121+
*/
122+
public static inline function green(input:String):String
123+
{
124+
return color(input, Green);
125+
}
126+
127+
/**
128+
* Colors the input string yellow.
129+
* @param input The input string.
130+
* @return The colored string.
131+
*/
132+
public static inline function yellow(input:String):String
133+
{
134+
return color(input, Yellow);
135+
}
136+
137+
/**
138+
* Colors the input string blue.
139+
* @param input The input string.
140+
* @return The colored string.
141+
*/
142+
public static inline function blue(input:String):String
143+
{
144+
return color(input, Blue);
145+
}
146+
147+
/**
148+
* Colors the input string magenta.
149+
* @param input The input string.
150+
* @return The colored string.
151+
*/
152+
public static inline function magenta(input:String):String
153+
{
154+
return color(input, Magenta);
155+
}
156+
157+
/**
158+
* Colors the input string cyan.
159+
* @param input The input string.
160+
* @return The colored string.
161+
*/
162+
public static inline function cyan(input:String):String
163+
{
164+
return color(input, Cyan);
165+
}
166+
167+
/**
168+
* Colors the input string gray.
169+
* @param input The input string.
170+
* @return The colored string.
171+
*/
172+
public static inline function gray(input:String):String
173+
{
174+
return color(input, Gray);
175+
}
176+
177+
/**
178+
* Colors the input string white.
179+
* @param input The input string.
180+
* @return The colored string.
181+
*/
182+
public static inline function white(input:String):String
183+
{
184+
return color(input, White);
185+
}
186+
187+
/**
188+
* Removes any color from the input string.
189+
* @param input The input string.
190+
* @return The uncolored string.
191+
*/
192+
public static inline function none(input:String):String
193+
{
194+
return color(input, None);
195+
}
196+
197+
/**
198+
* Applies the specified ANSI color code to the input string.
199+
* @param input The input string.
200+
* @param ansiColor The ANSI color code.
201+
* @return The colored string.
202+
*/
203+
public static inline function color(input:String, ansiColor:AnsiColor):String
204+
{
205+
return #if sys '$ansiColor$input${AnsiColor.None}' #else input #end;
206+
}
207+
}
208+
209+
/**
210+
* Enum abstract representing ANSI color codes.
211+
*/
212+
enum abstract AnsiColor(String) from String to String
213+
{
214+
var Black = '\033[0;30m';
215+
var Red = '\033[0;31m';
216+
var Green = '\033[0;32m';
217+
var Yellow = '\033[0;33m';
218+
var Blue = '\033[0;34m';
219+
var Magenta = '\033[0;35m';
220+
var Cyan = '\033[0;36m';
221+
var Gray = '\033[0;37m';
222+
var White = '\033[1;37m';
223+
var None = '\033[0;0m';
224+
}

0 commit comments

Comments
 (0)