🐛 Fix FastAPI People GitHub Action when there's nothing to change (#2196)

This commit is contained in:
Sebastián Ramírez 2020-10-18 21:45:10 +02:00 committed by GitHub
parent 1ea24e1813
commit 479e87e467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -1,13 +1,14 @@
import logging import logging
import subprocess import subprocess
import sys
from collections import Counter from collections import Counter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from pathlib import Path from pathlib import Path
from typing import Container, Dict, List, Optional, Set from typing import Container, Dict, List, Optional, Set
import httpx import httpx
from github import Github
import yaml import yaml
from github import Github
from pydantic import BaseModel, BaseSettings, SecretStr from pydantic import BaseModel, BaseSettings, SecretStr
github_graphql_url = "https://api.github.com/graphql" github_graphql_url = "https://api.github.com/graphql"
@ -487,13 +488,17 @@ if __name__ == "__main__":
"sponsors": sponsors, "sponsors": sponsors,
} }
people_path = Path("./docs/en/data/people.yml") people_path = Path("./docs/en/data/people.yml")
people_path.write_text( people_old_content = people_path.read_text(encoding="utf-8")
yaml.dump(people, sort_keys=False, width=200, allow_unicode=True), new_content = yaml.dump(people, sort_keys=False, width=200, allow_unicode=True)
encoding="utf-8", if people_old_content == new_content:
) logging.info("The FastAPI People data hasn't changed, finishing.")
sys.exit(0)
people_path.write_text(new_content, encoding="utf-8")
logging.info("Setting up GitHub Actions git user") logging.info("Setting up GitHub Actions git user")
subprocess.run(["git", "config", "user.name", "github-actions"], check=True) subprocess.run(["git", "config", "user.name", "github-actions"], check=True)
subprocess.run(["git", "config", "user.email", "github-actions@github.com"], check=True) subprocess.run(
["git", "config", "user.email", "github-actions@github.com"], check=True
)
branch_name = "fastapi-people" branch_name = "fastapi-people"
logging.info(f"Creating a new branch {branch_name}") logging.info(f"Creating a new branch {branch_name}")
subprocess.run(["git", "checkout", "-b", branch_name], check=True) subprocess.run(["git", "checkout", "-b", branch_name], check=True)