Merge pull request #260 from Cockatrice/tooomm-patch-3

More GH Actions stuff
This commit is contained in:
Zach H 2021-01-16 12:05:02 -05:00 committed by GitHub
commit 5dd5d37680
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 47 deletions

View File

@ -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 "Skipping deploy; just doing a build."
# 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 changes!"
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

View File

@ -1,6 +1,7 @@
name: Deploy
on:
workflow_dispatch:
push:
branches:
- master
@ -17,9 +18,13 @@ on:
jobs:
deploy:
# do not run the sheduled run on forks
if: github.event != 'schedule' || github.repository_owner == 'Cockatrice'
runs-on: ubuntu-latest
env:
DEPLOY: ${{github.ref == 'refs/heads/master'}}
OUTPUT_PATH: out
steps:
@ -27,7 +32,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
@ -42,6 +47,18 @@ jobs:
python3 -m pip install --upgrade pip setuptools
python3 -m pip install --requirement requirements.txt
- name: Deploy
- name: Run script
id: run
shell: bash
run: ./.ci/deploy.sh
run: python3 -m magic_spoiler
- name: Deploy changes
if: env.DEPLOY && steps.run.outputs.deploy != null
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

3
.gitignore vendored
View File

@ -1,7 +1,6 @@
# Project specific
out/
AllSets.pre.json
deploy_key.enc
# Byte-compiled / optimized / DLL files
__pycache__/
@ -100,4 +99,4 @@ ENV/
.DS_Store
*.sqlite
.*_cache
.*_cache

View File

@ -6,13 +6,13 @@
# Magic-Spoiler [![Discord](https://img.shields.io/discord/314987288398659595?label=Discord&logo=discord&logoColor=white)](https://discord.gg/3Z9yzmA) [![Gitter Chat](https://img.shields.io/gitter/room/Cockatrice/Magic-Spoiler)](https://gitter.im/Cockatrice/Magic-Spoiler) #
Magic-Spoiler is a Python script to scrape <i>[Scryfall](https://scryfall.com)</i> to compile XML files (Cockatrice formatted) and application-ready json files (mtgjson formatted) with information about spoiled cards from upcoming sets.
Magic-Spoiler is a Python script to scrape <i>[Scryfall](https://scryfall.com)</i> to compile XML files (Cockatrice formatted) and application-ready JSON files (MTGJSON formatted) with information about spoiled cards from upcoming sets.
## Output [![Build Status](https://travis-ci.org/Cockatrice/Magic-Spoiler.svg?branch=master)](https://travis-ci.org/Cockatrice/Magic-Spoiler) ##
## Output [![Build Status](https://github.com/Cockatrice/Magic-Spoiler/workflows/Deploy/badge.svg?branch=master&event=schedule)](https://github.com/Cockatrice/Magic-Spoiler/actions?query=workflow%3ADeploy+event%3Aschedule+branch%3Amaster) ##
Just looking for XML or JSON files? [They are in our `files` branch!](https://github.com/Cockatrice/Magic-Spoiler/tree/files)
When run by Travis, the script automatically updates the files and uploads new versions there. ([History of changes](https://github.com/Cockatrice/Magic-Spoiler/commits/files))<br>
Travis CI is run daily on a cron job basis.
When run by our CI, the script automatically updates the files and uploads new versions to this branch. ([History of changes](https://github.com/Cockatrice/Magic-Spoiler/commits/files))<br>
GitHub Actions are scheduled to autoamtically run on a daily basis.
## Errors ##
Noticed an error in the card data? Check out our [Contributing file](https://github.com/Cockatrice/Magic-Spoiler/blob/master/.github/CONTRIBUTING.md) for information on how to help!

View File

@ -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__":