Skip to content

Commit c97ab28

Browse files
authored
CI - Updated version handling (#1123)
* Updated version handling * Downgrade to macos-13
1 parent 66b8f88 commit c97ab28

File tree

2 files changed

+72
-73
lines changed

2 files changed

+72
-73
lines changed

.github/workflows/package.yml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ jobs:
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
1618

1719
- uses: Aidan63/setup-haxe@3d3101bcd0a2001699fc8295f4d9eddd0724d3e9
1820
with:
@@ -22,16 +24,20 @@ jobs:
2224
run: |
2325
haxe -version
2426
haxelib dev hxcpp .
27+
28+
- name: 'Get Previous tag'
29+
id: previoustag
30+
uses: "WyriHaximus/github-action-get-previous-tag@v1"
31+
with:
32+
prefix: v
2533

2634
- name: Set Version
27-
run: haxe -cp tools/version --run Write ${{github.run_number}} > version.env
28-
35+
run: haxe -p tools/version --run Write ${{ steps.previoustag.outputs.tag }} > version.env
2936

3037
- name: Build Tool
3138
run: |
3239
cd tools/hxcpp
3340
haxe compile.hxml
34-
3541
3642
- name: Check XCode
3743
if: startsWith(matrix.os,'macos')
@@ -49,7 +55,7 @@ jobs:
4955
5056
- name: Archive Linux Results
5157
if: startsWith(matrix.os,'ubuntu')
52-
uses: actions/upload-artifact@v3
58+
uses: actions/upload-artifact@v4
5359
with:
5460
name: linux-64
5561
path: |
@@ -75,15 +81,15 @@ jobs:
7581
7682
- name: Archive Windows Results
7783
if: startsWith(matrix.os,'windows')
78-
uses: actions/upload-artifact@v3
84+
uses: actions/upload-artifact@v4
7985
with:
8086
name: windows-64
8187
path: |
8288
bin/Windows64/Cppia.exe
8389
8490
- name: Archive Mac Results
8591
if: startsWith(matrix.os,'macos')
86-
uses: actions/upload-artifact@v3
92+
uses: actions/upload-artifact@v4
8793
with:
8894
name: mac-64
8995
path: |
@@ -94,19 +100,19 @@ jobs:
94100
runs-on: ubuntu-latest
95101
steps:
96102
- name: Download Linux
97-
uses: actions/download-artifact@v3
103+
uses: actions/download-artifact@v4
98104
with:
99105
name: linux-64
100106
path: hxcpp
101107

102108
- name: Download Mac
103-
uses: actions/download-artifact@v3
109+
uses: actions/download-artifact@v4
104110
with:
105111
name: mac-64
106112
path: hxcpp/bin/Mac64/
107113

108114
- name: Download Windows
109-
uses: actions/download-artifact@v3
115+
uses: actions/download-artifact@v4
110116
with:
111117
name: windows-64
112118
path: hxcpp/bin/Windows64/
@@ -126,23 +132,11 @@ jobs:
126132
zip -r hxcpp-${{ env.hxcpp_release }}.zip hxcpp-${{ env.hxcpp_release }}
127133
128134
- name: Create Release
129-
id: create_release
130-
uses: actions/create-release@v1
131-
env:
132-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
uses: ncipollo/release-action@v1
133136
with:
134-
tag_name: v${{ env.hxcpp_release }}
135-
release_name: Release ${{ env.hxcpp_release }}
137+
tag: v${{ env.hxcpp_release }}
138+
commit: ${{ github.head_ref }}
139+
name: Release ${{ env.hxcpp_release }}
136140
draft: false
137141
prerelease: false
138-
139-
- name: Upload Release Asset
140-
id: upload-release-asset
141-
uses: actions/upload-release-asset@v1
142-
env:
143-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144-
with:
145-
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
146-
asset_path: ./hxcpp-${{ env.hxcpp_release }}.zip
147-
asset_name: hxcpp-${{ env.hxcpp_release }}.zip
148-
asset_content_type: application/zip
142+
artifacts: ./hxcpp-${{ env.hxcpp_release }}.zip

tools/version/Write.hx

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,63 @@
1+
import haxe.Exception;
2+
import haxe.Json;
13
import sys.io.File;
24

5+
using StringTools;
6+
7+
typedef Haxelib = {
8+
var version: String;
9+
}
10+
311
class Write
412
{
513
public static function main()
614
{
7-
var args = Sys.args();
8-
// AL NOTE: this "30 +" is a bodge around some CI stuff.
9-
// Usually the ever incrementing CI run number is provided as the argument, but this ID is per github workflow.
10-
// So when the release ci yml moved file the number reset to zero and we started overwriting previous releases.
11-
// For now just append 30 since the previous release was 25 or something.
12-
//
13-
// This will need to be revisited when anything other than the last number increases as you would end up with
14-
// something like 5.0.42 instead of 5.0.0.
15-
var buildNumber = 30 + Std.parseInt(args[0]);
16-
if (buildNumber<1 || buildNumber==null)
17-
throw "Usage: Write buildNumber";
18-
19-
20-
var jsonFile = "haxelib.json";
21-
var lines = File.getContent(jsonFile).split("\n");
22-
var idx = 0;
23-
var versionMatch = ~/(.*"version"\s*:\s*")(.*)(".*)/;
24-
var found = false;
25-
var newVersion = "";
26-
while(idx<lines.length)
15+
switch Sys.args()
2716
{
28-
if (versionMatch.match(lines[idx]))
29-
{
30-
var parts = versionMatch.matched(2).split(".");
31-
if (parts.length==3)
32-
parts[2] = buildNumber+"";
33-
else
34-
parts.push(buildNumber+"");
35-
newVersion = parts.join(".");
36-
lines[idx]=versionMatch.matched(1) + newVersion + versionMatch.matched(3);
37-
found = true;
38-
break;
39-
}
40-
idx++;
41-
}
42-
if (!found)
43-
throw "Could not find version in " + jsonFile;
17+
case [ version ] if (version.startsWith('v')):
18+
switch version.substr(1).split('.')
19+
{
20+
case [ previousMajor, previousMinor, previousPatch ]:
21+
final jsonFile = "haxelib.json";
22+
final json = (cast Json.parse(File.getContent(jsonFile)) : Haxelib);
4423

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

47-
var writeVersionFilename = "include/HxcppVersion.h";
48-
var define = "HXCPP_VERSION";
49-
var lines = [
50-
'#ifndef $define',
51-
'#define $define "$newVersion"',
52-
'#endif'
53-
];
54-
File.saveContent( writeVersionFilename, lines.join("\n") );
32+
if (newMajor > previousMajor || newMinor > previousMinor)
33+
{
34+
json.version = '$newMajor.$newMinor.0';
35+
}
36+
else
37+
{
38+
json.version = '$newMajor.$newMinor.${ Std.parseInt(previousPatch) + 1 }';
39+
}
40+
case _:
41+
throw new Exception('Invalid version in haxelib.json');
42+
}
5543

56-
Sys.println("hxcpp_release=" + newVersion );
44+
File.saveContent(jsonFile, Json.stringify(json, '\t'));
45+
46+
final define = "HXCPP_VERSION";
47+
final lines = [
48+
'#ifndef $define',
49+
'#define $define "${ json.version }"',
50+
'#endif'
51+
];
52+
53+
File.saveContent("include/HxcppVersion.h", lines.join("\n"));
54+
55+
Sys.println("hxcpp_release=" + json.version );
56+
case _:
57+
throw new Exception('Invalid version in tag');
58+
}
59+
case other:
60+
throw new Exception('Invalid version $other');
61+
}
5762
}
5863
}

0 commit comments

Comments
 (0)