From 5eb7303247970f9acbdf21fc6cd1399a807a0505 Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:06:29 -0800 Subject: [PATCH 1/6] let's give this a shot? --- Jenkinsfile | 14 +++++++++++--- publish_package.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 publish_package.py diff --git a/Jenkinsfile b/Jenkinsfile index 05da1a9..56082cc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,9 +21,17 @@ node ('windows') { bat """pyinstaller --noconfirm --onefile --windowed "./main.py" """ } - // Wrap Up - Archive the Generated Executables, Tear Down the Build System. - stage('Archive/Teardown') { - archiveArtifacts artifacts: "dist\\*.exe" + // Wrap Up - Archive the Generated Executables + stage('Archive') { + // Provide Credentials to Upload to Gitea + withCredentials([ + usernamePassword(credentialsId: 'gitea-jenkinsbot', + usernameVariable: 'GITEA_USER', + passwordVariable: 'GITEA_PASS') + ]) { + // Publish the Latest + bat "python publish_package.py" + } } } \ No newline at end of file diff --git a/publish_package.py b/publish_package.py new file mode 100644 index 0000000..b8038d7 --- /dev/null +++ b/publish_package.py @@ -0,0 +1,39 @@ +################################################################################ +""" +Publish the EXE as a package to Gitea. +""" +################################################################################ + +import os +import requests + +OWNER = "jenkinsbot" +PKG_NAME = "ComputerKeeper-BUILD" +PKG_VERSION = "latest" +FILE_NAME = "main.exe" + +AUTH_USER = os.getenv("GITEA_USER") +AUTH_PASS = os.getenv("GITEA_PASS") + +HOST = "https://gitea.stanleysolutionsnw.com" + +def main(): + """Attempt Deleting the Package, then Add the New Package with File.""" + s = requests.Session() + s.auth = (AUTH_USER, AUTH_PASS) + # Delete Package + try: + s.delete( + f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}" + ) + except Exception: + # Intentionally Overlook Issues Here + pass + # Add New Package + s.put( + ( + f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}/" + + FILE_NAME + ), + data=open(f"dist/{FILE_NAME}", 'rb').read(), + ) From 6966d7572c9894255e689b5c4be71ce567d39323 Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:10:42 -0800 Subject: [PATCH 2/6] new insructions --- publish_package.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/publish_package.py b/publish_package.py index b8038d7..52e6c2d 100644 --- a/publish_package.py +++ b/publish_package.py @@ -23,17 +23,21 @@ def main(): s.auth = (AUTH_USER, AUTH_PASS) # Delete Package try: - s.delete( + print("Deleting...") + result = s.delete( f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}" ) + result.raise_for_status() except Exception: # Intentionally Overlook Issues Here - pass + print("No package to delete.") # Add New Package - s.put( + print("Adding new package...") + result = s.put( ( f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}/" + FILE_NAME ), data=open(f"dist/{FILE_NAME}", 'rb').read(), ) + result.raise_for_status() From 9c9621ed0de15a884530a883ea9f546fee183ee4 Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:16:42 -0800 Subject: [PATCH 3/6] new insructions --- publish_package.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/publish_package.py b/publish_package.py index 52e6c2d..8e5df78 100644 --- a/publish_package.py +++ b/publish_package.py @@ -41,3 +41,6 @@ def main(): data=open(f"dist/{FILE_NAME}", 'rb').read(), ) result.raise_for_status() + +if __name__ == "__main__": + main() \ No newline at end of file From 78ecefbf07fd8a8ae6e0c84a4fb32375459a9dfc Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:21:12 -0800 Subject: [PATCH 4/6] new insructions --- publish_package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish_package.py b/publish_package.py index 8e5df78..553db0f 100644 --- a/publish_package.py +++ b/publish_package.py @@ -7,7 +7,7 @@ Publish the EXE as a package to Gitea. import os import requests -OWNER = "jenkinsbot" +OWNER = "Potlatch-Loggers" PKG_NAME = "ComputerKeeper-BUILD" PKG_VERSION = "latest" FILE_NAME = "main.exe" From 37eb93d111c389171323005c2754b7a9c5e19b22 Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:22:46 -0800 Subject: [PATCH 5/6] new insructions --- publish_package.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/publish_package.py b/publish_package.py index 553db0f..33b26d1 100644 --- a/publish_package.py +++ b/publish_package.py @@ -28,6 +28,7 @@ def main(): f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}" ) result.raise_for_status() + # pylint: disable=broad-except except Exception: # Intentionally Overlook Issues Here print("No package to delete.") @@ -43,4 +44,4 @@ def main(): result.raise_for_status() if __name__ == "__main__": - main() \ No newline at end of file + main() From 312ad93ca0a0612193c4ed6eecc8426a9064671a Mon Sep 17 00:00:00 2001 From: Joe Stanley Date: Sun, 6 Nov 2022 20:34:37 -0800 Subject: [PATCH 6/6] added link --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3680c9f..617035a 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,21 @@ *a tool to manage a library of computers for Potlatch Jr/Sr High School* -### Build System: -Builds are generated by Stanley Solutions Jenkins; they can be accessed here: [StanleySolutions Jenkins](https://jenkins.stanleysolutionsnw.com/job/Potlatch%20Loggers%20Organization/job/ComputerKeeper/) +### Build System +Builds are generated by Stanley Solutions Jenkins; they can be accessed here: +[StanleySolutions Jenkins](https://jenkins.stanleysolutionsnw.com/job/Potlatch%20Loggers%20Organization/job/ComputerKeeper/) | **Branch** | **Build Status** | |------------|------------------| | Main | [![Master Branch Build Status](https://jenkins.stanleysolutionsnw.com/buildStatus/icon?job=Potlatch+Loggers+Organization%2FComputerKeeper%2Fmain)](https://jenkins.stanleysolutionsnw.com/job/Potlatch%20Loggers%20Organization/job/ComputerKeeper/job/main/) | +### Built Resources +Resulting EXE files built by Jenkins are archived as packages and can be found +in the [repository packages](https://gitea.stanleysolutionsnw.com/Potlatch-Loggers/ComputerKeeper/packages). + ## PyInstaller Command ```shell pyinstaller --noconfirm --onefile --windowed "./main.py" -``` \ No newline at end of file +```