-
Notifications
You must be signed in to change notification settings - Fork 196
167 lines (151 loc) · 5.09 KB
/
publish_plugin.yml
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: plugin publish
on:
issues:
types: [opened, reopened, edited]
pull_request_target:
types: [closed]
issue_comment:
types: [created]
pull_request_review:
types: [submitted]
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number || github.run_id }}
cancel-in-progress: false
jobs:
check:
runs-on: ubuntu-latest
name: check
# do not run on forked PRs, do not run on not related issues, do not run on pr comments
if: |
!(
(
github.event.pull_request &&
(
github.event.pull_request.head.repo.fork ||
!(
contains(github.event.pull_request.labels.*.name, 'Plugin')
)
)
) ||
(
github.event_name == 'issue_comment' && github.event.issue.pull_request
)
)
steps:
- run: echo "Check passed"
reaction:
runs-on: ubuntu-latest
name: reaction
needs: check
if: |
(
github.event_name == 'issue_comment' &&
github.event.action == 'created'
) ||
(
github.event_name == 'issues' &&
github.event.action == 'opened'
)
steps:
- name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_KEY }}
- name: Reaction on issue
if: github.event_name == 'issues'
run: |
gh api --method POST /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/reactions -f "content=rocket"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Reaction on issue comment
if: github.event_name == 'issue_comment'
run: |
gh api --method POST /repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions -f "content=rocket"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
plugin_test:
runs-on: ubuntu-latest
name: zhenxun plugin test
needs: check
permissions:
issues: read
outputs:
result: ${{ steps.plugin-test.outputs.RESULT }}
output: ${{ steps.plugin-test.outputs.OUTPUT }}
metadata: ${{ steps.plugin-test.outputs.METADATA }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
id: setup_python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install Poetry
if: ${{ !startsWith(github.event_name, 'pull_request') }}
run: pip install poetry
# Poetry cache depends on OS, Python version and Poetry version.
- name: Cache Poetry cache
uses: actions/cache@v3
if: ${{ !startsWith(github.event_name, 'pull_request') }}
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}
- name: Setup zhenxun
id: setup-zhenxun
if: ${{ !startsWith(github.event_name, 'pull_request') }}
run: |
git clone -b dev https://github.com/Hibikier/zhenxun_bot.git
- name: Test Plugin
id: plugin-test
if: ${{ !startsWith(github.event_name, 'pull_request') }}
run: |
cd zhenxun_bot
rm -rf ./zhenxun/plugins/* poetry.lock
poetry source remove ali
poetry install --no-root
poetry run pip install pydantic==1.10
curl -sSL https://github.com/zhenxun-org/zhenxunflow/releases/latest/download/plugin_test.py | poetry run python -
- name: Test Plugin PR
id: plugin-test-pr
if: ${{ startsWith(github.event_name, 'pull_request') }}
run: |
curl -sSL https://github.com/zhenxun-org/zhenxunflow/releases/latest/download/plugin_test.py | python -
zhenxunflow:
runs-on: ubuntu-latest
name: zhenxunflow
needs: plugin_test
steps:
- name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_KEY }}
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ steps.generate-token.outputs.token }}
- name: Cache pre-commit hooks
uses: actions/cache@v4
with:
path: .cache/.pre-commit
key: zhenxunflow-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
- name: zhenxunflow
uses: docker://ghcr.io/zhenxun-org/zhenxunflow:latest
with:
config: >
{
"base": "index",
"plugin_path": "plugins.json"
}
env:
PLUGIN_TEST_RESULT: ${{ needs.plugin_test.outputs.result }}
PLUGIN_TEST_OUTPUT: ${{ needs.plugin_test.outputs.output }}
PLUGIN_TEST_METADATA: ${{ needs.plugin_test.outputs.metadata }}
APP_ID: ${{ secrets.APP_ID }}
PRIVATE_KEY: ${{ secrets.APP_KEY }}
PRE_COMMIT_HOME: /github/workspace/.cache/.pre-commit
- name: Fix permission
run: sudo chown -R $(whoami):$(id -ng) .cache/.pre-commit