-
-
Notifications
You must be signed in to change notification settings - Fork 3k
195 lines (169 loc) Β· 6.61 KB
/
generate-changelog.yml
File metadata and controls
195 lines (169 loc) Β· 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Generate Data Changelogs
on:
push:
branches:
- master
paths:
- 'contributions/**'
- 'bin/scripts/changelog/**'
- '.github/workflows/generate-changelog.yml'
workflow_dispatch:
inputs:
retention_months:
description: 'Retention period in months'
required: false
default: '48'
full_history:
description: 'Process full git history'
type: boolean
default: true
target_repo:
description: 'Target repository (owner/repo)'
required: false
default: 'dr5hn/csc-changelog'
env:
TARGET_REPO: ${{ github.event.inputs.target_repo || 'dr5hn/csc-changelog' }}
TARGET_BRANCH: 'main'
jobs:
generate-changelogs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full git history needed
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install -r bin/scripts/changelog/requirements-changelog.txt
- name: Validate repository
run: |
echo "Repository: $(pwd)"
echo "Git status:"
git status
echo ""
echo "Checking contributions/ directory:"
ls -lh contributions/
echo ""
echo "Recent commits to contributions/:"
git log --oneline -10 -- contributions/ || echo "No commits found"
- name: Generate changelogs
run: |
echo "================================================"
echo "Starting Changelog Generation"
echo "================================================"
RETENTION_MONTHS="${{ github.event.inputs.retention_months || '24' }}"
python3 bin/scripts/changelog/changelog_generator.py \
--retention-months ${RETENTION_MONTHS} \
--show-sizes
echo ""
echo "================================================"
echo "Generation Complete"
echo "================================================"
- name: Check generated files
run: |
echo "Changelog directory structure:"
tree -L 2 changelogs/ || ls -R changelogs/
echo ""
echo "File sizes:"
du -sh changelogs/
du -sh changelogs/countries/ 2>/dev/null || echo "No countries directory"
du -sh changelogs/archives/ 2>/dev/null || echo "No archives directory"
- name: Clone target repository
run: |
echo "Cloning target repository: $TARGET_REPO"
cd ..
git clone https://x-access-token:${{ secrets.CHANGELOG_REPO_TOKEN }}@github.com/$TARGET_REPO.git changelog-repo
cd changelog-repo
# Configure git
git config user.name "Changelog Bot"
git config user.email "bot@changelog.countrystatecity.in"
# Create new branch for this update
BRANCH_NAME="update-changelog-$(date -u '+%Y%m%d-%H%M%S')"
git checkout -b $BRANCH_NAME
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Copy changelogs to target repo
run: |
echo "Copying generated changelogs to target repository..."
cp -r changelogs/* ../changelog-repo/
echo ""
echo "Files copied to target repo:"
ls -lh ../changelog-repo/
- name: Commit and push to target repo
run: |
cd ../changelog-repo
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
else
COMMIT_MSG="π Update changelogs - $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
COMMIT_MSG="${COMMIT_MSG}\n\nAuto-generated from: ${{ github.repository }}@${{ github.sha }}"
COMMIT_MSG="${COMMIT_MSG}\nTriggered by: ${{ github.event_name }}"
git commit -m "${COMMIT_MSG}"
git push origin $BRANCH_NAME
echo "HAS_CHANGES=true" >> $GITHUB_ENV
fi
- name: Create Pull Request in target repo
if: env.HAS_CHANGES == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CHANGELOG_REPO_TOKEN }}
script: |
const [owner, repo] = process.env.TARGET_REPO.split('/');
const prBody = [
'## Automated Changelog Update',
'',
`π€ Auto-generated from [\`${context.repo.owner}/${context.repo.repo}\`](https://github.com/${context.repo.owner}/${context.repo.repo})`,
'',
'### Source',
`- Commit: ${context.sha.substring(0, 7)}`,
`- Trigger: ${context.eventName}`,
`- Message: ${context.payload.head_commit?.message || 'Manual workflow dispatch'}`,
'',
'### Changes',
'This PR contains updated changelog data from the latest database changes.',
'',
'### Review Checklist',
'- [ ] Verify changelog file sizes are reasonable',
'- [ ] Check that statistics are updated',
'- [ ] Confirm website will display correctly',
'',
'---',
'',
'*To merge automatically, approve this PR or configure auto-merge.*'
].join('\n');
const { data: pr } = await github.rest.pulls.create({
owner,
repo,
title: 'π Update changelogs - ' + new Date().toISOString().split('T')[0],
head: process.env.BRANCH_NAME,
base: process.env.TARGET_BRANCH,
body: prBody
});
console.log(`Pull request created: ${pr.html_url}`);
core.setOutput('pr_url', pr.html_url);
core.setOutput('pr_number', pr.number);
- name: Summary
run: |
echo "================================================"
echo "Changelog Generation Summary"
echo "================================================"
echo "β
Changelogs generated successfully"
if [ "$HAS_CHANGES" = "true" ]; then
echo "β
Pull request created in $TARGET_REPO"
echo "π Branch: $BRANCH_NAME"
else
echo "βΉοΈ No changes detected"
fi
echo ""
echo "Target repository: $TARGET_REPO"
echo "================================================"