1515 if : github.repository_owner == 'MicrosoftDocs'
1616
1717 steps :
18+ # Checkout the automation branch
19+ - name : Checkout automation branch
20+ uses : actions/checkout@v3
21+ with :
22+ ref : automation # Explicitly check out the automation branch
23+
1824 # Set up Python
1925 - name : Set up Python
2026 uses : actions/setup-python@v4
3137 env :
3238 GITHUB_ACCESS_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3339 run : |
34- python -c "
35- from datetime import datetime
36- import os
37- import sys
38- import time
39-
40- from github import Github
41- from github.GithubException import GithubException
42-
43- # Create a Github instance
44- # Access the secret
45- access_token = os.getenv("GITHUB_ACCESS_TOKEN")
46- github = Github(access_token)
47- # Support private
48- repo = github.get_repo("MicrosoftDocs/SupportArticles-docs-pr")
49- # Get the current date and time
50- current_date_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
51- # Pull request content
52- title = f"Auto push to live {current_date_time}"
53- body = "Daily auto push to live."
54- head = "main" # Format: "username:branch"
55- base = "live" # The branch you want to merge your changes into
56- finish_commit = (f'Successfully push to live at {current_date_time}.')
57- # Start process
58- try:
59- # Check if a PR from 'main' to 'live' already exists
60- existing_prs = repo.get_pulls(state='open', head=head, base=base)
61- if existing_prs.totalCount > 0:
62- print(f'Found existing PR(s) from "{head}" to "{base}".\n {'\n '.join(pr.html_url for pr in existing_prs)}')
63- sys.exit(1)
64- print(f'Start creating pull request.')
65- pull_request = repo.create_pull(title=title, body=body, head=head, base=base)
66- print(f"PR created: {pull_request.html_url}. Start merging.")
67- # Merge
68- time.sleep(5)
69- pull_request.merge()
70- print('Success push to live.')
71- sys.exit(0)
72- except GithubException as e:
73- print(f"Error: {str(e)}")
74- sys.exit(1)
75- "
76-
40+ python scripts/auto_push.py
0 commit comments