Skip to content

Commit

Permalink
красота и фиксы
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgencheg committed Sep 8, 2024
1 parent d2b354c commit 1e7013f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ on:
types: [closed]

env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
CHANGELOG_DIR: Resources/Changelog/ChangelogLPP.yml
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
CHANGELOG_DIR: ${{ vars.CHANGELOG_DIR }}
PR_NUMBER: ${{ github.event.number }}
CHANGELOG_DISCORD_WEBHOOK: ${{ secrets.CHANGELOG_DISCORD_WEBHOOK }}

jobs:
changelog:
Expand All @@ -21,7 +20,7 @@ jobs:
uses: actions/checkout@v3
with:
token: ${{ secrets.BOT_TOKEN }}
ref: master
ref: ${{ vars.CHANGELOG_BRANCH }}

- name: Setup Git
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Changelog
name: Discord Changelog

on:
workflow_dispatch:
Expand All @@ -13,12 +13,12 @@ jobs:
- name: checkout
uses: actions/checkout@v3
with:
token: ${{secrets.BOT_TOKEN}}
ref: master

- name: Publish changelog
run: Tools/actions_changelogs_since_last_run.py
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
CHANGELOG_DISCORD_WEBHOOK: ${{ secrets.CHANGELOG_DISCORD_WEBHOOK }}
CHANGELOG_DIR: ${{ vars.CHANGELOG_DIR }}
CHANGELOG_WEBHOOK: ${{ secrets.CHANGELOG_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
continue-on-error: true
1 change: 1 addition & 0 deletions Resources/Prototypes/_LostParadise/Maps/normandy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
MailCarrier: [ 1, 2 ]
SalvageSpecialist: [ 4, 4 ]
# Civilian
Passenger: [ -1, -1 ]
Clown: [ 1, 1 ]
Mime: [ 1, 1 ]
Musician: [ 1, 3 ]
Expand Down
19 changes: 9 additions & 10 deletions Tools/actions_changelogs_since_last_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
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_TOKEN = os.environ["GITHUB_TOKEN"]
CHANGELOG_DIR = os.environ["CHANGELOG_DIR"]
CHANGELOG_WEBHOOK = os.environ["CHANGELOG_WEBHOOK"]

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

CHANGELOG_FILE = "Resources/Changelog/ChangelogLPP.yml"

TYPES_TO_EMOJI = {
"Fix": "🐛",
Expand All @@ -33,19 +32,19 @@
ChangelogEntry = dict[str, Any]

def main():
if not CHANGELOG_DISCORD_WEBHOOK:
if not CHANGELOG_WEBHOOK:
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_FILE, "r") as f:
with open(CHANGELOG_DIR, "r") as f:
cur_changelog = yaml.safe_load(f)

diff = diff_changelog(last_changelog, cur_changelog)
Expand Down Expand Up @@ -93,7 +92,7 @@ def get_last_changelog(sess: requests.Session, sha: str) -> 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 @@ -121,12 +120,12 @@ def get_discord_body(content: str):
def send_discord(content: str):
body = get_discord_body(content)

response = requests.post(CHANGELOG_DISCORD_WEBHOOK, json=body)
response = requests.post(CHANGELOG_WEBHOOK, json=body)
response.raise_for_status()


def send_to_discord(entries: Iterable[ChangelogEntry]) -> None:
if not CHANGELOG_DISCORD_WEBHOOK:
if not CHANGELOG_WEBHOOK:
print(f"No discord webhook URL found, skipping discord send")
return

Expand Down

0 comments on commit 1e7013f

Please sign in to comment.