Skip to content

Commit

Permalink
фиксы
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgencheg committed Sep 2, 2024
1 parent c3163d1 commit 93bf395
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 63 deletions.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion .github/workflows/close-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: superbrothers/close-pull-request@v3
with:
token: ${{ secrets.BOT_TOKEN }}
github_token: ${{ secrets.BOT_TOKEN }}
comment: "Благодарим вас за вклад в наш репозиторий. К сожалению, похоже, что вы отправили ПР из master ветки. Мы рекомендуем вам следовать [документации](https://docs.spacestation14.com/en/general-development/setup/git-for-the-ss14-developer.html). \n\n Вы можете перенести свою текущую работу из основной ветки в другую ветку с помощью [создав новый](https://git-scm.com/docs/git-branch) и [очистив](https://git-scm.com/docs/git-reset) master ветку."

# If you prefer to just comment on the pr and not close it, uncomment the bellow and comment the above
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conflict-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
Label:
if: github.actor != 'PJBot' && github.actor != 'DeltaV-Bot' && github.actor != 'SimpleStation14' != 'Lost-Paradise-Bot'
if: github.actor != 'PJBot' && github.actor != 'DeltaV-Bot' && github.actor != 'SimpleStation14' && github.actor != 'Lost-Paradise-Bot'
runs-on: ubuntu-latest
steps:
- name: Check for Merge Conflicts
Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/publish-changelog.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .github/workflows/publish-lostparadise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: 8.0.x

- name: Get Engine Tag
run: |
Expand Down Expand Up @@ -66,3 +64,9 @@ jobs:
key: ${{ secrets.SSH }}
port: ${{ secrets.PORT }}
script: pwsh /var/www/wiki/push.ps1 ${{ github.sha }}

- name: Publish changelog
run: Tools/actions_changelogs_since_last_run.py
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
CHANGELOG_DISCORD_WEBHOOK: ${{ secrets.CHANGELOG_DISCORD_WEBHOOK }}
52 changes: 17 additions & 35 deletions Tools/actions_changelogs_since_last_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
import yaml
from typing import Any, Iterable

GITHUB_API_URL = os.environ.get("GITHUB_API_URL", "https://api.github.com")
GITHUB_REPOSITORY = os.environ["GITHUB_REPOSITORY"]
GITHUB_RUN = os.environ["GITHUB_RUN_ID"]
BOT_TOKEN = os.environ["BOT_TOKEN"]
GITHUB_API_URL = os.environ.get("GITHUB_API_URL", "https://api.github.com")
GITHUB_REPOSITORY = os.environ["GITHUB_REPOSITORY"]
GITHUB_RUN = os.environ["GITHUB_RUN_ID"]
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
CHANGELOG_DIR = os.environ["CHANGELOG_DIR"]
CHANGELOG_DISCORD_WEBHOOK = os.environ["CHANGELOG_DISCORD_WEBHOOK"]

# https://discord.com/developers/docs/resources/webhook
DISCORD_SPLIT_LIMIT = 2000
CHANGELOG_DISCORD_WEBHOOK = os.environ.get("CHANGELOG_DISCORD_WEBHOOK")

CHANGELOG_FILES = ["Resources/Changelog/Changelog.yml", "Resources/Changelog/ChangelogLPP.yml"] # Corvax-MultiChangelog

TYPES_TO_EMOJI = {
"Fix": "🐛",
Expand All @@ -37,23 +36,19 @@ def main():
return

session = requests.Session()
session.headers["Authorization"] = f"Bearer {BOT_TOKEN}"
session.headers["Authorization"] = f"Bearer {GITHUB_TOKEN}"
session.headers["Accept"] = "Accept: application/vnd.github+json"
session.headers["X-GitHub-Api-Version"] = "2022-11-28"

most_recent = get_most_recent_workflow(session)
last_sha = most_recent['head_commit']['id']
print(f"Last successful publish job was {most_recent['id']}: {last_sha}")
last_changelog = yaml.safe_load(get_last_changelog(session, last_sha))
with open(CHANGELOG_DIR, "r") as f:
cur_changelog = yaml.safe_load(f)

# Corvax-MultiChangelog-Start
for changelog_file in CHANGELOG_FILES:
last_changelog = yaml.safe_load(get_last_changelog(session, last_sha, changelog_file))
with open(changelog_file, "r") as f:
cur_changelog = yaml.safe_load(f)

diff = diff_changelog(last_changelog, cur_changelog)
send_to_discord(diff)
# Corvax-MultiChangelog-End
diff = diff_changelog(last_changelog, cur_changelog)
send_to_discord(diff)


def get_most_recent_workflow(sess: requests.Session) -> Any:
Expand Down Expand Up @@ -86,7 +81,7 @@ def get_past_runs(sess: requests.Session, current_run: Any) -> Any:
return resp.json()


def get_last_changelog(sess: requests.Session, sha: str, changelog_file: str) -> str:
def get_last_changelog(sess: requests.Session, sha: str) -> str:
"""
Use GitHub API to get the previous version of the changelog YAML (Actions builds are fetched with a shallow clone)
"""
Expand All @@ -97,7 +92,7 @@ def get_last_changelog(sess: requests.Session, sha: str, changelog_file: str) ->
"Accept": "application/vnd.github.raw"
}

resp = sess.get(f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/contents/{changelog_file}", headers=headers, params=params)
resp = sess.get(f"{GITHUB_API_URL}/repos/{GITHUB_REPOSITORY}/contents/{CHANGELOG_DIR}", headers=headers, params=params)
resp.raise_for_status()
return resp.text

Expand Down Expand Up @@ -142,28 +137,17 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
for name, group in itertools.groupby(entries, lambda x: x["author"]):
# Need to split text to avoid discord character limit
group_content = io.StringIO()
group_content.write(f"**{name}** обновил(а):\n")
group_content.write(f"## {name}:\n")

for entry in group:
for change in entry["changes"]:
emoji = TYPES_TO_EMOJI.get(change['type'], "❓")
message = change['message']
url = entry.get("url")
# Corvax-Localization-Start
TRANSLATION_API_URL = os.environ.get("TRANSLATION_API_URL")
if TRANSLATION_API_URL:
resp = requests.post(TRANSLATION_API_URL, json={
"text": message,
"source_lang": "EN",
"target_lang": "RU"
})
message = resp.json()['data']
# Corvax-Localization-End
if url and url.strip():
group_content.write(f"{emoji} [-]({url}) {message}\n")
else:
group_content.write(f"{emoji} - {message}\n")
group_content.write(f"\n") # Corvax: Better formatting

group_text = group_content.getvalue()
message_text = message_content.getvalue()
Expand All @@ -172,7 +156,7 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:

# If adding the text would bring it over the group limit then send the message and start a new one
if message_length + group_length >= DISCORD_SPLIT_LIMIT:
print("Split changelog and sending to discord")
print("Split changelog and sending to discord")
send_discord(message_text)

# Reset the message
Expand All @@ -185,9 +169,7 @@ def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
message_text = message_content.getvalue()
if len(message_text) > 0:
print("Sending final changelog to discord")
content.seek(0) # Corvax
for chunk in iter(lambda: content.read(2000), ''): # Corvax: Split big changelogs messages
send_discord(chunk)
send_discord(message_text)


main()
1 change: 1 addition & 0 deletions Tools/changelogs/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function main() {
changes: entries,
id: getHighestCLNumber() + 1,
time: time,
url: `https://github.com/${process.env.GITHUB_REPOSITORY}/pull/${process.env.PR_NUMBER}`
};

// Write changelogs
Expand Down

0 comments on commit 93bf395

Please sign in to comment.