Skip to content

Commit

Permalink
Merge pull request #1005 from WolframResearch/feature/increment-pacle…
Browse files Browse the repository at this point in the history
…t-version

Automatically increment paclet version when pushing changes to main
  • Loading branch information
rhennigan authored Dec 31, 2024
2 parents 32f56cf + 67273d4 commit e609f09
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 10 deletions.
24 changes: 15 additions & 9 deletions .github/workflows/ExperimentalRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Experimental Release

on:
workflow_dispatch:
push:
workflow_run:
workflows: ["Increment Paclet Version"]
types:
- completed
branches: [main]

concurrency:
Expand Down Expand Up @@ -46,13 +49,16 @@ jobs:
run: |
git config --global --add safe.directory $(pwd)
if gh release view experimental; then
gh release delete experimental --cleanup-tag --yes --repo="${{ env.GITHUB_REPOSITORY }}"
if ! gh release view experimental; then
gh release create experimental \
--target="${{ github.ref }}" \
--repo="${{ env.GITHUB_REPOSITORY }}" \
--title="Experimental Release" \
--notes="This is an experimental release that's always updated with the latest build from the main branch." \
--prerelease
fi
gh release create experimental "${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \
--target="${{ github.ref }}" \
--repo="${{ env.GITHUB_REPOSITORY }}" \
--title="Experimental Release" \
--notes="This is an experimental release that's always updated with the latest build from the main branch." \
--prerelease
gh release upload experimental \
"${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \
--clobber \
--repo="${{ env.GITHUB_REPOSITORY }}"
56 changes: 56 additions & 0 deletions .github/workflows/IncrementPacletVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Increment Paclet Version

on:
workflow_dispatch:
push:
branches: [main]

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

env:
WOLFRAMSCRIPT_ENTITLEMENTID: ${{ secrets.WOLFRAMSCRIPT_ENTITLEMENTID }}
WOLFRAM_SYSTEM_ID: Linux-x86-64
UPDATE_PACLET_INFO: false

jobs:
IncrementVersion:
name: Increment Version
runs-on: ubuntu-latest
timeout-minutes: 15

container:
image: wolframresearch/wolframengine:14.1
options: --user root

steps:
- name: Update Git
run: |
apt-get update && apt-get install software-properties-common -y
add-apt-repository ppa:git-core/ppa -y
apt-get update && apt-get install git -y
- name: Checkout
uses: actions/checkout@v4

- name: Configure Git
run: |
git config --global --add safe.directory $(pwd)
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Increment Version
run: wolframscript -f Scripts/IncrementPacletVersion.wls

- name: Commit Changes
shell: bash
run: |
echo "Status: $(git status --porcelain)"
if [[ -n $(git status --porcelain) ]]; then
git add PacletInfo.wl
git commit -m "Automated: Increment paclet version"
git push
else
echo "No changes to commit"
fi
3 changes: 2 additions & 1 deletion Scripts/Common.wl
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ $envSHA = SelectFirst[
];

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

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
Expand Down Expand Up @@ -173,7 +174,7 @@ actionURL[ ] := Enclose[
(*updatePacletInfo*)
(* :!CodeAnalysis::BeginBlock:: *)
(* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)
updatePacletInfo[ dir_ ] /; $inCICD := Enclose[
updatePacletInfo[ dir_ ] /; $updatePacletInfo := Enclose[
Module[
{ cs, file, string, id, date, url, run, cmt, oldID, new },

Expand Down
76 changes: 76 additions & 0 deletions Scripts/IncrementPacletVersion.wls
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env wolframscript

BeginPackage[ "Wolfram`ChatbookScripts`" ];

If[ ! TrueQ @ $loadedDefinitions, Get @ FileNameJoin @ { DirectoryName @ $InputFileName, "Common.wl" } ];

Needs[ "Wolfram`PacletCICD`" -> "cicd`" ];

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Definitions*)

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*incrementPacletVersion*)
(* :!CodeAnalysis::BeginBlock:: *)
(* :!CodeAnalysis::Disable::SuspiciousSessionSymbol:: *)
(* :!CodeAnalysis::Disable::LeakedVariable:: *)
incrementPacletVersion[ dir_ ] := Enclose[
Catch @ Module[
{ cs, file, string, version, newVersion, new },

cs = ConfirmBy[ #1, StringQ, #2 ] &;
file = cs[ FileNameJoin @ { dir, "PacletInfo.wl" }, "PacletInfo" ];
string = cs[ ReadString @ file, "ReadString" ];
version = cs[ PacletObject[ Flatten @ File @ dir ][ "Version" ], "Version" ];

If[ StringEndsQ[ version, "." ~~ "0".. ~~ EndOfString ],
Print[ "Skipping paclet version update: ", version ];
Throw @ version
];

newVersion = cs[
StringReplace[
version,
"." ~~ v: DigitCharacter.. ~~ EndOfString :> "." <> ToString[ ToExpression @ v + 1 ]
],
"NewVersion"
];

ConfirmAssert[ PacletNewerQ[ newVersion, version ], "PacletNewerQ" ];

new = cs[
StringReplace[
string,
pre: ("\"Version\"" ~~ $$ws ~~ "->" ~~ $$ws) ~~ "\"" ~~ version ~~ "\"" :>
pre <> "\"" <> newVersion <> "\""
],
"UpdatedPacletInfo"
];

Print[ "Incrementing version: ", version, " -> ", newVersion ];
Confirm[ WithCleanup[ BinaryWrite[ file, new ], Close @ file ], "WritePacletInfo" ];

ConfirmMatch[
PacletObject[ Flatten @ File @ dir ][ "Version" ],
newVersion,
"PacletObject"
]
],
Function[
Print[ "::error::Failed to increment paclet version." ];
Print[ " ", ToString[ #, InputForm ] ];
If[ StringQ @ Environment[ "GITHUB_ACTION" ], Exit[ 1 ] ]
]
];
(* :!CodeAnalysis::EndBlock:: *)

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
(*Run*)
result = cicd`ScriptConfirmBy[ incrementPacletVersion @ $pacletDir, StringQ ];

EndPackage[ ];

Wolfram`ChatbookScripts`result

0 comments on commit e609f09

Please sign in to comment.