Skip to content

Commit 4eac02c

Browse files
committed
First workflow
1 parent 40bcb8b commit 4eac02c

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: JSON Tests Workflow
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'tests/**'
7+
8+
jobs:
9+
run_tests:
10+
name: Run JSON Schema Tests
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Repository
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.x'
21+
22+
- name: Install dependencies
23+
run: pip install PyGithub
24+
25+
- name: Run Python script
26+
run: python json_tests_workflow.py
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
GITHUB_REF: ${{ github.ref }}
30+
GITHUB_REPOSITORY: ${{ github.repository }}
31+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from github import Github
2+
import os
3+
import sys
4+
5+
def commit_and_push_changes(repo, branch, commit_message):
6+
try:
7+
repo.git.add(update=True)
8+
repo.index.commit(commit_message)
9+
origin = repo.remote(name='origin')
10+
origin.push(refspec=branch)
11+
print("Changes committed and pushed successfully.")
12+
except Exception as e:
13+
print(f"Error occurred while committing and pushing changes: {str(e)}")
14+
15+
def main():
16+
# GitHub authentication using personal access token
17+
# Replace 'YOUR_PERSONAL_ACCESS_TOKEN' with your actual token
18+
g = Github(os.environ.get('GITHUB_REPOSITORY'))
19+
20+
# Get repository and pull request number from environment variables
21+
repo_name = os.environ.get('GITHUB_REPOSITORY')
22+
pull_request_number = os.environ.get('GITHUB_REF').split('/')[-1]
23+
24+
if not repo_name or not pull_request_number:
25+
print("Repository name or pull request number not found in environment variables.")
26+
sys.exit(1)
27+
28+
# Get repository object
29+
repo = g.get_repo(repo_name)
30+
31+
# Get the pull request object
32+
pr = repo.get_pull(int(pull_request_number))
33+
34+
# Get the list of changed files in the pull request
35+
changed_files = [file.filename for file in pr.get_files()]
36+
37+
print(changed_files)
38+
# Filter the list to include only JSON files in the 'tests' directory
39+
# changed_json_files = [file for file in changed_files if file.startswith('tests/') and file.endswith('.json')]
40+
41+
# if changed_json_files:
42+
# # Commit and push changes
43+
# commit_message = "Update JSON files"
44+
# commit_and_push_changes(repo, pr.base.ref, commit_message)
45+
# else:
46+
# print("No changes detected in JSON files.")
47+
48+
if __name__ == "__main__":
49+
main()

0 commit comments

Comments
 (0)