Files
tools/execute.py

51 lines
1.3 KiB
Python
Raw Normal View History

2025-03-29 01:37:26 +03:00
#!/usr/bin/env python
2025-03-29 03:47:20 +03:00
import os
2025-03-29 01:37:26 +03:00
import sys
2025-03-29 22:50:32 +03:00
import base64
2025-03-29 01:37:26 +03:00
2025-03-31 18:39:33 +03:00
DEBUG = True
2025-03-29 14:44:34 +03:00
ACTIONS_RUNTIME_TOKEN = os.getenv('ACTIONS_RUNTIME_TOKEN')
2025-03-29 21:50:22 +03:00
INPUT_TOKEN = os.getenv('INPUT_TOKEN')
2025-03-29 14:44:34 +03:00
GITHUB_SERVER_URL = os.getenv('GITHUB_SERVER_URL')
GITHUB_REPOSITORY = os.getenv('GITHUB_REPOSITORY')
2025-03-30 20:17:22 +03:00
GITHUB_REF = os.getenv('GITHUB_REF')
2025-03-31 15:25:49 +03:00
GITHUB_REF_NAME = os.getenv('GITHUB_REF_NAME')
2025-03-29 22:50:32 +03:00
2025-03-30 04:50:49 +03:00
def escape(text):
return '"' + text + '"'
2025-03-29 03:56:34 +03:00
2025-03-31 18:39:33 +03:00
def exec_cmd(cmd):
result = os.popen(cmd)
print(result.read())
2025-03-30 20:22:02 +03:00
cmd = 'git init'
2025-03-31 18:39:33 +03:00
exec_cmd(cmd)
2025-03-30 20:24:48 +03:00
2025-03-30 04:50:49 +03:00
sample_string = "x-access-token:" + ACTIONS_RUNTIME_TOKEN
2025-03-30 04:51:33 +03:00
sample_string = "x-access-token:" + INPUT_TOKEN
2025-03-29 03:56:34 +03:00
sample_string_bytes = sample_string.encode("utf-8")
base64_bytes = base64.b64encode(sample_string_bytes)
base64_string = 'AUTHORIZATION: basic ' + base64_bytes.decode("utf-8")
2025-03-29 15:09:04 +03:00
key = 'http.'+GITHUB_SERVER_URL+'/.extraheader'
2025-03-30 04:50:49 +03:00
value = base64_string
2025-03-30 20:22:02 +03:00
cmd = 'git config set --local ' + key + ' ' + escape(value)
2025-03-31 18:39:33 +03:00
exec_cmd(cmd)
2025-03-29 15:09:04 +03:00
2025-03-30 05:00:02 +03:00
key = 'url.https://'+ACTIONS_RUNTIME_TOKEN+':x-oauth-basic@codex.r10x.net'+'/.insteadOf'
2025-03-30 04:13:57 +03:00
value = 'git@"'+base64_string+'"'
2025-03-30 20:22:02 +03:00
cmd = 'git config set --local ' + escape(key) + ' ' + escape(GITHUB_SERVER_URL)
2025-03-31 18:39:33 +03:00
exec_cmd(cmd)
2025-03-29 15:09:04 +03:00
2025-03-30 07:55:28 +03:00
cmd = 'git remote add origin ' + GITHUB_SERVER_URL + '/' + GITHUB_REPOSITORY
2025-03-31 18:39:33 +03:00
exec_cmd(cmd)
2025-03-30 07:55:28 +03:00
2025-03-30 20:27:57 +03:00
cmd = 'git fetch --progress --depth 1 origin ' + GITHUB_REF
2025-03-31 18:39:33 +03:00
exec_cmd(cmd)
2025-03-30 20:17:22 +03:00
2025-03-31 15:25:49 +03:00
cmd = 'git checkout ' + GITHUB_REF_NAME
2025-03-31 18:39:33 +03:00
exec_cmd(cmd)