Skip to content

Commit baf2627

Browse files
committed
New workflows
1 parent 11858c4 commit baf2627

13 files changed

Lines changed: 509 additions & 13 deletions

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false

.github/pull_request_template.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Description
2+
3+
<!-- Provide a clear and concise description of what this PR does -->
4+
5+
## Type of Change
6+
7+
- [ ] 🐛 Bug fix
8+
- [ ] ✨ New feature
9+
- [ ] 📚 Documentation update
10+
- [ ] 🔨 Refactoring
11+
12+
## Changes Made
13+
14+
-
15+
-
16+
-
17+
18+
## Testing
19+
20+
- [ ] I have tested the bot changes
21+
- [ ] I have verified bot commands work correctly
22+
23+
## Checklist
24+
25+
- [ ] My code follows the project's style guidelines
26+
- [ ] I have performed a self-review of my code
27+
- [ ] I have updated the README.md if applicable

.github/workflows/fanex-id-bot.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: faneX-ID Bot
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
actions: write
13+
14+
jobs:
15+
bot:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v6
20+
21+
- name: Use faneX-ID Bot (self)
22+
uses: ./
23+
with:
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
enabled: true
26+

.github/workflows/housekeeping.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Housekeeping
2+
3+
on:
4+
schedule:
5+
- cron: '0 3 * * 0'
6+
workflow_dispatch:
7+
8+
permissions:
9+
actions: write
10+
contents: read
11+
12+
env:
13+
WORKFLOW_RUNS_RETENTION_DAYS: 90
14+
15+
jobs:
16+
cleanup-workflow-runs:
17+
name: Cleanup Old Workflow Runs
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Delete old workflow runs
21+
uses: Mattraks/delete-workflow-runs@v2
22+
with:
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
repository: ${{ github.repository }}
25+
retain_days: ${{ env.WORKFLOW_RUNS_RETENTION_DAYS }}
26+
keep_minimum_runs: 5
27+
delete_workflow_pattern: '*'
28+
delete_run_by_conclusion_pattern: |
29+
cancelled
30+
skipped
31+
failure
32+
33+
cleanup-caches:
34+
name: Cleanup Orphaned Caches
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Cleanup caches
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const owner = context.repo.owner;
42+
const repo = context.repo.repo;
43+
let caches = [];
44+
let page = 1;
45+
while (true) {
46+
const response = await github.rest.actions.getActionsCacheList({
47+
owner, repo, per_page: 100, page: page
48+
});
49+
caches = caches.concat(response.data.actions_caches);
50+
if (response.data.actions_caches.length < 100) break;
51+
page++;
52+
}
53+
let deletedCount = 0;
54+
for (const cache of caches) {
55+
if (cache.ref.startsWith('refs/pull/')) {
56+
const prNumber = cache.ref.match(/refs\/pull\/(\d+)/)?.[1];
57+
if (prNumber) {
58+
try {
59+
const pr = await github.rest.pulls.get({owner, repo, pull_number: parseInt(prNumber)});
60+
if (pr.data.state === 'closed') {
61+
await github.rest.actions.deleteActionsCacheById({owner, repo, cache_id: cache.id});
62+
deletedCount++;
63+
}
64+
} catch (e) {
65+
await github.rest.actions.deleteActionsCacheById({owner, repo, cache_id: cache.id});
66+
deletedCount++;
67+
}
68+
}
69+
}
70+
}
71+
console.log(`Deleted ${deletedCount} orphaned caches`);
72+

.github/workflows/pr-assistant.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: PR Assistant
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, closed]
6+
push:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
checks: write
14+
issues: write
15+
16+
jobs:
17+
pr-validation:
18+
if: github.event_name == 'pull_request' && github.event.action != 'closed'
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v6
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v6
26+
with:
27+
python-version: '3.12'
28+
29+
- name: Install Dependencies
30+
run: |
31+
pip install PyGithub requests pyyaml
32+
33+
- name: Validate Bot Scripts
34+
run: |
35+
python -m py_compile bot.py workflow_manager.py comment_handler.py
36+
37+
- name: Validate Action YAML
38+
run: |
39+
python << 'EOF'
40+
import yaml
41+
import sys
42+
try:
43+
with open('action.yml') as f:
44+
yaml.safe_load(f)
45+
print("✅ action.yml is valid")
46+
except Exception as e:
47+
print(f"❌ action.yml validation failed: {e}")
48+
sys.exit(1)
49+
EOF
50+
51+
- name: Feedback Comment
52+
if: always()
53+
uses: actions/github-script@v6
54+
with:
55+
script: |
56+
const outcome = '${{ job.status }}';
57+
if (outcome === 'failure') {
58+
github.rest.issues.createComment({
59+
issue_number: context.issue.number,
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
body: "❌ **PR Validation Failed**\n\nPlease check the validation errors above."
63+
});
64+
} else if (outcome === 'success') {
65+
github.rest.issues.createComment({
66+
issue_number: context.issue.number,
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
body: "✅ **PR Validation Passed**\n\nAll checks passed successfully!"
70+
});
71+
}
72+
73+
thank-you:
74+
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
75+
runs-on: ubuntu-latest
76+
steps:
77+
- uses: actions/github-script@v6
78+
with:
79+
script: |
80+
const author = context.payload.pull_request.user.login;
81+
const admins = ['FaserF', 'fabia', 'github-actions[bot]'];
82+
if (admins.includes(author)) return;
83+
github.rest.issues.createComment({
84+
issue_number: context.issue.number,
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
body: `🎉 **Thank you @${author}!**\n\nYour contribution to the **faneX-ID GitHub Bot** repository is valuable! 🚀`
88+
});
89+

