ci: test release script

This commit is contained in:
luvletter2333 2023-03-03 10:13:12 +08:00
parent 5890d96dda
commit 7f43e7f173
No known key found for this signature in database
GPG Key ID: 9EB7723F3A0ACF92
3 changed files with 41 additions and 34 deletions

View File

@ -6,22 +6,23 @@ def read_env(key):
if key in os.environ: if key in os.environ:
return os.environ[key] return os.environ[key]
else: else:
print(f"failed to read env {key}")
return "" return ""
APK_FOLDER = "apks" APK_FOLDER = "apks"
API_PREFIX = "http://127.0.0.1:8081/bot" + os.environ["BOT_TOKEN"] + "/" API_PREFIX = "http://127.0.0.1:38118/bot" + os.environ["BOT_TOKEN"] + "/"
BOT_TAGET = read_env("BOT_TARGET") BOT_TARGET = read_env("BOT_TARGET")
ADMIN_USERID = BOT_TAGET.replace("-100","") ADMIN_USERID = BOT_TARGET.replace("-100","")
VERSION_NAME = read_env("VERSION_NAME") VERSION_NAME = read_env("VERSION_NAME")
VERSION_CODE = read_env("VERSION_CODE") VERSION_CODE = read_env("VERSION_CODE")
COMMIT_HASH = read_env("GITHUB_SHA") COMMIT_HASH = read_env("GITHUB_SHA")
COMMIT_MESSAGE = read_env("COMMIT_MESSAGE") COMMIT_MESSAGE = read_env("COMMIT_MESSAGE")
APK_CHANNEL_ID = "@NekoXApks" APK_CHANNEL_ID = "@miaomiao_apks"
UPDATE_CHANNEL_ID = "@NekogramX" UPDATE_CHANNEL_ID = "@miaomiao_apks"
UPDATE_METADATA_CHANNEL_ID = "@nekox_update_metadata" UPDATE_METADATA_CHANNEL_ID = "@miaomiao_metadata"
CI_CHANNEL_ID = "@NekoX_CI" CI_CHANNEL_ID = "@NekoX_CI"
def generateReleaseMessage(first_apk_message_id, release_text) -> str: def generateReleaseMessage(first_apk_message_id, release_text) -> str:
@ -53,14 +54,14 @@ def waitReply(mid):
last_update = max(last_update, update["update_id"]) last_update = max(last_update, update["update_id"])
def sendMessage(message, user_id = BOT_TAGET) -> int: def sendMessage(message, user_id = BOT_TARGET) -> int:
data = { data = {
"chat_id" : user_id, "chat_id" : user_id,
"text": message, "text": message,
"parse_mode": "Markdown" "parse_mode": "Markdown"
} }
resp = requests.post(API_PREFIX + "sendMessage", json=data).json() resp = requests.post(API_PREFIX + "sendMessage", json=data).json()
# print(resp) print(resp)
return int(resp["result"]["message_id"]) return int(resp["result"]["message_id"])
@ -68,18 +69,18 @@ def sendDocument(user_id, path, message = ""):
files = {'document': open(path, 'rb')} files = {'document': open(path, 'rb')}
data = {'chat_id': user_id, 'caption': message, 'parse_mode': 'Markdown'} data = {'chat_id': user_id, 'caption': message, 'parse_mode': 'Markdown'}
response = requests.post(API_PREFIX + "sendDocument", files=files, data=data) response = requests.post(API_PREFIX + "sendDocument", files=files, data=data)
# print(response.json()) print(response.json())
def sendRelease(): def sendRelease():
apks = os.listdir(APK_FOLDER) apks = os.listdir(APK_FOLDER)
apks.sort() apks.sort()
# print(apks) print(apks)
# read message from admin # read message from admin
mid = sendMessage(f"Please reply the release message for the version {VERSION_NAME},{VERSION_CODE}:", user_id=BOT_TAGET) mid = sendMessage(f"Please reply the release message for the version {VERSION_NAME},{VERSION_CODE}:", user_id=BOT_TARGET)
admin_resp = waitReply(mid) admin_resp = waitReply(mid)
# print(admin_resp) print(admin_resp)
release_text = admin_resp["text"] release_text = admin_resp["text"]
# send message and apks to APK channel # send message and apks to APK channel
@ -109,16 +110,17 @@ def sendCIRelease():
if __name__ == '__main__': if __name__ == '__main__':
print(sys.argv)
if len(sys.argv) != 2: if len(sys.argv) != 2:
print("Run Type: release, ci, debug") print("Run Type: release, ci, debug")
os._exit(1) exit(1)
mode = sys.argv[1] mode = sys.argv[1]
try: try:
if mode == "release": if mode == "release":
sendRelease() sendRelease()
elif mode == "ci": elif mode == "ci":
if COMMIT_MESSAGE.startswith("ci"): if COMMIT_MESSAGE.startswith("ci"):
CI_CHANNEL_ID = BOT_TAGET CI_CHANNEL_ID = BOT_TARGET
sendCIRelease() sendCIRelease()
elif mode == "debug": elif mode == "debug":
APK_CHANNEL_ID = "@test_channel_nekox" APK_CHANNEL_ID = "@test_channel_nekox"
@ -126,8 +128,9 @@ if __name__ == '__main__':
UPDATE_METADATA_CHANNEL_ID = "@test_channel_nekox" UPDATE_METADATA_CHANNEL_ID = "@test_channel_nekox"
sendRelease() sendRelease()
else: else:
os._exit(1) print("unknown mode")
exit(1)
except Exception as e: except Exception as e:
print(e) print(e)
os._exit(1) exit(1)

