Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
在配置文件里写入 commit id (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
chen310 authored Mar 18, 2022
1 parent 07ac7d3 commit c6b95a4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ jobs:
DEFAULT_CRON: "0 30 0 * * * *"
DEFAULT_REGION: "ap-guangzhou"
DEFAULT_FUNCTION_NAME: "NeteaseCloudMusicTasks"

SHA: ${{ github.sha }}
2 changes: 2 additions & 0 deletions .github/workflows/upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
uses: actions/checkout@v2
- name: Create config file
run: mv config.example.json config.json
- name: Write sha to config file
run: sed -i "s/commitId/${{ github.sha }}/g" config.json
- name: Setting environment variable
run: |
ver=$(cat config.json | grep version | grep -o "[\.0-9]*")
Expand Down
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
/* 开源地址: https://github.com/chen310/NeteaseCloudMusicTasks */
"version": "2.20",
"sha": "commitId",
/* 多账号的配置详见 https://github.com/chen310/NeteaseCloudMusicTasks#%E5%A4%9A%E8%B4%A6%E5%8F%B7 */
"users": [
{
Expand Down
1 change: 1 addition & 0 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def start(event={}, context={}):
config = json5.load(f)

print('Version:', config['version'])
print('Commit ID:', config['sha'])

# 公共配置
setting = config['setting']
Expand Down
23 changes: 20 additions & 3 deletions ql_update.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import os


def writeSha(path, file):
cur = os.getcwd()
os.chdir(path)
result = os.popen('git rev-parse HEAD').read().strip()
os.chdir(cur)

if len(result) == 40 and ' ' not in result:
os.system('sed -i "s/commitId/{}/g" {}'.format(result, file))
print('已写入 commit id')
else:
print('commit id 获取失败')


if __name__ == "__main__":
github_url = 'https://github.com/chen310/NeteaseCloudMusicTasks.git'

Expand All @@ -21,12 +35,15 @@
os.system('cp -f {} {}'.format(scripts_config, old_config))
print('复制配置示例文件...')
os.system('cp -f {} {}'.format(repo_config, example_config))
writeSha(os.path.dirname(repo_config), example_config)
print('更新配置文件...')
os.system('python3 {}scripts/chen310_NeteaseCloudMusicTasks/updateconfig.py {} {} {}'.format(
data_path, repo_config, scripts_config, scripts_config))
data_path, example_config, scripts_config, scripts_config))
print('更新完成')
else:
print('复制配置文件')
os.system('cp {} {}'.format(repo_config, scripts_config))
print('复制配置示例文件...')
os.system('cp -f {} {}'.format(repo_config, example_config))
writeSha(os.path.dirname(repo_config), example_config)
print('复制配置文件...')
os.system('cp {} {}'.format(example_config, scripts_config))

1 change: 1 addition & 0 deletions serverless/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ else
config_file="config.json"
old_config_file="config.old.json"
example_config_file="config.example.json"
sed -i "s/commitId/$SHA/g" $example_config_file
# 复制模板文件为配置文件
cp $example_config_file $config_file
if [ -e "code/config.json" ]; then
Expand Down
11 changes: 11 additions & 0 deletions updateconfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json5
import sys
import os
from utils import jsonDumps
from utils import updateConfig

Expand Down Expand Up @@ -61,6 +62,16 @@ def processSetting(setting, template):


def before(src, dst):
if 'sha' in src:
del src['sha']

if 'sha' in dst and dst['sha'] == 'commitId':
result = os.popen('git rev-parse HEAD').read().strip()
if len(result) == 40 and ' ' not in result:
dst['sha'] = result
else:
del dst['sha']

for user in src['users']:
if 'md5' in user:
del user['md5']
Expand Down

0 comments on commit c6b95a4

Please sign in to comment.