Skip to content

Commit e609f09

Browse files
authored
Merge pull request #1005 from WolframResearch/feature/increment-paclet-version
Automatically increment paclet version when pushing changes to main
2 parents 32f56cf + 67273d4 commit e609f09

File tree

4 files changed

+149
-10
lines changed

4 files changed

+149
-10
lines changed

.github/workflows/ExperimentalRelease.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ name: Experimental Release
22

33
on:
44
workflow_dispatch:
5-
push:
5+
workflow_run:
6+
workflows: ["Increment Paclet Version"]
7+
types:
8+
- completed
69
branches: [main]
710

811
concurrency:
@@ -46,13 +49,16 @@ jobs:
4649
run: |
4750
git config --global --add safe.directory $(pwd)
4851
49-
if gh release view experimental; then
50-
gh release delete experimental --cleanup-tag --yes --repo="${{ env.GITHUB_REPOSITORY }}"
52+
if ! gh release view experimental; then
53+
gh release create experimental \
54+
--target="${{ github.ref }}" \
55+
--repo="${{ env.GITHUB_REPOSITORY }}" \
56+
--title="Experimental Release" \
57+
--notes="This is an experimental release that's always updated with the latest build from the main branch." \
58+
--prerelease
5159
fi
5260
53-
gh release create experimental "${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \
54-
--target="${{ github.ref }}" \
55-
--repo="${{ env.GITHUB_REPOSITORY }}" \
56-
--title="Experimental Release" \
57-
--notes="This is an experimental release that's always updated with the latest build from the main branch." \
58-
--prerelease
61+
gh release upload experimental \
62+
"${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \
63+
--clobber \
64+
--repo="${{ env.GITHUB_REPOSITORY }}"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Increment Paclet Version
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
8+
concurrency:
9+
group: ${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
env:
13+
WOLFRAMSCRIPT_ENTITLEMENTID: ${{ secrets.WOLFRAMSCRIPT_ENTITLEMENTID }}
14+
WOLFRAM_SYSTEM_ID: Linux-x86-64
15+
UPDATE_PACLET_INFO: false
16+
17+
jobs:
18+
IncrementVersion:
19+
name: Increment Version
20+
runs-on: ubuntu-latest
21+
timeout-minutes: 15
22+
23+
container:
24+
image: wolframresearch/wolframengine:14.1
25+
options: --user root
26+
27+
steps:
28+
- name: Update Git
29+
run: |
30+
apt-get update && apt-get install software-properties-common -y
31+
add-apt-repository ppa:git-core/ppa -y
32+
apt-get update && apt-get install git -y
33+
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Configure Git
38+
run: |
39+
git config --global --add safe.directory $(pwd)
40+
git config --global user.name 'github-actions[bot]'
41+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
42+
43+
- name: Increment Version
44+
run: wolframscript -f Scripts/IncrementPacletVersion.wls
45+
46+
- name: Commit Changes
47+
shell: bash
48+
run: |
49+
echo "Status: $(git status --porcelain)"
50+
if [[ -n $(git status --porcelain) ]]; then
51+
git add PacletInfo.wl
52+
git commit -m "Automated: Increment paclet version"
53+
git push
54+
else
55+
echo "No changes to commit"
56+
fi

Scripts/Common.wl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ $envSHA = SelectFirst[
117117
];
118118

119119
$inCICD = StringQ @ $envSHA;
120+
$updatePacletInfo = TrueQ[ $inCICD && ! MatchQ[ Environment[ "UPDATE_PACLET_INFO" ], "false"|"False"|"0" ] ];
120121

121122
(* ::**************************************************************************************************************:: *)
122123
(* ::Subsection::Closed:: *)
@@ -173,7 +174,7 @@ actionURL[ ] := Enclose[
173174
(*updatePacletInfo*)
174175
(* :!CodeAnalysis::BeginBlock:: *)
175176
(* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)
176-
updatePacletInfo[ dir_ ] /; $inCICD := Enclose[
177+
updatePacletInfo[ dir_ ] /; $updatePacletInfo := Enclose[
177178
Module[
178179
{ cs, file, string, id, date, url, run, cmt, oldID, new },
179180

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)