Skip to content

Commit 9e3cabc

Browse files
Fix permissions issues in the direct commit (#416)
* Fix permissions issues * create a pr instead of a direct commit
1 parent 558189f commit 9e3cabc

1 file changed

Lines changed: 41 additions & 7 deletions

File tree

.github/workflows/data-processing.yml

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
runs-on: ubuntu-22.04
1616
permissions:
1717
contents: read
18+
pull-requests: write
1819
env:
1920
PYTHON_VERSION: "3.11"
2021
steps:
@@ -131,26 +132,59 @@ jobs:
131132
exit 1
132133
fi
133134
134-
- name: Commit and push GA data to master
135+
- name: Create PR for GA data update
135136
if: github.event_name != 'pull_request'
136137
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
138153
139154
# Configure git
140155
git config --local user.email "action@github.com"
141156
git config --local user.name "GitHub Action"
142157
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
144163
git checkout master
164+
git checkout -b "$BRANCH_NAME"
145165
146-
# Add and commit the GA data file directly
166+
# Add and commit the GA data file
147167
echo "Adding GA data file..."
148168
git add data/ga_data.json
149169
git commit -m "Update GA data - $(date -u +'%Y-%m-%d %H:%M:%S UTC')"
150170
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 }}
154188

155189
- name: Run Google Scholar script
156190
continue-on-error: true # Continue even if this step fails

0 commit comments

Comments
 (0)