Compare commits
No commits in common. "cb2273be12f07427769748d7db4ab744820ecb11" and "bc362d08092e8d71ca810bf23a25c1a2f39f0c9f" have entirely different histories.
cb2273be12
...
bc362d0809
25
.github/workflows/deploy.yml
vendored
Normal file
25
.github/workflows/deploy.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Run deploy script
|
||||||
|
run: python3 deploy.py
|
||||||
|
|
||||||
|
- name: Commit and push changes
|
||||||
|
run: |
|
||||||
|
git config --global user.name 'GitHub Actions'
|
||||||
|
git config --global user.email 'actions@github.com'
|
||||||
|
git add .
|
||||||
|
git commit -m "Deploy changes"
|
||||||
|
git push --force origin HEAD:deploy
|
56
deploy.py
56
deploy.py
@ -1,54 +1,26 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
ON_CF = os.getenv("CF_PAGES") == "1"
|
|
||||||
|
|
||||||
|
|
||||||
def get_env_info() -> dict[str, str]:
|
def get_env_info() -> dict[str, str]:
|
||||||
# 读取环境变量
|
# 读取环境变量
|
||||||
env_info = {}
|
env_info = {}
|
||||||
# git branch
|
# git branch
|
||||||
# if on cf, read it from env: CF_PAGES_BRANCH
|
branch = run(
|
||||||
if ON_CF:
|
["git", "branch", "--show-current"], capture_output=True, text=True, encoding="utf-8"
|
||||||
branch = os.getenv("CF_PAGES_BRANCH") or "unknown"
|
)
|
||||||
else:
|
env_info["branch"] = branch.stdout.strip()
|
||||||
branch = run(
|
|
||||||
["git", "branch", "--show-current"],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
encoding="utf-8",
|
|
||||||
).stdout
|
|
||||||
env_info["branch"] = branch.strip()
|
|
||||||
# git commit hash
|
# git commit hash
|
||||||
# on cf -> get from CF_PAGES_COMMIT_SHA
|
commit = run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, encoding="utf-8")
|
||||||
if ON_CF:
|
env_info["commit"] = commit.stdout.strip()
|
||||||
commit = os.getenv("CF_PAGES_COMMIT_SHA") or "unknown"
|
|
||||||
else:
|
|
||||||
commit = run(
|
|
||||||
["git", "rev-parse", "HEAD"],
|
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
encoding="utf-8",
|
|
||||||
).stdout
|
|
||||||
env_info["commit"] = commit.strip()
|
|
||||||
# git commit message
|
# git commit message
|
||||||
message = run(
|
message = run(
|
||||||
["git", "log", "-1", "--pretty=%B"],
|
["git", "log", "-1", "--pretty=%B"], capture_output=True, text=True, encoding="utf-8"
|
||||||
capture_output=True,
|
|
||||||
text=True,
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
)
|
||||||
env_info["message"] = message.stdout.strip()
|
env_info["message"] = message.stdout.strip()
|
||||||
# git tag
|
# git tag
|
||||||
if ON_CF:
|
tag = run(["git", "describe", "--tags"], capture_output=True, text=True, encoding="utf-8")
|
||||||
tag = os.getenv("CF_PAGES_COMMIT_TAG") or "cf"
|
env_info["tag"] = tag.stdout.strip()
|
||||||
else:
|
|
||||||
tag = run(
|
|
||||||
["git", "describe", "--tags"], capture_output=True, text=True, encoding="utf-8"
|
|
||||||
).stdout
|
|
||||||
env_info["tag"] = tag.strip()
|
|
||||||
return env_info
|
return env_info
|
||||||
|
|
||||||
|
|
||||||
@ -83,11 +55,11 @@ if __name__ == "__main__":
|
|||||||
file_branch_name = file.parent.name
|
file_branch_name = file.parent.name
|
||||||
hash_color = hash(file_branch_name) & 0xFFFFFF
|
hash_color = hash(file_branch_name) & 0xFFFFFF
|
||||||
border = border_template.format(f"#{hash_color:06x}")
|
border = border_template.format(f"#{hash_color:06x}")
|
||||||
|
|
||||||
# git 信息:
|
# git 信息:
|
||||||
version_info = f"{file_branch_name}/{branch}:{tag}<br/>{message}"
|
version_info = f"{file_branch_name}/{branch}:{tag}<br/>{message}"
|
||||||
marker = marker_template.format(version_info)
|
marker = marker_template.format(version_info)
|
||||||
|
|
||||||
print(f"Branch: {file_branch_name}\n{border}\n{marker}\n")
|
print(f"Branch: {file_branch_name}\n{border}\n{marker}\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -97,10 +69,8 @@ if __name__ == "__main__":
|
|||||||
version_info = f"{branch}:{tag.split('-')[0]}"
|
version_info = f"{branch}:{tag.split('-')[0]}"
|
||||||
marker = marker_template.format(version_info)
|
marker = marker_template.format(version_info)
|
||||||
print(f"Master: {border}\n{marker}\n")
|
print(f"Master: {border}\n{marker}\n")
|
||||||
|
|
||||||
raw_content = raw_content.replace(border_raw, border).replace(
|
raw_content = raw_content.replace(border_raw, border).replace(marker_raw, marker)
|
||||||
marker_raw, marker
|
|
||||||
)
|
|
||||||
|
|
||||||
# 写入文件
|
# 写入文件
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user