diff --git a/.github/workflows/ExperimentalRelease.yml b/.github/workflows/ExperimentalRelease.yml index 554dcce6..ac142d1a 100644 --- a/.github/workflows/ExperimentalRelease.yml +++ b/.github/workflows/ExperimentalRelease.yml @@ -2,7 +2,10 @@ name: Experimental Release on: workflow_dispatch: - push: + workflow_run: + workflows: ["Increment Paclet Version"] + types: + - completed branches: [main] concurrency: @@ -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 \ No newline at end of file + gh release upload experimental \ + "${{ env.PACLET_BUILD_DIR }}/Wolfram__Chatbook.paclet" \ + --clobber \ + --repo="${{ env.GITHUB_REPOSITORY }}" \ No newline at end of file diff --git a/.github/workflows/IncrementPacletVersion.yml b/.github/workflows/IncrementPacletVersion.yml new file mode 100644 index 00000000..2f9acdcd --- /dev/null +++ b/.github/workflows/IncrementPacletVersion.yml @@ -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 \ No newline at end of file diff --git a/Scripts/Common.wl b/Scripts/Common.wl index b79de8d3..25a7cbef 100644 --- a/Scripts/Common.wl +++ b/Scripts/Common.wl @@ -117,6 +117,7 @@ $envSHA = SelectFirst[ ]; $inCICD = StringQ @ $envSHA; +$updatePacletInfo = TrueQ[ $inCICD && ! MatchQ[ Environment[ "UPDATE_PACLET_INFO" ], "false"|"False"|"0" ] ]; (* ::**************************************************************************************************************:: *) (* ::Subsection::Closed:: *) @@ -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 }, diff --git a/Scripts/IncrementPacletVersion.wls b/Scripts/IncrementPacletVersion.wls new file mode 100644 index 00000000..d191bd47 --- /dev/null +++ b/Scripts/IncrementPacletVersion.wls @@ -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 \ No newline at end of file