|
15 | 15 | runs-on: ubuntu-22.04 |
16 | 16 | permissions: |
17 | 17 | contents: read |
| 18 | + pull-requests: write |
18 | 19 | env: |
19 | 20 | PYTHON_VERSION: "3.11" |
20 | 21 | steps: |
@@ -131,26 +132,59 @@ jobs: |
131 | 132 | exit 1 |
132 | 133 | fi |
133 | 134 |
|
134 | | - - name: Commit and push GA data to master |
| 135 | + - name: Create PR for GA data update |
135 | 136 | if: github.event_name != 'pull_request' |
136 | 137 | run: | |
137 | | - echo "=== Committing GA data to master branch ===" |
| 138 | + echo "=== Creating PR for GA data update ===" |
| 139 | + |
| 140 | + # Check if it's the first day of the month OR manually triggered |
| 141 | + CURRENT_DAY=$(date +%d) |
| 142 | + if [ "$CURRENT_DAY" != "01" ] && [ "${{ github.event_name }}" != "workflow_dispatch" ]; then |
| 143 | + echo "ℹ️ Not the first day of the month ($CURRENT_DAY) and not manually triggered, skipping PR creation" |
| 144 | + echo "✅ GA data updated but no PR created (will create PR on 1st of month or manual trigger)" |
| 145 | + exit 0 |
| 146 | + fi |
| 147 | + |
| 148 | + if [ "$CURRENT_DAY" = "01" ]; then |
| 149 | + echo "📅 First day of month detected, creating PR for GA data update" |
| 150 | + else |
| 151 | + echo "🔧 Manual trigger detected, creating PR for GA data update" |
| 152 | + fi |
138 | 153 | |
139 | 154 | # Configure git |
140 | 155 | git config --local user.email "action@github.com" |
141 | 156 | git config --local user.name "GitHub Action" |
142 | 157 | |
143 | | - # Checkout master branch |
| 158 | + # Create a new branch for the GA data update |
| 159 | + BRANCH_NAME="ga-data-update-$(date +%Y%m%d)" |
| 160 | + echo "Creating branch: $BRANCH_NAME" |
| 161 | + |
| 162 | + # Checkout master and create new branch |
144 | 163 | git checkout master |
| 164 | + git checkout -b "$BRANCH_NAME" |
145 | 165 | |
146 | | - # Add and commit the GA data file directly |
| 166 | + # Add and commit the GA data file |
147 | 167 | echo "Adding GA data file..." |
148 | 168 | git add data/ga_data.json |
149 | 169 | git commit -m "Update GA data - $(date -u +'%Y-%m-%d %H:%M:%S UTC')" |
150 | 170 | |
151 | | - # Push to master branch |
152 | | - git push origin master |
153 | | - echo "✅ GA data committed and pushed to master branch" |
| 171 | + # Push the branch |
| 172 | + git push origin "$BRANCH_NAME" |
| 173 | + echo "✅ Branch pushed: $BRANCH_NAME" |
| 174 | + |
| 175 | + # Create a PR |
| 176 | + echo "Creating pull request..." |
| 177 | + gh pr create \ |
| 178 | + --title "📊 Monthly GA Data Update - $(date +%B %Y)" \ |
| 179 | + --body "Automated monthly Google Analytics data update. Generated on $(date -u +'%Y-%m-%d %H:%M:%S UTC'). Files changed: data/ga_data.json" \ |
| 180 | + --base master \ |
| 181 | + --head "$BRANCH_NAME" \ |
| 182 | + --label "automated,ga-data,monthly-update" |
| 183 | + |
| 184 | + echo "✅ PR created for GA data update" |
| 185 | + env: |
| 186 | + GITHUB_TOKEN: ${{ secrets.STAGING_GITHUB_TOKEN }} |
| 187 | + GH_TOKEN: ${{ secrets.STAGING_GITHUB_TOKEN }} |
154 | 188 |
|
155 | 189 | - name: Run Google Scholar script |
156 | 190 | continue-on-error: true # Continue even if this step fails |
|
0 commit comments