Skip to content

Commit 99e67a8

Browse files
committed
update automation workflow
1 parent 42ac7fe commit 99e67a8

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

.github/workflows/automation.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ on:
66
# Temporarily set automation to one branch to avoid issues w/ main codebase
77
- automation-workflow
88
schedule:
9-
- cron: '0 0 1 */3 *' # Run at midnight on the first day of every quarter
9+
# Fetch data at 1:15 AM, days 1-20, first month of each quarter
10+
- cron: '15 1 1-20 1,4,7,10 *'
11+
# Process data at 1:15 AM, days 1-20, second month of each quarter
12+
- cron: '15 1 1-20 2,5,8,11 *'
13+
# Generate report at 1:15 AM, days 1-20, third month of each quarter
14+
- cron: '15 1 1-20 3,6,9,12 *'
1015
workflow_dispatch:
1116

1217
jobs:
@@ -41,7 +46,7 @@ jobs:
4146
env:
4247
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4348
run: |
44-
python scripts/git_operations.py --operation commit --message "Automated data fetch and commit"
49+
python scripts/shared.py --operation commit --message "Automated data fetch and commit"
4550
4651
process:
4752
runs-on: ubuntu-latest
@@ -75,7 +80,7 @@ jobs:
7580
env:
7681
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7782
run: |
78-
python scripts/git_operations.py --operation commit --message "Automated data processing and commit"
83+
python scripts/shared.py --operation commit --message "Automated data processing and commit"
7984
8085
report:
8186
runs-on: ubuntu-latest
@@ -109,4 +114,4 @@ jobs:
109114
env:
110115
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111116
run: |
112-
python scripts/git_operations.py --operation commit --message "Automated report generation and commit"
117+
python scripts/shared.py --operation commit --message "Automated report generation and commit"

scripts/shared.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Standard library
2+
import argparse
23
import logging
34
import os
45
from datetime import datetime, timezone
56

67
# Third-party
8+
from git import InvalidGitRepositoryError, NoSuchPathError, Repo
79
from pandas import PeriodIndex
810

911

@@ -48,3 +50,44 @@ def log_paths(logger, paths):
4850
paths_list.append(f"\n{' ' * 12}{label:<11} {path}")
4951
paths_list = "".join(paths_list)
5052
logger.info(f"PATHS:{paths_list}")
53+
54+
55+
def commit_changes(message):
56+
repo_path = os.getcwd()
57+
try:
58+
repo = Repo(repo_path)
59+
except InvalidGitRepositoryError:
60+
logging.error(f"Invalid Git repository at {repo_path}")
61+
return
62+
except NoSuchPathError:
63+
logging.error(f"No such path: {repo_path}")
64+
return
65+
66+
repo.git.add(update=True)
67+
repo.index.commit(message)
68+
origin = repo.remote(name="origin")
69+
origin.push()
70+
71+
72+
def main():
73+
parser = argparse.ArgumentParser(description="Git operations script")
74+
parser.add_argument(
75+
"--operation",
76+
type=str,
77+
required=True,
78+
help="Operation to perform: commit",
79+
)
80+
parser.add_argument(
81+
"--message", type=str, required=True, help="Commit message"
82+
)
83+
84+
args = parser.parse_args()
85+
86+
if args.operation == "commit":
87+
commit_changes(args.message)
88+
else:
89+
raise ValueError("Unsupported operation")
90+
91+
92+
if __name__ == "__main__":
93+
main()

0 commit comments

Comments
 (0)