From ca2a4c3ae51185a775c1c2bdfce9d30d380e36bb Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Wed, 13 Mar 2024 10:47:39 -0700 Subject: [PATCH] actions: use PackageHaxelib script --- .github/workflows/haxelib.yml | 18 +++++----- haxelib/PackageHaxelib.hx | 67 ++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/.github/workflows/haxelib.yml b/.github/workflows/haxelib.yml index cad5b24..cb2004f 100644 --- a/.github/workflows/haxelib.yml +++ b/.github/workflows/haxelib.yml @@ -11,15 +11,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/upload-artifact@v3 + - uses: actions/checkout@v4 + - uses: krdlab/setup-haxe@v1 + with: + haxe-version: 4.3.4 + - name: Package Haxelib + working-directory: haxelib + run: haxe haxelib.hxml + - uses: actions/upload-artifact@v4 with: name: feathersui-validators-haxelib - path: | - src/ - haxelib.json - README.md - LICENSE - NOTICE - CHANGELOG.md + path: bin/haxelib/ if-no-files-found: error diff --git a/haxelib/PackageHaxelib.hx b/haxelib/PackageHaxelib.hx index da6dbe0..0d96a29 100644 --- a/haxelib/PackageHaxelib.hx +++ b/haxelib/PackageHaxelib.hx @@ -1,6 +1,6 @@ /* Feathers UI - Copyright 2020 Bowler Hat LLC. All Rights Reserved. + Copyright 2024 Bowler Hat LLC. All Rights Reserved. This program is free software. You can redistribute and/or modify it in accordance with the terms of the accompanying license agreement. @@ -17,13 +17,21 @@ import sys.io.File; class PackageHaxelib { public static function main():Void { + final destDir = FileSystem.absolutePath("../bin/haxelib"); + if (FileSystem.exists(destDir)) { + deleteDir(destDir); + } + FileSystem.createDirectory(destDir); + + copyFile(FileSystem.absolutePath("../haxelib.json"), destDir); + copyFile(FileSystem.absolutePath("../README.md"), destDir); + copyFile(FileSystem.absolutePath("../CHANGELOG.md"), destDir); + copyFile(FileSystem.absolutePath("../LICENSE"), destDir); + copyFile(FileSystem.absolutePath("../NOTICE"), destDir); + copyDir(FileSystem.absolutePath("../src"), destDir); + var entries = new List(); - addFile(FileSystem.absolutePath("../haxelib.json"), entries); - addFile(FileSystem.absolutePath("../README.md"), entries); - addFile(FileSystem.absolutePath("../CHANGELOG.md"), entries); - addFile(FileSystem.absolutePath("../LICENSE"), entries); - addFile(FileSystem.absolutePath("../NOTICE"), entries); - addDirectory(FileSystem.absolutePath("../src"), true, entries); + addDirectory(destDir, entries); var jsonContent = File.getContent("../haxelib.json"); var json = Json.parse(jsonContent); @@ -44,12 +52,47 @@ class PackageHaxelib { zip.write(entries); } + private static function copyFile(filePath:String, destDir:String):Void { + var fileName = Path.withoutDirectory(filePath); + File.copy(filePath, Path.join([destDir, fileName])); + } + + private static function copyDir(directoryPath:String, destParentDir:String):Void { + var dirName = Path.withoutDirectory(directoryPath); + var destDirPath = Path.join([destParentDir, dirName]); + FileSystem.createDirectory(destDirPath); + for (fileName in FileSystem.readDirectory(directoryPath)) { + var filePath = Path.join([directoryPath, fileName]); + if (FileSystem.isDirectory(filePath)) { + copyDir(filePath, destDirPath); + } else { + // extra files on macOS that should be skipped + if (fileName == ".DS_Store") { + continue; + } + copyFile(filePath, destDirPath); + } + } + } + + private static function deleteDir(directoryPath:String):Void { + for (fileName in FileSystem.readDirectory(directoryPath)) { + var filePath = Path.join([directoryPath, fileName]); + if (FileSystem.isDirectory(filePath)) { + deleteDir(filePath); + } else { + FileSystem.deleteFile(filePath); + } + } + FileSystem.deleteDirectory(directoryPath); + } + private static function addFile(filePath:String, result:List):Void { addFileInternal(filePath, Path.directory(filePath), result); } - private static function addDirectory(directoryPath:String, recursive:Bool, result:List):Void { - addDirectoryInternal(directoryPath, Path.directory(directoryPath), recursive, result); + private static function addDirectory(directoryPath:String, result:List):Void { + addDirectoryInternal(directoryPath, directoryPath, result); } private static function addFileInternal(filePath:String, relativeToDirPath:String, result:List):Void { @@ -66,13 +109,11 @@ class PackageHaxelib { }); } - private static function addDirectoryInternal(directoryPath:String, relativeTo:String, recursive:Bool, result:List):Void { + private static function addDirectoryInternal(directoryPath:String, relativeTo:String, result:List):Void { for (fileName in FileSystem.readDirectory(directoryPath)) { var filePath = Path.join([directoryPath, fileName]); if (FileSystem.isDirectory(filePath)) { - if (recursive) { - addDirectoryInternal(filePath, relativeTo, true, result); - } + addDirectoryInternal(filePath, relativeTo, result); } else { addFileInternal(filePath, relativeTo, result); }