Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

permissions:
contents: write

jobs:
check:
if: github.repository == 'bedrock-dot-dev/docs' && (github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch')
Expand Down Expand Up @@ -57,23 +60,23 @@ jobs:
- name: Setup git environment ⚙️
if: github.ref == 'refs/heads/master'
run: |
git config --global user.name 'destruc7i0n'
git config --global user.email '[email protected]'
git config user.name 'destruc7i0n'
git config user.email '[email protected]'

- name: Check for docs update 🔎
id: check
env:
DRY_RUN: ${{ github.ref != 'refs/heads/master' }}
working-directory: scripts
run: |
cd scripts
python3 update.py

- name: Update summary 📝
run: |
echo "### Check output 🗒️" >> $GITHUB_STEP_SUMMARY
echo "Dry run: ${{ github.ref != 'refs/heads/master' }}" >> $GITHUB_STEP_SUMMARY
echo "Update found: ${{ (steps.check.outputs.update == 'true' && '✅') || '❌' }}" >> $GITHUB_STEP_SUMMARY
echo 'JSON output: `${{ steps.check.outputs.release_data }}`' >> $GITHUB_STEP_SUMMARY
echo 'JSON output: `${{ steps.check.outputs.version_data }}`' >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check.outputs.update }}" == "true" ]; then
echo 'Commit message: ${{ steps.check.outputs.msg }}' >> $GITHUB_STEP_SUMMARY
fi
Expand All @@ -94,7 +97,7 @@ jobs:
],
"username": "bedrock.dev",
"avatar_url": "https://bedrock.dev/favicon/android-chrome-512x512.png",
}' | curl -X POST -H "Content-Type: application/json" -d @- $DISCORD_WEBHOOK
}' | curl --fail-with-body --silent --show-error -X POST -H "Content-Type: application/json" -d @- "$DISCORD_WEBHOOK"

- name: Archive documentation files 📁
if: steps.check.outputs.update == 'true'
Expand All @@ -110,4 +113,4 @@ jobs:
run: |
# sleep for a bit for GitHub's cache
sleep 10s
curl -X POST $VERCEL_DEPLOY_HOOK
curl --fail-with-body --silent --show-error -X POST "$VERCEL_DEPLOY_HOOK"
9 changes: 5 additions & 4 deletions scripts/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

LINE = '-' * 20

ROOT = Path('../')
TAGS_PATH = Path('../tags.json')
SCRIPTS_PATH = Path(__file__).resolve().parent
ROOT = SCRIPTS_PATH.parent
TAGS_PATH = ROOT / 'tags.json'

CACHE_PATH = Path('./cache')
CACHE_PATH = SCRIPTS_PATH / 'cache'

TMP_PATH = Path('./tmp')
TMP_PATH = SCRIPTS_PATH / 'tmp'

IS_ACTIONS = 'GITHUB_ACTIONS' in os.environ
DRY_RUN = os.environ.get('DRY_RUN') == 'true'
Expand Down
32 changes: 16 additions & 16 deletions scripts/update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json, shutil, subprocess, shlex
import json, shutil, subprocess

from releases import get_latest_releases
from versions import get_latest_versions
from util import MinecraftVersion, write_to_github_output, ensure_required_paths
from docs import get_docs_update

Expand Down Expand Up @@ -44,8 +44,8 @@ def do_versioned_commits(updates: list[tuple[MinecraftVersion, MinecraftVersion]
print(f'Committing "{copy_previous_version_msg}"')

# add previous files commit
subprocess.run(shlex.split('git add --all'), cwd=Constants.ROOT)
subprocess.run(shlex.split(f'git commit -m \'{copy_previous_version_msg}\''), cwd=Constants.ROOT)
subprocess.run(['git', 'add', '--all'], cwd=Constants.ROOT, check=True)
subprocess.run(['git', 'commit', '-m', copy_previous_version_msg], cwd=Constants.ROOT, check=True)

# remove the new version directories to handle deleted files
for prev, new in updates:
Expand All @@ -60,32 +60,32 @@ def do_versioned_commits(updates: list[tuple[MinecraftVersion, MinecraftVersion]
final_msg = f'Docs update: {msg}'
print(f'Committing "{final_msg}"')

subprocess.run(shlex.split('git add --all'), cwd=Constants.ROOT)
subprocess.run(shlex.split(f'git commit -m \'{final_msg}\''), cwd=Constants.ROOT)
subprocess.run(['git', 'add', '--all'], cwd=Constants.ROOT, check=True)
subprocess.run(['git', 'commit', '-m', final_msg], cwd=Constants.ROOT, check=True)

subprocess.run(shlex.split('git push'), cwd=Constants.ROOT)
subprocess.run(['git', 'push'], cwd=Constants.ROOT, check=True)

def main() -> None:
ensure_required_paths()

latest_releases = get_latest_releases()
latest_versions = get_latest_versions()
tags = json.loads(Constants.TAGS_PATH.read_text())

# mapping of version tag to current and latest release
release_data: dict[Tags, dict[str, str]] = {}
# mapping of version tag to current and latest version
version_data: dict[str, dict[str, str]] = {}
for tag in Tags:
latest_version_id = latest_releases[tag.value]
latest_version_id = latest_versions[tag.value]
current_version_id = tags[tag.value][1]
release_data[tag.value] = {
version_data[tag.value] = {
'current': current_version_id,
'latest': latest_version_id,
}

print('Release data:', json.dumps(release_data, indent=2))
print('Version data:', json.dumps(version_data, indent=2))
print(Constants.LINE)

# write as a github actions output
write_to_github_output('release_data', json.dumps(release_data))
write_to_github_output('version_data', json.dumps(version_data))

commit_msg_parts = []
version_updates = []
Expand All @@ -97,8 +97,8 @@ def check_update(tag: Tags) -> bool:
:return: True if there is an update, False otherwise
"""

current_version = MinecraftVersion(release_data[tag.value]['current'])
latest_version = MinecraftVersion(release_data[tag.value]['latest'])
current_version = MinecraftVersion(version_data[tag.value]['current'])
latest_version = MinecraftVersion(version_data[tag.value]['latest'])

if latest_version > current_version:
print(f'New {tag.name} version found: {latest_version}')
Expand Down
4 changes: 3 additions & 1 deletion scripts/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os, shutil
from pathlib import Path

import constants as Constants
Expand Down Expand Up @@ -71,6 +71,8 @@ def ensure_required_paths() -> None:
"""
Ensures that the required paths exist
"""
if Constants.TMP_PATH.exists():
shutil.rmtree(Constants.TMP_PATH)
Constants.TMP_PATH.mkdir(exist_ok=True, parents=True)
Constants.CACHE_PATH.mkdir(exist_ok=True, parents=True)

Expand Down
4 changes: 2 additions & 2 deletions scripts/releases.py → scripts/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import constants as Constants
from constants import Tags

def get_latest_releases() -> dict[str, str]:
def get_latest_versions() -> dict[str, str]:
"""
Gets the latest releases from the checked out version files
Gets the latest versions from the checked out version files
:return: A dict with the latest preview and stable versions
"""
stable_version_map = json.loads((Constants.SOURCES[Tags.STABLE.value] / 'version.json').read_text())
Expand Down