diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index ead482b54..c44816997 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -12,7 +12,9 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: Aidan63/setup-haxe@3d3101bcd0a2001699fc8295f4d9eddd0724d3e9 with: @@ -22,16 +24,20 @@ jobs: run: | haxe -version haxelib dev hxcpp . + + - name: 'Get Previous tag' + id: previoustag + uses: "WyriHaximus/github-action-get-previous-tag@v1" + with: + prefix: v - name: Set Version - run: haxe -cp tools/version --run Write ${{github.run_number}} > version.env - + run: haxe -p tools/version --run Write ${{ steps.previoustag.outputs.tag }} > version.env - name: Build Tool run: | cd tools/hxcpp haxe compile.hxml - - name: Check XCode if: startsWith(matrix.os,'macos') @@ -49,7 +55,7 @@ jobs: - name: Archive Linux Results if: startsWith(matrix.os,'ubuntu') - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linux-64 path: | @@ -75,7 +81,7 @@ jobs: - name: Archive Windows Results if: startsWith(matrix.os,'windows') - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: windows-64 path: | @@ -83,7 +89,7 @@ jobs: - name: Archive Mac Results if: startsWith(matrix.os,'macos') - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mac-64 path: | @@ -94,19 +100,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Download Linux - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: linux-64 path: hxcpp - name: Download Mac - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: mac-64 path: hxcpp/bin/Mac64/ - name: Download Windows - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: windows-64 path: hxcpp/bin/Windows64/ @@ -126,23 +132,11 @@ jobs: zip -r hxcpp-${{ env.hxcpp_release }}.zip hxcpp-${{ env.hxcpp_release }} - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ncipollo/release-action@v1 with: - tag_name: v${{ env.hxcpp_release }} - release_name: Release ${{ env.hxcpp_release }} + tag: v${{ env.hxcpp_release }} + commit: ${{ github.head_ref }} + name: Release ${{ env.hxcpp_release }} draft: false prerelease: false - - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./hxcpp-${{ env.hxcpp_release }}.zip - asset_name: hxcpp-${{ env.hxcpp_release }}.zip - asset_content_type: application/zip \ No newline at end of file + artifacts: ./hxcpp-${{ env.hxcpp_release }}.zip \ No newline at end of file diff --git a/tools/version/Write.hx b/tools/version/Write.hx index e4eaec13c..b1e34526e 100644 --- a/tools/version/Write.hx +++ b/tools/version/Write.hx @@ -1,58 +1,63 @@ +import haxe.Exception; +import haxe.Json; import sys.io.File; +using StringTools; + +typedef Haxelib = { + var version: String; +} + class Write { public static function main() { - var args = Sys.args(); - // AL NOTE: this "30 +" is a bodge around some CI stuff. - // Usually the ever incrementing CI run number is provided as the argument, but this ID is per github workflow. - // So when the release ci yml moved file the number reset to zero and we started overwriting previous releases. - // For now just append 30 since the previous release was 25 or something. - // - // This will need to be revisited when anything other than the last number increases as you would end up with - // something like 5.0.42 instead of 5.0.0. - var buildNumber = 30 + Std.parseInt(args[0]); - if (buildNumber<1 || buildNumber==null) - throw "Usage: Write buildNumber"; - - - var jsonFile = "haxelib.json"; - var lines = File.getContent(jsonFile).split("\n"); - var idx = 0; - var versionMatch = ~/(.*"version"\s*:\s*")(.*)(".*)/; - var found = false; - var newVersion = ""; - while(idx previousMajor || newMinor > previousMinor) + { + json.version = '$newMajor.$newMinor.0'; + } + else + { + json.version = '$newMajor.$newMinor.${ Std.parseInt(previousPatch) + 1 }'; + } + case _: + throw new Exception('Invalid version in haxelib.json'); + } - Sys.println("hxcpp_release=" + newVersion ); + File.saveContent(jsonFile, Json.stringify(json, '\t')); + + final define = "HXCPP_VERSION"; + final lines = [ + '#ifndef $define', + '#define $define "${ json.version }"', + '#endif' + ]; + + File.saveContent("include/HxcppVersion.h", lines.join("\n")); + + Sys.println("hxcpp_release=" + json.version ); + case _: + throw new Exception('Invalid version in tag'); + } + case other: + throw new Exception('Invalid version $other'); + } } }