.github/workflows/pr-autofix.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: PR Auto-Fix
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches: [main, master]
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
auto-fix:
13+
runs-on: ubuntu-latest
14+
if: github.actor != 'github-actions[bot]' && github.event.pull_request.head.repo.full_name == github.repository
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v6
18+
with:
19+
ref: ${{ github.head_ref }}
20+
fetch-depth: 0
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v6
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Install & Run Python Fixes
28+
run: |
29+
pip install black isort
30+
black . --extend-exclude="/(\.git|\.github|__pycache__|\.pytest_cache)/"
31+
isort . --profile black --skip-glob=".github/*"
32+
33+
- name: Check for changes & Commit
34+
run: |
35+
if [[ -n $(git status -s) ]]; then
36+
git config --global user.name 'github-actions[bot]'
37+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
38+
git add .
39+
git commit -m "style: auto-fix linting issues [skip ci]"
40+
git push origin HEAD:${{ github.head_ref }}
41+
fi
42+

.github/workflows/pr-thanks.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Thank Contributor
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
thank-you:
12+
if: github.event.pull_request.merged == true
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/github-script@v8
16+
with:
17+
script: |
18+
const author = context.payload.pull_request.user.login;
19+
const bots = ['github-actions[bot]', 'dependabot[bot]', 'renovate[bot]'];
20+
const admins = [context.repo.owner, 'FaserF', 'fabia'];
21+
if (admins.includes(author) || bots.includes(author)) return;
22+
github.rest.issues.createComment({
23+
issue_number: context.issue.number,
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
body: `🎉 **Thank you @${author}!**\n\nYour contribution to the **faneX-ID GitHub Bot** repository is valuable! 🚀`
27+
})
28+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: PR Validation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
branches: [main, master]
7+
8+
permissions:
9+
contents: read
10+
pull-requests: write
11+
checks: write
12+
13+
jobs:
14+
validate:
15+
name: "🛡️ Bot Validation"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v6
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v6
23+
with:
24+
python-version: '3.12'
25+
26+
- name: Install Tools
27+
run: |
28+
pip install PyGithub requests pyyaml
29+
30+
- name: Validate Python Syntax
31+
run: |
32+
python -m py_compile bot.py workflow_manager.py comment_handler.py
33+
34+
- name: Validate YAML Files
35+
run: |
36+
python << 'EOF'
37+
import yaml
38+
import sys
39+
for yaml_file in ['action.yml', 'config.yaml']:
40+
try:
41+
with open(yaml_file) as f:
42+
yaml.safe_load(f)
43+
print(f"✅ {yaml_file} is valid")
44+
except FileNotFoundError:
45+
print(f"⚠️ {yaml_file} not found, skipping")
46+
except Exception as e:
47+
print(f"❌ {yaml_file} validation failed: {e}")
48+
sys.exit(1)
49+
EOF
50+
51+
feedback:
52+
needs: [validate]
53+
runs-on: ubuntu-latest
54+
if: always()
55+
steps:
56+
- name: Comment on PR
57+
uses: actions/github-script@v8
58+
with:
59+
script: |
60+
const status = '${{ needs.validate.result }}';
61+
if (status === 'success') {
62+
github.rest.issues.createComment({
63+
issue_number: context.issue.number,
64+
owner: context.repo.owner,
65+
repo: context.repo.repo,
66+
body: "✅ **PR Validation Passed!**\n\nAll checks passed successfully."
67+
});
68+
} else {
69+
github.rest.issues.createComment({
70+
issue_number: context.issue.number,
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
body: "❌ **PR Validation Failed**\n\nPlease check the logs and fix the issues."
74+
});
75+
}
76+

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ runs:
2222
- name: Install dependencies
2323
shell: bash
2424
run: |
25-
pip install PyGithub requests
25+
pip install -r requirements.txt
26+
27+
- name: Checkout bot code
28+
uses: actions/checkout@v6
29+
with:
30+
repository: faneX-ID/github-bot
31+
path: github-bot
32+
token: ${{ inputs.github-token }}
2633

2734
- name: Run bot
2835
shell: bash
36+
working-directory: github-bot
2937
env:
3038
GITHUB_TOKEN: ${{ inputs.github-token }}
3139
GITHUB_REPOSITORY: ${{ github.repository }}

0 commit comments

Comments
 (0)