Skip to content

Commit

Permalink
Create step to auto-update Luau
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed Sep 23, 2024
1 parent 41fb02e commit 4a7c42a
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/update-luau-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Update Luau Version

on:
workflow_dispatch:
schedule:
- cron: "10 0 * * *" # Runs at 00:10 UTC every day

jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Generate App Token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.TYPES_GENERATOR_APP_ID }}
private-key: ${{ secrets.TYPES_GENERATOR_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: true

- name: Update Luau Version
run: echo "LUAU_VERSION=$(scripts/update_luau_and_changelog.py)" >> $GITHUB_ENV

- name: Create Pull Request
id: create_pull_request
uses: peter-evans/create-pull-request@v6
with:
title: Sync to upstream Luau $LUAU_VERSION
body: |
Sync to upstream Luau $LUAU_VERSION
- This pull request is **auto-generated**
branch: auto/update-luau
commit-message: Sync to upstream Luau $LUAU_VERSION
base: main
token: ${{ steps.generate_token.outputs.token }}

# - name: Enable Pull Request Automerge
# run: gh pr merge --squash --auto "${{ steps.create_pull_request.outputs.pull-request-number }}"
# env:
# GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
95 changes: 95 additions & 0 deletions scripts/update_luau_and_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
# Run in root of repository
# scripts/update_luau_and_changelog.py

import subprocess
import sys

CHANGELOG_FILE = "CHANGELOG.md"

# Update submodule
subprocess.run(["git", "submodule", "update", "--remote"], check=True)

# Check for changes
if not subprocess.check_output(["git", "status", "--porcelain", "-uno"]):
print("No changes", file=sys.stderr)
exit(0)

# Current luau version
VERSION = subprocess.check_output(
["git", "describe", "--tags", "--abbrev=0"], cwd="luau"
).decode()
MESSAGE = f"Sync to upstream Luau {VERSION}"

# Read the current contents of the changelog file
file_path = CHANGELOG_FILE
with open(file_path, "r") as file:
lines = file.readlines()

# Initialize variables
unreleased_section_found = False
changed_subcategory_found = False
changed_inserted = False
updated_lines: list[str] = []
updated = False

for line in lines:
if updated:
updated_lines.append(line)
continue

if line.startswith("## [Unreleased]"):
unreleased_section_found = True
updated_lines.append(line)
continue

if unreleased_section_found:
if changed_subcategory_found:
if line.startswith("- Sync to upstream Luau "):
updated_lines.append(f"- {MESSAGE}")
updated = True
continue
elif line.startswith("##"):
# Changed category ended
if updated_lines[-1].strip() == "":
updated_lines.pop()
updated_lines.append(f"- {MESSAGE}")
updated_lines.append("\n")
updated_lines.append(line)
updated = True
continue
updated_lines.append(line)
continue

if line.startswith("### Changed"):
changed_subcategory_found = True
updated_lines.append(line)
continue

if line.startswith("## "):
updated_lines.append("### Changed\n")
updated_lines.append("\n")
updated_lines.append(f"- {MESSAGE}")
updated_lines.append("\n")
updated_lines.append(line)
updated = True
continue

# If Unreleased section not found, create it at the beginning
if line.startswith("## "):
# If the first section is not Unreleased, add it and stop further processing
if not unreleased_section_found:
updated_lines.append("## [Unreleased]\n")
updated_lines.append("### Changed\n")
updated_lines.append(f"- {MESSAGE}")
unreleased_section_found = True
updated = True
updated_lines.append(line)
else:
updated_lines.append(line)

# Write the updated contents back to the file
with open(file_path, "w") as file:
file.writelines(updated_lines)

print(VERSION)

0 comments on commit 4a7c42a

Please sign in to comment.