diff --git a/.github/workflows/reusable.yml b/.github/workflows/reusable.yml index 254e7d8..3bb0a9e 100644 --- a/.github/workflows/reusable.yml +++ b/.github/workflows/reusable.yml @@ -95,10 +95,17 @@ jobs: - name: Pull Script Tooling id: pull-python-script + if: ${{github.event_name != 'schedule' }} uses: actions/checkout@v3 with: repository: texas-mcallen-mission/deploy-google-app-script-action-typescript path: deploy-data + ref: 'main' + + - name: Set up things to make it easier to transition over. + id: repo-setup + if: ${{ github.event_name != 'schedule'}} + run: /bin/python3 deploy-data/scripts/pre-setup.py - name: Set scriptId in .clasp.json file id: set-script-id @@ -142,10 +149,17 @@ jobs: env: CONFIG_DATA: ${{ secrets.IN_CONFIG_DATA }} # 🐧 + + - name: rename git-info and give it an A + id: rename-git-info-in-python + if: ${{github.event_name != 'schedule' }} + run: /bin/python3 deploy-data/scripts/rename-git-info.py "testArg" + +# updated in fixes-and-updates branch to catch errors. - name: Push script to scripts.google.com id: clasp-push if: ${{ github.event_name != 'schedule' }} - run: clasp push -f + run: /bin/python3 deploy-data/scripts/run-clasp-fancy.py - name: Deploy Script id: clasp-deploy diff --git a/required-files/.clasp.json b/required-files/.clasp.json new file mode 100644 index 0000000..9246855 --- /dev/null +++ b/required-files/.clasp.json @@ -0,0 +1,7 @@ +{ + "scriptId": "SCRIPT_ID", + "rootDir": "./", + "parentId": [ + "PARENT_ID" + ] +} \ No newline at end of file diff --git a/required-files/.claspignore b/required-files/.claspignore new file mode 100644 index 0000000..7153ed9 --- /dev/null +++ b/required-files/.claspignore @@ -0,0 +1 @@ +deploy-data/** diff --git a/required-files/appsscript.json b/required-files/appsscript.json new file mode 100644 index 0000000..3cf1d24 --- /dev/null +++ b/required-files/appsscript.json @@ -0,0 +1,7 @@ +{ + "timeZone": "America/New_York", + "dependencies": { + }, + "exceptionLogging": "STACKDRIVER", + "runtimeVersion": "V8" +} \ No newline at end of file diff --git a/git-info.js b/required-files/git-info.js similarity index 83% rename from git-info.js rename to required-files/git-info.js index 6fc2d26..0ca5136 100644 --- a/git-info.js +++ b/required-files/git-info.js @@ -1,4 +1,6 @@ // the contents of this file get find-replaced using sed at action runtime- please be careful in here! +// Hey, you should consider making a permanent copy of this and deleting this line! + const GITHUB_DATA = { commit_sha:"COMMITSHA", // done action_event_name: "EVENTNAME", // done diff --git a/required-files/tsconfig.json b/required-files/tsconfig.json new file mode 100644 index 0000000..5792bec --- /dev/null +++ b/required-files/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "lib": ["ESNext"], + "target": "ES6", + "types": [ + "google-apps-script" + ], + "outDir": "./ts", + "rootDir": "./" + + } +} \ No newline at end of file diff --git a/scripts/add-config.py b/scripts/add-config.py index a9ae8b1..2adf8f6 100644 --- a/scripts/add-config.py +++ b/scripts/add-config.py @@ -1,4 +1,5 @@ import sys +import os nameOfScript = sys.argv[0] commandLineArgs = sys.argv[1] @@ -7,7 +8,7 @@ numArgs = len(sys.argv) -print(nameOfScript," arguments: ",numArgs) +print(nameOfScript," arguments: ",numArgs,"running with rename script internally.") file_in = open("git-info.js", "rt") diff --git a/scripts/pre-setup.py b/scripts/pre-setup.py new file mode 100644 index 0000000..57e97ff --- /dev/null +++ b/scripts/pre-setup.py @@ -0,0 +1,44 @@ +import os +import shutil +print("setting things up.") + +# Things to check for: +# Does clasp.json exist yet? +# Does git-info.js (or TS?) exist yet? - if not, copy over local version +# Does .claspignore exist yet? - if not, create a file, and put /deploy-data in it +# - also just pipe in deploy-data/ in there, it really doesn't matter if it's there twice +# Could also stick an empty .gs file in there as a watermark, lol? +# Basically I need to find *everything* necessary to make an empty repo and push it and make a local, basic copy. + +claspIg = ".claspignore" +deployDataLine = "deploy-data/**" + +files = [".clasp.json", "git-info.js", "tsconfig.json", "appsscript.json", claspIg] + +addedFiles = [] + + +reqFileDir = "deploy-data/required-files/" + +for entry in files: + if os.path.exists(entry) == False and os.path.exists(reqFileDir+entry) == True: + shutil.copy2(reqFileDir+entry, entry) + addedFiles.append(entry) + + +# then run code to modify claspignore? +if addedFiles.count(claspIg) == 0: # this is like array.includes, I guess? + # pipe thingies in + print("modifying"+claspIg) + claspIgnoreFile = open(claspIg, mode="r+") + print("pre-mod:", claspIgnoreFile.read()) + print(deployDataLine, file=claspIgnoreFile) # adds newline + claspIgnoreFile.close() + + +if len(addedFiles) > 0: + # spread operator thingy to get rid of the brackets. Super neat! + print("Completed- added ", *addedFiles) +else: + print("Completeted, no new files added.") + diff --git a/scripts/rename-git-info.py b/scripts/rename-git-info.py new file mode 100644 index 0000000..4939a14 --- /dev/null +++ b/scripts/rename-git-info.py @@ -0,0 +1,11 @@ +import os +import glob + +print(glob.glob(os.getcwd())) + +input_source = "git-info.js" +print("current working directory:",os.getcwd()) +output_dest = "aaa-git-info.js" +print("renaming") +os.rename(input_source,output_dest) +print("finished") diff --git a/scripts/run-clasp-fancy.py b/scripts/run-clasp-fancy.py new file mode 100644 index 0000000..5cf1d69 --- /dev/null +++ b/scripts/run-clasp-fancy.py @@ -0,0 +1,44 @@ +import subprocess + +# The new-and-improved CLASP runner! +# This bad boi checks the output of CLASP and makes sure that it doesn't throw an error. +# Previously, if clasp didn't succeed, it'd just continue on without any indication of problems. +# Now, it'll throw an error and spit out the logs if it breaks. *WAY* better. :) +# + +# custom exception type +class killAction(Exception): + pass + +# the thing that runs clasp pushing itself +result = subprocess.run(["clasp","push","-f"],stdout=subprocess.PIPE) + +# the rest of this parses the output from CLASP. + +# wrote this as a function so that I could write tests for it +def wasSuccessful(data): + + returnVal = True + + gaxios = "GaxiosError:" + pushFailure = "Push failed. Errors:" + gaxiosFail = (gaxios in data) # true if GaxiosError: is in the log + pushFail = (pushFailure in data) # true if Push Failure is in the log + if gaxiosFail or pushFail: + returnVal = False + return returnVal + +encoding = 'utf-8' +parsedResult = str(result.stdout,encoding) +claspRun = wasSuccessful(parsedResult) + +# *might* add some extra parsing here to make the result easier to read? + +print(parsedResult) +if claspRun == False: + # and then throw an error. + raise killAction(""" + Clasp had an internal error!""") +else: + print(""" + Push succeeded.""")