Support Report Generator #124
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Support Report Generator | |
on: | |
schedule: | |
- cron: '0 5,13,21 * * *' # Runs at 12am, 8am, 4pm EST consistently | |
workflow_dispatch: | |
permissions: | |
issues: write | |
contents: write | |
jobs: | |
run-private-script: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Support Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: pieces-app/support | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
path: support | |
fetch-depth: 0 # Fetch all history for all branches | |
- name: Checkout Private Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: pieces-app/support_automation | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
path: support_automation | |
fetch-depth: 0 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install Dependencies | |
run: | | |
pip install -r support_automation/requirements.txt | |
- name: Get Monday Date | |
id: monday_date | |
run: | | |
echo "MONDAY_DATE=$(date -d 'monday this week' +'%Y-%m-%d')" >> $GITHUB_ENV | |
- name: Configure Git | |
run: | | |
cd support | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Checkout or Create Support Repo Branch | |
run: | | |
cd support | |
BRANCH_NAME="report_${MONDAY_DATE}" | |
git fetch origin | |
if git show-ref --verify --quiet refs/remotes/origin/$BRANCH_NAME; then | |
# If the branch exists on remote, check it out and pull the latest changes | |
git checkout $BRANCH_NAME | |
git pull origin $BRANCH_NAME | |
else | |
# If the branch does not exist, create it from main (or your default branch) | |
git checkout -b $BRANCH_NAME main | |
fi | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
- name: Checkout or Create Support Automation Repo Branch | |
run: | | |
cd support_automation | |
BRANCH_NAME="report_${MONDAY_DATE}" | |
git fetch origin | |
if git show-ref --verify --quiet refs/remotes/origin/$BRANCH_NAME; then | |
# If the branch exists on remote, check it out and pull the latest changes | |
git checkout $BRANCH_NAME | |
git pull origin $BRANCH_NAME | |
else | |
# If the branch does not exist, create it from main (or your default branch) | |
git checkout -b $BRANCH_NAME main | |
fi | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
- name: Run Daily Report Script | |
env: | |
SUPPORT_BOT_APP_ID: ${{ secrets.SUPPORT_BOT_APP_ID }} | |
SUPPORT_BOT_INSTALLATION_ID: ${{ secrets.SUPPORT_BOT_INSTALLATION_ID }} | |
SUPPORT_BOT_PRIVATE_KEY: ${{ secrets.SUPPORT_BOT_PRIVATE_KEY }} | |
SUPPORT_TRIAGE_BOT: ${{ secrets.SUPPORT_TRIAGE_BOT }} | |
run: | | |
python support_automation/triage_bot/main.py report ${{ github.repository }} daily | |
- name: Run Weekly Report Script | |
env: | |
SUPPORT_BOT_APP_ID: ${{ secrets.SUPPORT_BOT_APP_ID }} | |
SUPPORT_BOT_INSTALLATION_ID: ${{ secrets.SUPPORT_BOT_INSTALLATION_ID }} | |
SUPPORT_BOT_PRIVATE_KEY: ${{ secrets.SUPPORT_BOT_PRIVATE_KEY }} | |
SUPPORT_TRIAGE_BOT: ${{ secrets.SUPPORT_TRIAGE_BOT }} | |
run: | | |
python support_automation/triage_bot/main.py report ${{ github.repository }} weekly | |
- name: Commit and Push Changes to Support Automation Repo | |
run: | | |
cd support_automation | |
git add -A | |
git commit -m "Add support triage report for $(date +'%Y-%m-%d') [skip ci]" || echo "No changes to commit" | |
# Push changes and set upstream if not already set | |
git push --set-upstream origin $BRANCH_NAME | |
- name: Create Pull Request for Support Automation Repo | |
env: | |
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
run: | | |
cd support_automation | |
BRANCH_NAME="report_${MONDAY_DATE}" | |
# Check if PR already exists | |
PR_EXISTS=$(gh pr list --head $BRANCH_NAME --json number -q '.[0].number') | |
if [ -z "$PR_EXISTS" ]; then | |
# Create new PR if none exists | |
gh pr create \ | |
--title "Support Triage Report for $(date +'%Y-%m-%d')" \ | |
--body "Automated support triage report generation for $(date +'%Y-%m-%d')" \ | |
--base main \ | |
--head $BRANCH_NAME | |
else | |
echo "Pull Request already exists for branch $BRANCH_NAME." | |
fi | |
- name: Copy Reports to Support Repo | |
run: | | |
if [ ! -d "support/reports" ]; then | |
mkdir -p support/reports | |
fi | |
# Copy daily reports | |
cp -rn support_automation/reports/* support/reports/ 2>/dev/null || true | |
cp -ru support_automation/reports/* support/reports/ | |
- name: Commit and Push Changes to Support Repo | |
run: | | |
cd support | |
git add -A | |
git commit -m "Add support triage report for $(date +'%Y-%m-%d') [skip ci]" || echo "No changes to commit" | |
# Push changes and set upstream if not already set | |
git push --set-upstream origin $BRANCH_NAME | |
- name: Create Pull Request for Support Repo | |
env: | |
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
run: | | |
cd support | |
BRANCH_NAME="report_${MONDAY_DATE}" | |
# Check if PR already exists | |
PR_EXISTS=$(gh pr list --head $BRANCH_NAME --json number -q '.[0].number') | |
if [ -z "$PR_EXISTS" ]; then | |
# Create new PR if none exists | |
gh pr create \ | |
--title "Support Triage Report for $(date +'%Y-%m-%d')" \ | |
--body "Automated support triage report generation for $(date +'%Y-%m-%d')" \ | |
--base main \ | |
--head $BRANCH_NAME | |
else | |
echo "Pull Request already exists for branch $BRANCH_NAME." | |
fi | |
- name: Always clean up resources | |
if: always() | |
run: | | |
rm -rf ~/.ssh | |
rm -rf support_automation | |
rm -rf support | |
unset SUPPORT_BOT_APP_ID | |
unset SUPPORT_BOT_INSTALLATION_ID | |
unset SUPPORT_BOT_PRIVATE_KEY | |
unset SUPPORT_TRIAGE_BOT |