Skip to content

[adapter]: alicebot-adapter-mirai #67

[adapter]: alicebot-adapter-mirai

[adapter]: alicebot-adapter-mirai #67

Workflow file for this run

name: Marketplace Actions
on:
issues:
types:
- opened
- reopened
- edited
issue_comment:
types:
- created
- edited
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
jobs:
react-to-new-issue:
name: New Issue
if: github.event_name == 'issues' && github.event.action == 'opened'
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.comment.outputs.comment-id }}
steps:
- name: Add comment
id: comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.issue.number }}
body: |
感谢你的提交.
自动验证将在几分钟内开始.
edited-old-issue:
name: Edited Issue
if: github.event_name == 'issues' && github.event.action == 'edited'
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.comment.outputs.comment-id }}
steps:
- name: Add comment
id: comment
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ github.event.issue.number }}
body: |
感谢你的提交.
自动验证将在几分钟内开始.
is-revalidation:
if: github.event.issue.state == 'open' && github.event_name == 'issue_comment'
name: Revalidation
runs-on: ubuntu-latest
steps:
- name: Run /validate command
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
command=$(echo "$COMMENT_BODY" | head -1)
if [[ $command != "/validate"* ]]; then
echo "No /validate command found in first line of the comment \"${command}\", skipping" >> $GITHUB_STEP_SUMMARY
exit 1
fi
- name: Add reactions
uses: peter-evans/create-or-update-comment@v2
with:
comment-id: ${{ github.event.comment.id }}
reactions: '+1'
parse-issue:
name: Parse Issue
needs: [react-to-new-issue,is-revalidation,edited-old-issue]
if: always() && (needs.react-to-new-issue.result == 'success' || needs.is-revalidation.result == 'success' || needs.edited-old-issue.result == 'success')
runs-on: ubuntu-latest
env:
REPO: ${{ github.repository }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
outputs:
module_name: ${{ steps.set-output.outputs.module_name }}
pypi_name: ${{ steps.set-output.outputs.pypi_name }}
result: ${{ steps.run.outputs.result }}
output: ${{ steps.run.outputs.output }}
type: ${{ steps.run.outputs.type }}
name: ${{ steps.run.outputs.name }}
steps:
- name: Parse issue body
id: parse
uses: zentered/issue-forms-body-parser@v1.5.1
- name: Get Inputs
id: set-output
env:
JSON_DATA: ${{ steps.parse.outputs.data }}
run: |
module_name=$(echo $JSON_DATA | jq -r '.["module-name"].text' )
echo "module_name=$module_name" >> $GITHUB_OUTPUT
pypi_name=$(echo $JSON_DATA | jq -r '.["pypi-name"].text' )
echo "pypi_name=$pypi_name" >> $GITHUB_OUTPUT
# 启动py脚本环境,并传入module_name,pypi_name,ISSUE_TITLE
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: 3.9
cache: true
- name: Install dependencies
run: pdm install
- name: Run Python script
id: run
env:
TITLE: ${{ env.ISSUE_TITLE }}
PYPI_NAME: ${{ steps.set-output.outputs.pypi_name }}
run: |
pdm run .github/actions_scripts/parse.py
parse-failed:
name: Parse Failed
runs-on: ubuntu-latest
needs: parse-issue
if: always() && needs.parse-issue.outputs.result == 'error'
steps:
- uses: actions/checkout@v3.3.0
- name: Render template
id: render
uses: chuhlomin/render-template@v1.6
with:
template: .github/workflows/templates/validation-failed.md
vars: |
validation_output: ${{ needs.parse-issue.outputs.output }}
- name: Add comment
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.render.outputs.result }}
- name: Remove label validation/succeeded
if: contains(github.event.issue.labels.*.name, 'validation/succeeded')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["validation/succeeded"]
})
- name: Add label parse-issue/failed
if: contains(github.event.issue.labels.*.name, 'parse-issue/failed') == false
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["parse-issue/failed"]
})
- name: Mark job as failed
run: exit 1
validate:
name: Validate
runs-on: ubuntu-latest
if: always() && needs.parse-issue.outputs.result == 'success'
needs:
- parse-issue
outputs:
name: ${{ steps.test.outputs.name }}
description: ${{ steps.test.outputs.description }}
author: ${{ steps.test.outputs.author }}
license: ${{ steps.test.outputs.license }}
homepage: ${{ steps.test.outputs.homepage }}
tags: ${{ steps.test.outputs.tags }}
result: ${{ steps.test.outputs.result || steps.install-pypi-error.outputs.result }}
output: ${{ steps.test.outputs.output || steps.install-pypi-error.outputs.output }}
steps:
- name: Remove label parse-issue/failed
if: contains(github.event.issue.labels.*.name, 'parse-issue/failed')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["parse-issue/failed"]
})
- uses: actions/checkout@v3
# Set up Python 3.8 environment
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: 3.9
cache: true
- name: Install dependencies
run: pdm install
# 若type不为bot,则安装pypi_name
- name: Install pypi_name
id: install-pypi
if: needs.parse-issue.outputs.type != 'bot'
continue-on-error: true
run: pdm add ${{ needs.parse-issue.outputs.pypi_name }}
- name: Install Error
id: install-pypi-error
if: steps.install-pypi.outcome != 'success' || steps.install-pypi.conclusion != 'success'
run: | # 输出错误信息
echo "result=error" >> $GITHUB_OUTPUT
echo "output=安装pypi包失败,请检查是否存在依赖冲突或者其他情况" >> $GITHUB_OUTPUT
- name: alicebot test
id: test
if: steps.install-pypi.outcome == 'success' && steps.install-pypi.conclusion == 'success'
env:
PYPI_NAME: ${{ needs.parse-issue.outputs.pypi_name }}
MODULE_NAME: ${{ needs.parse-issue.outputs.module_name }}
TYPE: ${{ needs.parse-issue.outputs.type }}
run: |
pdm run .github/actions_scripts/test.py
validation-failed:
name: Validation Failed
runs-on: ubuntu-latest
needs: validate
if: always() && needs.validate.outputs.result == 'error'
steps:
- uses: actions/checkout@v3.3.0
- name: Render template
id: render
uses: chuhlomin/render-template@v1.6
with:
template: .github/workflows/templates/validation-failed.md
vars: |
validation_output: ${{ needs.validate.outputs.output }}
- name: Add comment
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.render.outputs.result }}
- name: Remove label validation/succeeded
if: contains(github.event.issue.labels.*.name, 'validation/succeeded')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["validation/succeeded"]
})
- name: Add label validation/failed
if: contains(github.event.issue.labels.*.name, 'validation/failed') == false
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["validation/failed"]
})
- name: Mark job as failed
run: exit 1
create-pr:
name: Create PR
runs-on: ubuntu-latest
needs: [validate,parse-issue]
if: always() && needs.validate.outputs.result == 'success' && needs.parse-issue.outputs.result == 'success'
env:
REPO: ${{ github.repository }}
ISSUE_NUM: ${{ github.event.issue.number }}
ISSUE_TITLE: ${{ github.event.issue.title }}
TYPE: ${{ needs.parse-issue.outputs.type }}
outputs:
result: ${{ steps.copy-commands.outputs.result }}
file_json: ${{ steps.file.outputs.file_json }}
steps:
- name: Get open linked PR
id: get_open_linked_pr
run: |
open_linked_pr_length=$(\
gh pr list \
--repo $REPO \
--state open \
--search "close #$ISSUE_NUM in:body" \
--json number | jq '. | length'\
)
echo "::set-output name=open_linked_pr_length::$open_linked_pr_length"
- name: Check open linked pr length
if: steps.get_open_linked_pr.outputs.open_linked_pr_length != 0
run: |
echo "Unclosed pull request is existing."
exit 1
- uses: actions/checkout@v3
- uses: pdm-project/setup-pdm@v3
name: Setup PDM
with:
python-version: 3.9
cache: true
- name: Install dependencies
run: pdm install
- name: Change file
id: file
env:
TYPE: ${{ needs.parse-issue.outputs.type }}
MODULE_NAME: ${{ needs.parse-issue.outputs.module_name }}
PYPI_NAME: ${{ needs.parse-issue.outputs.pypi_name }}
NAME: ${{ needs.validate.outputs.name }}
DESCRIPTION: ${{ needs.validate.outputs.description }}
AUTHOR: ${{ needs.validate.outputs.author }}
LICENSE: ${{ needs.validate.outputs.license }}
HOMEPAGE: ${{ needs.validate.outputs.homepage }}
TAGS: ${{ needs.validate.outputs.tags }}
run: |
pdm run .github/actions_scripts/file.py
- name: Reopen issue
if: ${{ github.event.issue.state }} == "closed"
run: gh issue reopen $ISSUE_NUM
- name: Define new branch name
id: define_new_branch_name
run: |
new_branch_name=$(echo "${ISSUE_NUM}-$(TZ=UTC-9 date '+%Y%m%d-%H%M%S')")
echo "::set-output name=new_branch_name::$new_branch_name"
- name: Create branch
uses: EndBug/add-and-commit@v9
with:
new_branch: ${{ steps.define_new_branch_name.outputs.new_branch_name }}
- name: Create PR
run: |
gh pr create \
--head $NEW_BRANCH_NAME \
--base $BASE_BRANCH_NAME \
--title "$ISSUE_TITLE" \
--body "close #${ISSUE_NUM}"
env:
NEW_BRANCH_NAME: ${{ steps.define_new_branch_name.outputs.new_branch_name }}
BASE_BRANCH_NAME: ${{ github.event.repository.default_branch }}
- name: Copy Commands
id: copy-commands
run: |
echo "git fetch origin ${NEW_BRANCH}"
echo "git checkout ${NEW_BRANCH}"
echo "code --reuse-window ${TYPE}.json"
result="success"
echo "result=$result" >> $GITHUB_OUTPUT
env:
NEW_BRANCH: ${{ steps.define_new_branch_name.outputs.new_branch_name }}
validation-succeeded:
name: Validation Succeeded
runs-on: ubuntu-latest
needs: [validate,create-pr]
if: always() && needs.validate.outputs.result == 'success' && needs.create-pr.outputs.result == 'success'
steps:
- uses: actions/checkout@v3.3.0
- name: Render template
id: render
uses: chuhlomin/render-template@v1.6
with:
template: .github/workflows/templates/validation-succeeded.md
vars: |
content: ${{ needs.create-pr.outputs.file_json }}
- name: Add Comment
uses: peter-evans/create-or-update-comment@v3.0.2
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.render.outputs.result }}
- name: Remove label validation/failed
if: contains(github.event.issue.labels.*.name, 'validation/failed')
uses: actions/github-script@v6
with:
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ["validation/failed"]
})
- name: Add label validation/succeeded
if: contains(github.event.issue.labels.*.name, 'validation/succeeded') == false
uses: actions/github-script@v6
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["validation/succeeded"]
})