4
4
- cron : ' 0 0 1 * *' # Run monthly on the 1st at midnight
5
5
workflow_dispatch : # Allow manual trigger
6
6
7
+ permissions :
8
+ issues : write
9
+ contents : read
10
+
7
11
jobs :
8
12
check_freshness :
9
13
runs-on : ubuntu-latest
@@ -15,19 +19,29 @@ jobs:
15
19
- uses : actions/setup-python@v4
16
20
with :
17
21
python-version : ' 3.x'
22
+
23
+ - name : Install dependencies
24
+ run : |
25
+ python -m pip install --upgrade pip
26
+ pip install requests
18
27
19
- - name : Create scripts directory
20
- run : mkdir -p .github/scripts
21
-
22
- - name : Copy Python script
28
+ - name : Create and run freshness check script
29
+ env :
30
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23
31
run : |
24
- cat > .github/scripts/ check_freshness.py << 'EOL'
32
+ cat > check_freshness.py << 'EOL'
25
33
import os
26
34
import subprocess
35
+ import requests
27
36
from datetime import datetime, timedelta
28
37
29
- FRESHNESS_PERIOD = timedelta(days=180) # 6 months
30
- IGNORED_FILES = ["_index.md"] # Add any files to ignore
38
+ # Configuration
39
+ FRESHNESS_PERIOD = timedelta(days=180) # 180 days (6 months)
40
+ IGNORED_FILES = ["_index.md"]
41
+ GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
42
+ GITHUB_REPO = os.environ.get('GITHUB_REPOSITORY', 'owner/repo')
43
+ GITHUB_API_URL = f"https://api.github.com/repos/{GITHUB_REPO}/issues"
44
+
31
45
now = datetime.now()
32
46
33
47
def get_last_modified_time(file_path):
55
69
stale_files.append((relative_path, last_modified))
56
70
return stale_files
57
71
58
- docs_directory = "docs/content/master" # Crossplane docs directory
72
+ def create_github_issue(body):
73
+ if not GITHUB_TOKEN:
74
+ print("Error: GITHUB_TOKEN environment variable not set")
75
+ return False
76
+
77
+ headers = {
78
+ 'Authorization': f'token {GITHUB_TOKEN}',
79
+ 'Accept': 'application/vnd.github.v3+json'
80
+ }
81
+
82
+ issue_data = {
83
+ 'title': '📚 Documentation Freshness Check Results',
84
+ 'body': body,
85
+ 'labels': ['documentation', 'maintenance']
86
+ }
87
+
88
+ response = requests.post(GITHUB_API_URL, headers=headers, json=issue_data)
89
+ if response.status_code == 201:
90
+ print(f"Issue created successfully: {response.json()['html_url']}")
91
+ return True
92
+ else:
93
+ print(f"Failed to create issue. Status code: {response.status_code}")
94
+ print(f"Response: {response.text}")
95
+ return False
96
+
97
+ # Main execution
98
+ docs_directory = "content"
59
99
stale_docs = check_freshness(docs_directory)
60
100
sorted_stale_docs = sorted(stale_docs, key=lambda x: x[1])
61
101
@@ -66,37 +106,10 @@ jobs:
66
106
issue_body += f"- `{doc}` (Last Modified: {mod_time.strftime('%Y-%m-%d')})\n"
67
107
issue_body += "\nPlease review these documents to ensure they are up-to-date and accurate."
68
108
69
- with open("issue_body.txt", "w") as f:
70
- f.write(issue_body)
71
-
72
- with open("has_stale.txt", "w") as f:
73
- f.write("true")
109
+ print(issue_body) # Print to console
110
+ create_github_issue(issue_body) # Create GitHub issue
74
111
else:
75
- with open("has_stale.txt", "w") as f:
76
- f.write("false")
112
+ print("All documentation is up to date!")
77
113
EOL
78
-
79
- - name : Run freshness check
80
- run : python3 .github/scripts/check_freshness.py
81
-
82
- - name : Check for stale docs
83
- id : check
84
- run : |
85
- HAS_STALE=$(cat has_stale.txt)
86
- echo "has_stale=$HAS_STALE" >> $GITHUB_OUTPUT
87
-
88
- - name : Create Issue
89
- if : steps.check.outputs.has_stale == 'true'
90
- uses : actions/github-script@v6
91
- with :
92
- script : |
93
- const fs = require('fs');
94
- const issueBody = fs.readFileSync('issue_body.txt', 'utf8');
95
-
96
- await github.rest.issues.create({
97
- owner: context.repo.owner,
98
- repo: context.repo.repo,
99
- title: '📚 Documentation Freshness Check Results',
100
- body: issueBody,
101
- labels: ['documentation', 'maintenance']
102
- });
114
+
115
+ python check_freshness.py
0 commit comments