diff --git a/.ci/deploy.sh b/.ci/deploy.sh deleted file mode 100755 index e11aa1ce..00000000 --- a/.ci/deploy.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -e # Exit with nonzero exit code if anything fails - -function doCompile { - echo "Running script..." - python3 -m magic_spoiler -} - -# Pull requests and commits to other branches shouldn't try to deploy, just build to verify -if [[ ! -d $OUTPUT_PATH ]]; then - mkdir "$OUTPUT_PATH" - echo "Not running from master... doing a build, but skipping deploy!" - # Run our compile script and let user know in logs - doCompile - exit 0 -fi - -# Run our compile script and exit gracefully if there are no updates -if ! doCompile; then - echo "::warning::No updates found... skipping file upload!" - exit 0 -fi - -cd "$OUTPUT_PATH" -git config user.name github-actions -git config user.email github-actions@github.com - -# We don't want the AllSets... waste of space -git add -A . -git commit -m "Deploy: ${GITHUB_SHA}" - -# push using built-in token -git push diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 08a3fb6c..8dc6cb91 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,6 +1,7 @@ name: Deploy on: + workflow_dispatch: push: branches: - master @@ -15,13 +16,12 @@ on: # every 6 hours = 4 times a day - cron: '0 */6 * * *' - workflow_dispatch: - jobs: deploy: runs-on: ubuntu-latest env: + DEPLOY: ${{github.ref == 'refs/heads/master'}} OUTPUT_PATH: out steps: @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v2 - name: Checkout output branch - if: github.ref == 'refs/heads/master' + if: env.DEPLOY uses: actions/checkout@v2 with: ref: files @@ -44,6 +44,18 @@ jobs: python3 -m pip install --upgrade pip setuptools python3 -m pip install --requirement requirements.txt - - name: Deploy + - name: Run + id: run shell: bash - run: ./.ci/deploy.sh + run: python3 -m magic_spoiler + + - name: Deploy + if: env.DEPLOY && steps.run.outputs.deploy == true + shell: bash + working-directory: ${{env.OUTPUT_PATH}} + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add -A . + git commit -m "Deploy: $GITHUB_SHA" + git push diff --git a/magic_spoiler/__main__.py b/magic_spoiler/__main__.py index b8aef5ee..2c51b167 100644 --- a/magic_spoiler/__main__.py +++ b/magic_spoiler/__main__.py @@ -7,7 +7,6 @@ import hashlib import json import pathlib import shutil -import sys import time from typing import IO, Any, Dict, List, Tuple, Union @@ -525,7 +524,7 @@ def write_set_json(trice_dict: List[Dict[str, Any]], set_obj: Dict[str, str]) -> output_file_path = OUTPUT_TMP_DIR.joinpath("{}.json".format(set_obj["code"])) - OUTPUT_TMP_DIR.mkdir(exist_ok=True) + OUTPUT_TMP_DIR.mkdir(parents=True, exist_ok=True) with output_file_path.open("w") as f: json.dump(trice_dict, f, sort_keys=True, indent=4) @@ -630,9 +629,9 @@ def main() -> None: # Cleanup outdated stuff that's not necessary changed |= delete_old_files() - # Set nonzero exit code if files haven't changed - if not changed: - sys.exit(1) + # Set output to deploy + if changed: + print("::set-output name=deploy::true") if __name__ == "__main__":