diff --git a/.github/scripts/parse_changelog.py b/.github/scripts/parse_changelog.py new file mode 100644 index 0000000..47b4414 --- /dev/null +++ b/.github/scripts/parse_changelog.py @@ -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}') \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ff9d33e --- /dev/null +++ b/.github/workflows/release.yaml @@ -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<> $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 }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..fe46dfb --- /dev/null +++ b/CHANGELOG.md @@ -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) diff --git a/backend/minecraft_server.py b/backend/minecraft_server.py index 8b6fcc5..500612c 100644 --- a/backend/minecraft_server.py +++ b/backend/minecraft_server.py @@ -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.