-
Notifications
You must be signed in to change notification settings - Fork 3
130 lines (117 loc) · 4.07 KB
/
Copy pathvalidate.yml
File metadata and controls
130 lines (117 loc) · 4.07 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Validate & Publish
on:
pull_request_target:
types: [opened, synchronize, reopened]
paths:
- 'incoming/**'
push:
branches: [main]
paths:
- 'incoming/**'
permissions:
contents: write
pull-requests: write
jobs:
validate:
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
allow-unsafe-pr-checkout: true
- uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Validate bundles
id: validate
shell: bash
run: |
set +e
exit_code=0
truncate -s 0 /tmp/validate_output.txt
files=(incoming/*.klyx)
if [ -f "${files[0]}" ]; then
echo "Checking ownership and validating bundles..." | tee -a /tmp/validate_output.txt
python3 .github/workflows/check_owner.py \
"${{ github.event.pull_request.user.login }}" \
"${files[@]}" 2>&1 | tee -a /tmp/validate_output.txt
[ $? -ne 0 ] && exit_code=1
for f in incoming/*.klyx; do
[ ! -f "$f" ] && continue
python3 .github/workflows/validate_bundle.py "$f" 2>&1 | tee -a /tmp/validate_output.txt
[ $? -ne 0 ] && exit_code=1
done
else
echo "No incoming bundles to validate." | tee -a /tmp/validate_output.txt
fi
exit $exit_code
- name: Post validation comment
if: always()
env:
GH_TOKEN: ${{ github.token }}
run: |
python3 .github/workflows/format_comment.py \
"${{ steps.validate.outcome }}" > /tmp/comment_body.txt
gh pr comment ${{ github.event.pull_request.number }} \
--body-file /tmp/comment_body.txt
publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
- uses: actions/setup-python@v6
with:
python-version: '3.14'
- name: Check for bundles
id: check
run: |
count=$(ls -1 incoming/*.klyx 2>/dev/null | wc -l)
echo "count=$count" >> "$GITHUB_OUTPUT"
- name: Get PR author for owner fallback
if: steps.check.outputs.count != '0'
id: pr_author
env:
GH_TOKEN: ${{ secrets.BOT_PAT }}
run: |
PR_NUM=$(git log -1 --format="%s" | sed -n 's/.*#\([0-9]\+\).*/\1/p')
AUTHOR=""
if [ -n "$PR_NUM" ]; then
AUTHOR=$(gh pr view "$PR_NUM" --json author --jq '.author.login' 2>/dev/null || echo "")
fi
echo "author=${AUTHOR:-${{ github.actor }}}" >> "$GITHUB_OUTPUT"
- name: Publish bundles
if: steps.check.outputs.count != '0'
env:
BOT_PAT: ${{ secrets.BOT_PAT }}
run: |
OWNER="${{ steps.pr_author.outputs.author }}"
if [ -n "$OWNER" ]; then
python3 .github/workflows/publish.py --default-owner "$OWNER"
else
python3 .github/workflows/publish.py
fi
- name: Commit and push to main
if: steps.check.outputs.count != '0'
run: |
git config user.name "klyx-bot"
git config user.email "bot@klyx-dev.github.io"
git add plugins/ incoming/
if git diff --cached --quiet; then
echo "No changes to commit"
exit 0
fi
git remote set-url origin "https://x-access-token:${BOT_PAT}@github.com/klyx-dev/plugins.git"
git commit -m "publish plugins"
git push origin main
env:
BOT_PAT: ${{ secrets.BOT_PAT }}
- name: Purge jsDelivr cache
if: steps.check.outputs.count != '0'
run: |
curl -s "https://purge.jsdelivr.net/gh/klyx-dev/plugins@main/plugins/index.json"
python3 .github/workflows/purge_cache.py incoming/*.klyx 2>/dev/null || true