Skip to content

Commit ff2435d

Browse files
committed
Automatically increment paclet version when pushing changes to main
1 parent 32f56cf commit ff2435d

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Increment Paclet Version
2+
3+
on:
4+
push:
5+
branches: [feature/increment-paclet-version] # TODO: Change to main after testing
6+
7+
concurrency:
8+
group: ${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
env:
12+
WOLFRAMSCRIPT_ENTITLEMENTID: ${{ secrets.WOLFRAMSCRIPT_ENTITLEMENTID }}
13+
WOLFRAM_SYSTEM_ID: Linux-x86-64
14+
15+
jobs:
16+
IncrementVersion:
17+
name: Increment Version
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 15
20+
21+
container:
22+
image: wolframresearch/wolframengine:14.1
23+
options: --user root
24+
25+
steps:
26+
- name: Update Git
27+
run: |
28+
apt-get update && apt-get install software-properties-common -y
29+
add-apt-repository ppa:git-core/ppa -y
30+
apt-get update && apt-get install git -y
31+
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Configure Git
36+
run: |
37+
git config --global user.name 'github-actions[bot]'
38+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
39+
40+
- name: Increment Version
41+
run: wolframscript -f Scripts/IncrementPacletVersion.wls
42+
43+
- name: Commit Changes
44+
run: |
45+
if [[ -n $(git status --porcelain) ]]; then
46+
git add PacletInfo.wl
47+
git commit -m "Automated: Increment paclet version"
48+
git push
49+
else
50+
echo "No changes to commit"
51+
fi

Scripts/IncrementPacletVersion.wls

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env wolframscript
2+
3+
BeginPackage[ "Wolfram`ChatbookScripts`" ];
4+
5+
If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];
6+
7+
Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];
8+
9+
(* ::**************************************************************************************************************:: *)
10+
(* ::Section::Closed:: *)
11+
(*Definitions*)
12+
13+
(* ::**************************************************************************************************************:: *)
14+
(* ::Subsection::Closed:: *)
15+
(*incrementPacletVersion*)
16+
(* :!CodeAnalysis::BeginBlock:: *)
17+
(* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)
18+
(* :!CodeAnalysis::Disable::LeakedVariable:: *)
19+
incrementPacletVersion[ dir_ ] := Enclose[
20+
Catch @ Module[
21+
{ cs, file, string, version, newVersion, new },
22+
23+
cs = ConfirmBy[ #1, StringQ, #2 ] &;
24+
file = cs[ FileNameJoin @ { dir, "PacletInfo.wl" }, "PacletInfo" ];
25+
string = cs[ ReadString @ file, "ReadString" ];
26+
version = cs[ PacletObject[ Flatten @ File @ dir ][ "Version" ], "Version" ];
27+
28+
If[ StringEndsQ[ version, "." ~~ "0".. ~~ EndOfString ],
29+
Print[ "Skipping paclet version update: ", version ];
30+
Throw @ version
31+
];
32+
33+
newVersion = cs[
34+
StringReplace[
35+
version,
36+
"." ~~ v: DigitCharacter.. ~~ EndOfString :> "." <> ToString[ ToExpression @ v + 1 ]
37+
],
38+
"NewVersion"
39+
];
40+
41+
ConfirmAssert[ PacletNewerQ[ newVersion, version ], "PacletNewerQ" ];
42+
43+
new = cs[
44+
StringReplace[
45+
string,
46+
pre: ("\"Version\"" ~~ $$ws ~~ "->" ~~ $$ws) ~~ "\"" ~~ version ~~ "\"" :>
47+
pre <> "\"" <> newVersion <> "\""
48+
],
49+
"UpdatedPacletInfo"
50+
];
51+
52+
Print[ "Incrementing version: ", version, " -> ", newVersion ];
53+
Confirm[ WithCleanup[ BinaryWrite[ file, new ], Close @ file ], "WritePacletInfo" ];
54+
55+
ConfirmMatch[
56+
PacletObject[ Flatten @ File @ dir ][ "Version" ],
57+
newVersion,
58+
"PacletObject"
59+
]
60+
],
61+
Function[
62+
Print[ "::error::Failed to increment paclet version." ];
63+
Print[ " ", ToString[ #, InputForm ] ];
64+
If[ StringQ @ Environment[ "GITHUB_ACTION" ], Exit[ 1 ] ]
65+
]
66+
];
67+
(* :!CodeAnalysis::EndBlock:: *)
68+
69+
(* ::**************************************************************************************************************:: *)
70+
(* ::Section::Closed:: *)
71+
(*Run*)
72+
result = cicd`ScriptConfirmBy[ incrementPacletVersion @ $pacletDir, StringQ ];
73+
74+
EndPackage[ ];
75+
76+
Wolfram`ChatbookScripts`result

0 commit comments

Comments
 (0)