Skip to content

Commit

Permalink
feat(instance) : add auto start to minecraft instance
Browse files Browse the repository at this point in the history
  • Loading branch information
WasinUddy committed Nov 15, 2024
1 parent f4e76a6 commit 6bd1b13
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/parse_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys
import re
import os
from typing import Tuple


def parse_changelog(changelog_path: str = 'CHANGELOG.md', with_v: bool = False) -> Tuple[str, str, str]:
with open(changelog_path) as f:
changelog = f.read()

# Get the first (Highest Latest) version
version_pattern = r'## \[(v?\d+\.\d+\.\d+)\] - (\d{4}-\d{2}-\d{2})'
match = re.search(version_pattern, changelog)
if not match:
print('Version not found in CHANGELOG.md', file=sys.stderr)
sys.exit(1)

version, date = match.groups()
version = version.strip()
date = date.strip()

# Extract Latest version details
latest_version_pattern = r'## \[v?{0}\] - {1}(.*?)(?:\n## \[v?\d+\.\d+\.\d+\] - \d{{4}}-\d{{2}}-\d{{2}}|\Z)'.format(
re.escape(version), re.escape(date))
match = re.search(latest_version_pattern, changelog, re.DOTALL)
if not match:
print('Latest version details not found in CHANGELOG.md', file=sys.stderr)
sys.exit(1)

latest_version_details = match.group(1).strip()

return version, date, latest_version_details


if __name__ == '__main__':
# Parse sys.argv if specified
version, date, latest_version_details = parse_changelog(*sys.argv[1:])

os.makedirs('github_action_outputs', exist_ok=True)

# Write to file
with open('./github_action_outputs/version.txt', 'w') as f:
f.write(version)

with open('./github_action_outputs/date.txt', 'w') as f:
f.write(date)

with open('./github_action_outputs/latest_version_details.txt', 'w') as f:
f.write(latest_version_details)

print(f'Version: {version}\nDate: {date}\nLatest Version Details:\n{latest_version_details}')
64 changes: 64 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release from Changelog

on:
push:
paths:
- 'CHANGELOG.md'


jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Parse Changelog
run: |
python .github/scripts/parse_changelog.py
- name: Read Changelog Outputs
id: read_changelog
run: |
version=$(cat github_action_outputs/version.txt)
date=$(cat github_action_outputs/date.txt)
details=$(cat github_action_outputs/latest_version_details.txt)
echo "VERSION=$version" >> $GITHUB_ENV
echo "DATE=$date" >> $GITHUB_ENV
echo "DETAILS<<EOF" >> $GITHUB_ENV
echo "$details" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create Tag
uses: actions/github-script@v7
with:
script: |
const version = process.env.VERSION;
const tagName = `${version}`;
const { data: tag } = await github.rest.git.createTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tagName,
message: `Release ${tagName}`,
object: context.sha,
type: 'commit',
});
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: tag.sha,
});
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.VERSION }}
tag_name: ${{ env.VERSION }}
body: ${{ env.DETAILS }}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Changelog

## [2.0.1] - 2024-11-15
### Added
- Auto start minecraft server on container start suggested by [issue #12](https://github.com/WasinUddy/Montainer/issues/12) by [niker](https://github.com/niker)
2 changes: 2 additions & 0 deletions backend/minecraft_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def __init__(self, cwd: str):
self.is_running = False
self.log_file = None

self.start() # Start the server instance on initialization

def start(self):
"""
Start the Minecraft server instance if it is not already running.
Expand Down

0 comments on commit 6bd1b13

Please sign in to comment.