-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from David-Lor/develop
2.2.1
- Loading branch information
Showing
8 changed files
with
314 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"""EXTRACT CHANGELOG Script | ||
This script extracts the changelog for the given version from the README.md file, under the `## Changelog` section. | ||
The version is given as x.y.z (e.g. 0.1.1) as an arg (e.g. running "python extract_changelog.py 0.1.1"). | ||
The changelog is saved as markdown on a file. | ||
""" | ||
|
||
import sys | ||
import re | ||
from typing import List | ||
|
||
from markdown2 import markdown | ||
from bs4 import BeautifulSoup | ||
from bs4.element import Tag | ||
|
||
README_FILE = "README.md" | ||
CHANGELOG_OUTPUT_FILE = "changelog_generated.md" | ||
|
||
|
||
def _is_valid_version(version: str) -> bool: | ||
return bool(re.match(r"^(\d+\.)?(\d+\.)?(\*|\d+)$", version)) | ||
|
||
|
||
def _find_changelog_list(soup: BeautifulSoup, version: str) -> Tag: | ||
all_lists = soup.find_all("li") | ||
return next(li for li in all_lists if li.text.startswith(version)) | ||
|
||
|
||
def _parse_changelog(li: Tag) -> List[str]: | ||
all_changelog_lists = li.find("ul").find_all("li") | ||
return [li.text.strip() for li in all_changelog_lists] | ||
|
||
|
||
def _format_changelog_output(changelog: List[str]) -> str: | ||
output = "" | ||
for change in changelog: | ||
output += f"\n- {change}" | ||
return output.strip() | ||
|
||
|
||
def _read(filename: str) -> str: | ||
with open(filename, "r") as f: | ||
return f.read() | ||
|
||
|
||
def _save(filename: str, content: str): | ||
with open(filename, "w") as f: | ||
f.write(content) | ||
|
||
|
||
def extract_changelog(version: str): | ||
assert _is_valid_version(version) | ||
|
||
readme_content = _read(README_FILE) | ||
readme_html = markdown(readme_content) | ||
|
||
soup = BeautifulSoup(readme_html, "html.parser") | ||
changelog_list = _find_changelog_list(soup=soup, version=version) | ||
changelog_changes = _parse_changelog(changelog_list) | ||
changelog_output = _format_changelog_output(changelog_changes) | ||
|
||
_save(filename=CHANGELOG_OUTPUT_FILE, content=changelog_output) | ||
|
||
|
||
if __name__ == '__main__': | ||
extract_changelog(sys.argv[-1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
markdown2==2.3.10 | ||
beautifulsoup4==4.9.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
on: | ||
push: | ||
tags: | ||
- "*.*.*" | ||
|
||
name: Create Release | ||
|
||
jobs: | ||
build: | ||
name: Create Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Setup | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Setup Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
architecture: x64 | ||
- name: Install Python requirements | ||
run: python -m pip install -r .github/workflows/extract_changelog_requirements.txt | ||
|
||
# Fetch variables | ||
- name: Extract version from tag | ||
id: get_version | ||
run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3) | ||
- name: Fetch changelog for release description | ||
id: get_changelog | ||
run: "python .github/workflows/extract_changelog.py ${{ steps.get_version.outputs.VERSION }}" | ||
|
||
# Generate artifact | ||
- name: Create release artifact (zip) | ||
id: create_zip | ||
run: | | ||
cp README.md README.txt | ||
cp LICENSE.md LICENSE.txt | ||
zip release-artifact.zip SimpleGangWar.cs SimpleGangWar.ini README.txt LICENSE.txt | ||
# Release | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: "v${{ github.ref }}" | ||
body_path: changelog_generated.md | ||
draft: false | ||
prerelease: false | ||
- name: Upload release asset | ||
id: upload_release_asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: "./release-artifact.zip" | ||
asset_name: "GTAV-SimpleGangWar-${{ steps.get_version.outputs.VERSION }}.zip" | ||
asset_content_type: "application/zip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
bin/ | ||
obj/ | ||
.vs/ | ||
*.csproj | ||
*.config | ||
*.sln | ||
bin/ | ||
obj/ | ||
.vs/ | ||
*.csproj | ||
*.config | ||
*.sln | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Copyright 2021 David Lorenzo @ github.com/David-Lor | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.