Skip to content

Commit

Permalink
Merge pull request #257 from Loup-Garou911XD/main
Browse files Browse the repository at this point in the history
Updated action
  • Loading branch information
Loup-Garou911XD authored Apr 20, 2024
2 parents a30d298 + 9fcf038 commit 45e7b73
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 32 deletions.
68 changes: 40 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,56 @@ name: Create Release

on:
push:
tags:
- v1.*
paths:
- index.json

jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: |
output=$(python3 test/get_changes.py "${{ github.ref }}")
echo "::set-output name=changelog::$output"
id: set_changelog
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token

- name: 'Get Previous tag'
uses: oprypin/find-latest-tag@v1.1.2
with:
repository: ${{ github.repository }}
releases-only: true # We know that all relevant tags have a GitHub release for them.
id: previoustag

- name: set_variables
run: |
output1=$(python3 test/get_latest.py)
output2=$(python3 test/get_changes.py "$output1")
output3=$(python3 test/version_is_lower.py ${{ steps.previoustag.outputs.tag }})
echo "latestVersion=$output1" >> $GITHUB_OUTPUT
echo "changelog=$output2" >> $GITHUB_OUTPUT
echo "shouldRun=$output3" >> $GITHUB_OUTPUT
id: set_variables



- name: Bump version and push tag
if: ${{ steps.set_variables.outputs.shouldRun == '1' }}
id: tag_version
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: |
${{ steps.set_variables.outputs.latestVersion }}
- name: Create release
if: ${{ steps.tag_version.outputs.new_tag }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
artifacts: "plugin_manager.py"
body: |
## Changelog
${{ steps.set_changelog.outputs.changelog }}
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 }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./plugin_manager.py
asset_name: plugin_manager.py
asset_content_type: application
${{ steps.set_variables.outputs.changelog }}
8 changes: 4 additions & 4 deletions test/get_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import sys


def get_version_changelog(version):
def get_version_changelog(version: str):
"""Get changelog entry from CHANGELOG.md for given version"""
with open('CHANGELOG.md', 'r') as file:
content = file.read()
pattern = rf"### {version} \(\d\d-\d\d-\d{{4}}\)\n(.*?)(?=### \d+\.\d+\.\d+|\Z)"
Expand All @@ -15,10 +16,9 @@ def get_version_changelog(version):

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python3 script.py version_number")
print(f"Usage: python3 {__file__.split('/')[-1]} version_number")
sys.exit(1)

version = sys.argv[1].replace("refs/tags/", "")
version = version.replace("v", "", 1)
version = sys.argv[1].replace("v", "", 1)
changelog = get_version_changelog(version)
print(changelog)
13 changes: 13 additions & 0 deletions test/get_latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json


def get_latest():
"""Get latest version entry from index.json"""
with open('index.json', 'r') as file:
content = json.loads(file.read())
latest_version = list(content["versions"].keys())[0]
return latest_version


if __name__ == "__main__":
print(get_latest())
34 changes: 34 additions & 0 deletions test/version_is_lower.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
from get_latest import get_latest


def semantic_to_str(semantic_version: str):
"""Convert version in the form of v1.2.3 to 001002003
for comparing 2 version in semantic versioning format"""
out = ""
for i in (semantic_version.split(".")):
if len(i) == 1:
out += "00"+i
if len(i) == 2:
out += "0"+i
return out


def version_is_lower(version: str):
"""Check if given version is lower than the latest entry in index.json"""
latest = semantic_to_str(get_latest())
version = semantic_to_str(version)
if latest > version:
return True
else:
return False


if __name__ == "__main__":
if len(sys.argv) < 2:
print(f"Usage: python3 {__file__.split('/')[-1]} version_number")
sys.exit(1)

version = sys.argv[1].replace("v", "", 1)
out = version_is_lower(version)
print(int(out))

0 comments on commit 45e7b73

Please sign in to comment.