Skip to content

Commit

Permalink
feat: update cordcloud action
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglbme committed Nov 17, 2021
1 parent 5f32fbf commit 821364d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ CordCloud 帐号自动续命。可配置 workflow 的触发条件为 `schedule`

| 参数 | 描述 | 是否必传 | 默认值 |
|---|---|---|---|
| `username` | 你的 CordCloud 帐号 || |
| `email` | 你的 CordCloud 邮箱 || |
| `passwd` | 你的 CordCloud 密码 || |
| `host` | CordCloud 站点 || `cordcloud.biz` |

注意:使用此 CordCloud Action 前,请关闭两步验证,即把验证设置为“不要求”。

## 完整示例

在你的任意一个 GitHub 仓库 `.github/workflows/` 文件夹下创建一个 .yml 文件,如 `cc.yml`,内容如下:
Expand All @@ -28,12 +30,12 @@ jobs:
steps:
- uses: yanglbme/cordcloud-action@main
with:
username: ${{ secrets.USERNAME }}
passwd: ${{ secrets.PASSWD }}
email: ${{ secrets.CC_EMAIL }}
passwd: ${{ secrets.CC_PASSWD }}
host: cordcloud.site
```
同时,在项目的 `Settings -> Secrets` 路径下配置好 `USERNAME` 与 `PASSWD` ,不要直接在 `.yml` 文件中暴露个人帐号信息。
同时,在项目的 `Settings -> Secrets` 路径下配置好 `CC_EMAIL` 与 `CC_PASSWD` ,不要直接在 `.yml` 文件中暴露个人帐号信息。

注意:

Expand Down
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ name: 'CordCloud Action'
description: 'GitHub Action for CordCloud'
author: 'yanglbme'
branding:
icon: 'arrow-right-circle'
icon: 'check-circle'
color: 'gray-dark'
inputs:
username:
description: 'your cordcloud username'
email:
description: 'your cordcloud email'
required: true
passwd:
description: 'your cordcloud password'
required: true
host:
description: 'base host'
required: false
default: 'cordcloud.biz'
default: 'cordcloud.site'
outputs:
result:
description: 'The result of api'
Expand Down
35 changes: 24 additions & 11 deletions app/action.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
import requests
from actions_toolkit import core


class Action:
def __init__(self, username: str, passwd: str, host: str = 'cordcloud.biz'):
self.username = username
def __init__(self, email: str, passwd: str, code: str = '', host: str = 'cordcloud.site'):
self.email = email
self.passwd = passwd
self.code = code
self.host = host.replace('https://', '').replace('http://', '')
self.session = requests.session()

def format_url(self, path):
def format_url(self, path) -> str:
return f'https://{self.host}/{path}'

def check_in(self) -> str:
def login(self) -> dict:
login_url = self.format_url('auth/login')
check_in_url = self.format_url('user/checkin')
form_data = {
'email': self.username,
'email': self.email,
'passwd': self.passwd,
'code': ''
'code': self.code
}
self.session.post(login_url, data=form_data)
resp = self.session.post(login_url, data=form_data)
return resp.json()

def check_in(self) -> dict:
check_in_url = self.format_url('user/checkin')
resp = self.session.post(check_in_url)
return resp.json()['msg']
return resp.json()

def run(self):
res = self.login()
if res['ret'] != 1:
raise Exception(f'CordCloud 帐号登录异常,错误日志:{res}')
core.info(f'帐号登录成功,结果:{res}')

def run(self) -> str:
return self.check_in()
res = self.check_in()
if res['ret'] != 1:
raise Exception(f'CordCloud 帐号自动签到续命异常,错误日志:{res}')
core.info(f'帐号续命成功,结果:{res}')
14 changes: 7 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from app.action import Action

if __name__ == '__main__':
username = core.get_input('username')
passwd = core.get_input('passwd')
host = core.get_input('host') or 'cordcloud.biz'
action = Action(username, passwd, host)
try:
res = action.run()
core.info(f'CordCloud Action 运行成功,结果:{res}')
email = core.get_input('email', required=True)
passwd = core.get_input('passwd', required=True)
host = core.get_input('host') or 'cordcloud.site'
action = Action(email, passwd, host=host)
action.run()
core.info(f'CordCloud Action 成功结束运行!')
except Exception as e:
core.set_failed(str(e))
core.error(f'{str(e)}')

0 comments on commit 821364d

Please sign in to comment.