-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6138fc
commit 3036d02
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Commit User Records | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # or your default branch | ||
workflow_dispatch: | ||
|
||
jobs: | ||
commit: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Install dependencies | ||
run: | | ||
pip install PyGithub | ||
- name: Commit and push user records | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
python -c " | ||
import os | ||
import json | ||
from github import Github | ||
|
||
# GitHub repository details | ||
GITHUB_REPO_OWNER = 'ChrisTitusTech' | ||
GITHUB_REPO_NAME = 'WinUtil' | ||
FILE_PATH = 'user_records.json' | ||
|
||
# Load user records (simulate here, you may use actual logic) | ||
user_records = {'example_user_id': {'github_username': 'example_user', 'contributions': 'some_status'}} | ||
|
||
# Convert user records to JSON | ||
file_content = json.dumps(user_records, indent=4) | ||
|
||
# Initialize GitHub client | ||
g = Github(os.getenv('GITHUB_TOKEN')) | ||
repo = g.get_repo(f'{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}') | ||
|
||
# Update or create file in the repository | ||
try: | ||
file = repo.get_contents(FILE_PATH) | ||
repo.update_file(file.path, 'Update user records', file_content, file.sha) | ||
except: | ||
repo.create_file(FILE_PATH, 'Create user records file', file_content) | ||
|
||
print('User records committed successfully.') | ||
" |