Skip to content

Commit

Permalink
CI - Updated version handling (#1123)
Browse files Browse the repository at this point in the history
* Updated version handling

* Downgrade to macos-13
  • Loading branch information
Aidan63 authored Oct 12, 2024
1 parent 66b8f88 commit c97ab28
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 73 deletions.
48 changes: 21 additions & 27 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
Expand All @@ -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: |
Expand All @@ -75,15 +81,15 @@ 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: |
bin/Windows64/Cppia.exe
- name: Archive Mac Results
if: startsWith(matrix.os,'macos')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mac-64
path: |
Expand All @@ -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/
Expand All @@ -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
artifacts: ./hxcpp-${{ env.hxcpp_release }}.zip
97 changes: 51 additions & 46 deletions tools/version/Write.hx
Original file line number Diff line number Diff line change
@@ -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<lines.length)
switch Sys.args()
{
if (versionMatch.match(lines[idx]))
{
var parts = versionMatch.matched(2).split(".");
if (parts.length==3)
parts[2] = buildNumber+"";
else
parts.push(buildNumber+"");
newVersion = parts.join(".");
lines[idx]=versionMatch.matched(1) + newVersion + versionMatch.matched(3);
found = true;
break;
}
idx++;
}
if (!found)
throw "Could not find version in " + jsonFile;
case [ version ] if (version.startsWith('v')):
switch version.substr(1).split('.')
{
case [ previousMajor, previousMinor, previousPatch ]:
final jsonFile = "haxelib.json";
final json = (cast Json.parse(File.getContent(jsonFile)) : Haxelib);

File.saveContent(jsonFile, lines.join("\n") );
switch json.version.split('.')
{
case [ newMajor, newMinor, _ ]:
if (newMajor < previousMajor || (newMajor == previousMajor && newMinor < previousMinor))
{
throw new Exception('Version in haxelib.json is older than the last tag');
}

var writeVersionFilename = "include/HxcppVersion.h";
var define = "HXCPP_VERSION";
var lines = [
'#ifndef $define',
'#define $define "$newVersion"',
'#endif'
];
File.saveContent( writeVersionFilename, lines.join("\n") );
if (newMajor > 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');
}
}
}

0 comments on commit c97ab28

Please sign in to comment.