-
Notifications
You must be signed in to change notification settings - Fork 38
94 lines (81 loc) · 3.33 KB
/
ci.yml
File metadata and controls
94 lines (81 loc) · 3.33 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
name: Update README
on:
push:
branches:
- master
pull_request:
branches:
- master
# Top-level permissions to be inherited by all jobs
permissions:
contents: write
pull-requests: write
issues: write
jobs:
update-readme:
runs-on: ubuntu-latest
# Explicitly set permissions for this job to ensure they're properly inherited
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x" # Use the latest Python version
- name: Setup GitHub CLI
run: |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
- name: Run Python script to update README
run: |
python generate_readme.py
- name: Commit changes if any
run: |
git config --local user.name "github-actions"
git config --local user.email "github-actions@github.com"
git add README.md
if git diff-index --cached --quiet HEAD; then
echo "No changes to commit."
else
git commit -m "Update README with new data"
fi
- name: Find changed theme files
if: github.event_name == 'pull_request'
id: changed_files
run: |
# Get list of changed files in the PR using GitHub CLI
PR_FILES=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files \
--jq '.[].filename' | grep -v ".github/" | head -1)
# Extract theme directory name if it exists
if [[ $PR_FILES =~ ^([^/]+)/ ]]; then
THEME_DIR="${BASH_REMATCH[1]}"
echo "CHANGED_FILE=$THEME_DIR" >> $GITHUB_ENV
echo "Theme directory detected: $THEME_DIR"
echo "found=true" >> $GITHUB_OUTPUT
else
echo "No theme directory changes detected in PR"
echo "found=false" >> $GITHUB_OUTPUT
fi
- name: Generate theme comment
if: github.event_name == 'pull_request' && steps.changed_files.outputs.found == 'true'
run: |
python theme_comment.py
- name: Post comment on PR
if: github.event_name == 'pull_request' && steps.changed_files.outputs.found == 'true'
run: |
# Set the GitHub token for CLI authentication
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
# Post comment using GitHub CLI
gh pr comment ${{ github.event.pull_request.number }} --body-file pr_comment.md
- name: Push changes to remote repository
# Only push changes on push events to master, not on pull requests
if: github.event_name == 'push' && success()
run: |
# Using the built-in GITHUB_TOKEN with updated permissions
git push "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"