View File

@ -472,28 +472,26 @@ jobs:
run: | run: |
sudo apt install python3 python3-pip -y sudo apt install python3 python3-pip -y
pip3 install requests pip3 install requests
- name: Upload - name: Prepare Upload
run: | run: |
chmod +x telegram-bot-api-binary chmod +x telegram-bot-api-binary
function start() { function start() {
./telegram-bot-api-binary --api-id=21724 --api-hash=3e0cb5efcd52300aec5994fdfc5bdc16 --local 2>&1 > /dev/null & ./telegram-bot-api-binary --api-id=21724 --api-hash=3e0cb5efcd52300aec5994fdfc5bdc16 -p 38118 --local 2>&1 > /dev/null &
sleep 5 sleep 5
} }
start start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
- name: Upload
run: |
curl https://raw.githubusercontent.com/NekoX-Dev/NekoX/dev/.github/scripts/upload.py -o upload.py curl https://raw.githubusercontent.com/NekoX-Dev/NekoX/dev/.github/scripts/upload.py -o upload.py
export BOT_TOKEN=${{ secrets.HELPER_BOT_TOKEN }} export BOT_TOKEN="${{ secrets.HELPER_BOT_TOKEN }}"
export BOT_TARGET=${{ secrets.HELPER_BOT_TARGET }} export BOT_TARGET="${{ secrets.HELPER_BOT_TARGET }}"
export COMMIT_MESSAGE="${{ github.event.head_commit.message }}" export COMMIT_MESSAGE="${{ github.event.head_commit.message }}"
export VERSION_NAME="${{ env.VERSION_NAME }}"
export VERSION_CODE="${{ env.VERSION_CODE }}"
echo ${{ env.VERSION_NAME }}
python3 upload.py ci python3 upload.py ci
pkill telegram-bot pkill telegram-bot

View File

@ -381,17 +381,19 @@ jobs:
with: with:
name: telegram-bot-api-binary name: telegram-bot-api-binary
path: . path: .
- name: Release - name: Prepare Upload
run: | run: |
chmod +x telegram-bot-api-binary chmod +x telegram-bot-api-binary
function start() { function start() {
./telegram-bot-api-binary --api-id=21724 --api-hash=3e0cb5efcd52300aec5994fdfc5bdc16 --local 2>&1 > /dev/null & ./telegram-bot-api-binary -p 38118 --api-id=21724 --api-hash=3e0cb5efcd52300aec5994fdfc5bdc16 --local 2>&1 > /dev/null &
sleep 5 sleep 5
} }
start start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
curl http://127.0.0.1:8081/ || start curl http://127.0.0.1:38118/ || start
- name: Upload
run: |
mkdir apks mkdir apks
find artifacts -name "*.apk" -exec cp {} apks \; find artifacts -name "*.apk" -exec cp {} apks \;
curl https://raw.githubusercontent.com/NekoX-Dev/NekoX/dev/.github/scripts/upload.py -o upload.py curl https://raw.githubusercontent.com/NekoX-Dev/NekoX/dev/.github/scripts/upload.py -o upload.py
@ -401,6 +403,10 @@ jobs:
export VERSION_NAME="$(grep -E "def verName = " TMessagesProj/build.gradle | sed "s/def verName = //" | sed "s/\"//g")" export VERSION_NAME="$(grep -E "def verName = " TMessagesProj/build.gradle | sed "s/def verName = //" | sed "s/\"//g")"
python3 upload.py release python3 upload.py release
pkill telegram-bot pkill telegram-bot
- name: Setup upterm session
uses: lhotari/action-upterm@v1
with:
limit-access-to-users: luvletter2333
telegram-bot-api: telegram-bot-api:
name: Telegram Bot API name: Telegram Bot API