From 0bcbc5ea624a25e4e4c5dd8ae0a137d0e1a04831 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Fri, 8 Jul 2022 12:20:05 +0000 Subject: [PATCH 01/14] :construction_worker: Add manual workflows --- .github/workflows/delete.yml | 42 +++++++++++++++++++++ .github/workflows/register.yml | 68 ++++++++++++++++++++++++++++++++++ .github/workflows/update.yml | 52 ++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 .github/workflows/delete.yml create mode 100644 .github/workflows/register.yml create mode 100644 .github/workflows/update.yml diff --git a/.github/workflows/delete.yml b/.github/workflows/delete.yml new file mode 100644 index 0000000..83b5add --- /dev/null +++ b/.github/workflows/delete.yml @@ -0,0 +1,42 @@ +name: delete + +on: + workflow_dispatch: + inputs: + package_name: + description: 'Package name' + required: true + type: choice + options: + - mydependency + - private-hello + - public-hello + +jobs: + delete: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Run Action + env: + PKG_ACTION: "DELETE" + PKG_NAME: ${{ inputs.package_name }} + run: | + pip install beautifulsoup4 + python .github/actions.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: ":package: [:robot:] Delete package from PyPi index" + title: "[🤖] Delete ${{ inputs.package_name }} from PyPi index" + body: "Automatically generated PR, deleting ${{ inputs.package_name }} from PyPi index." + branch-suffix: "random" + delete-branch: true diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml new file mode 100644 index 0000000..934d92f --- /dev/null +++ b/.github/workflows/register.yml @@ -0,0 +1,68 @@ +name: register + +on: + workflow_dispatch: + inputs: + package_name: + description: 'Package name' + required: true + type: string + version: + description: 'Version of the package' + required: true + type: string + author: + description: 'Author(s) of the package' + required: true + type: string + short_desc: + description: 'A short description of the package' + required: true + type: string + long_desc: + description: 'A longer description of the package (HTML)' + required: true + type: string + homepage: + description: 'Homepage of the package (link to the github repository)' + required: true + type: string + link: + description: 'Link used for `pip`. For example, for a github-hosted package refered by the tag `v3.0.2`, it would be : git+https://github.com/huggingface/transformers@v3.0.2' + required: true + type: string + +jobs: + register: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Run Action + env: + PKG_ACTION: "REGISTER" + PKG_NAME: ${{ inputs.package_name }} + PKG_VERSION: ${{ inputs.version }} + PKG_AUTHOR: ${{ inputs.author }} + PKG_SHORT_DESC: ${{ inputs.short_desc }} + PKG_LONG_DESC: ${{ inputs.long_desc }} + PKG_HOMEPAGE: ${{ inputs.homepage }} + PKG_LINK: ${{ inputs.link }} + run: | + pip install beautifulsoup4 + python .github/actions.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: ":package: [:robot:] Register package in PyPi index" + title: "[🤖] Register ${{ inputs.package_name }} in PyPi index" + body: "Automatically generated PR, registering ${{ inputs.package_name }} in PyPi index." + branch-suffix: "random" + delete-branch: true diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 0000000..58302be --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,52 @@ +name: update + +on: + workflow_dispatch: + inputs: + package_name: + description: 'Package name' + required: true + type: choice + options: + - mydependency + - private-hello + - public-hello + version: + description: 'New version of the package' + required: true + type: string + link: + description: 'Link used for `pip`. For example, for a github-hosted package refered by the tag `v3.0.2`, it would be : git+https://github.com/huggingface/transformers@v3.0.2' + required: true + type: string + +jobs: + update: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.6] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Run Action + env: + PKG_ACTION: "DELETE" + PKG_NAME: ${{ inputs.package_name }} + PKG_VERSION: ${{ inputs.version }} + PKG_LINK: ${{ inputs.link }} + run: | + pip install beautifulsoup4 + python .github/actions.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: ":package: [:robot:] Update package in PyPi index" + title: "[🤖] Update ${{ inputs.package_name }} in PyPi index" + body: "Automatically generated PR, updating ${{ inputs.package_name }} in PyPi index." + branch-suffix: "random" + delete-branch: true From 309809cf8a2acc1c2f7e0d84a460480b97a3499a Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Fri, 8 Jul 2022 12:31:16 +0000 Subject: [PATCH 02/14] :construction: Modifying actions.py to work with new workflow --- .github/actions.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/.github/actions.py b/.github/actions.py index f07780d..994f66b 100644 --- a/.github/actions.py +++ b/.github/actions.py @@ -64,7 +64,7 @@ def package_exists(soup, package_name): return False -def register(issue_ctx): +def register(pkg_name, version, author, short_desc, long_desc, homepage, link): args = parse_issue(issue_ctx) print_args(args) check_args(args, ['package name', 'version', 'author', 'short description', 'long description', 'homepage', 'link']) @@ -106,7 +106,7 @@ def register(issue_ctx): f.write(template) -def update(issue_ctx): +def update(pkg_name, version, link): args = parse_issue(issue_ctx) print_args(args) check_args(args, ['package name', 'new version', 'link for the new version']) @@ -145,7 +145,7 @@ def update(issue_ctx): index.write(soup.prettify("utf-8")) -def delete(issue_ctx): +def delete(pkg_name): args = parse_issue(issue_ctx) print_args(args) check_args(args, ['package name']) @@ -167,19 +167,27 @@ def delete(issue_ctx): def main(): - # Get the context from the environment variable - context = json.loads(os.environ['GITHUB_CONTEXT']) - issue_ctx = context['event']['issue'] - title = issue_ctx['title'] - - if title.startswith("🟢"): - register(issue_ctx) - - if title.startswith("🔵"): - update(issue_ctx) - - if title.startswith("🔴"): - delete(issue_ctx) + # Call the right method, with the right arguments + action = os.environ["PKG_ACTION"] + + if action == "REGISTER": + register( + pkg_name=os.environ["PKG_NAME"], + version=os.environ["PKG_VERSION"], + author=os.environ["PKG_AUTHOR"], + short_desc=os.environ["PKG_SHORT_DESC"], + long_desc=os.environ["PKG_LONG_DESC"], + homepage=os.environ["PKG_HOMEPAGE"], + link=os.environ["PKG_LINK"], + ) + elif action == "DELETE": + delete(pkg_name=os.environ["PKG_NAME"]) + elif action == "UPDATE": + update( + pkg_name=os.environ["PKG_NAME"], + version=os.environ["PKG_VERSION"], + link=os.environ["PKG_LINK"], + ) if __name__ == "__main__": From 23968309147a014d3abdd28eb785cd1302f34e59 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 09:54:45 +0000 Subject: [PATCH 03/14] :construction: Update the code of actions --- .github/actions.py | 68 +++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/.github/actions.py b/.github/actions.py index 994f66b..fd602c0 100644 --- a/.github/actions.py +++ b/.github/actions.py @@ -65,24 +65,22 @@ def package_exists(soup, package_name): def register(pkg_name, version, author, short_desc, long_desc, homepage, link): - args = parse_issue(issue_ctx) - print_args(args) - check_args(args, ['package name', 'version', 'author', 'short description', 'long description', 'homepage', 'link']) + # Read our index first with open(INDEX_FILE) as html_file: soup = BeautifulSoup(html_file, "html.parser") - n_package_name = normalize(args['package name']) + norm_pkg_name = normalize(pkg_name) - if package_exists(soup, n_package_name): - raise ValueError("Package {} seems to already exists".format(n_package_name)) + if package_exists(soup, norm_pkg_name): + raise ValueError("Package {} seems to already exists".format(norm_pkg_name)) # Create a new anchor element for our new package last_anchor = soup.find_all('a')[-1] # Copy the last anchor element new_anchor = copy.copy(last_anchor) - new_anchor['href'] = "{}/".format(n_package_name) - new_anchor.contents[0].replace_with(args['package name']) + new_anchor['href'] = "{}/".format(norm_pkg_name) + new_anchor.contents[0].replace_with(pkg_name) spans = new_anchor.find_all('span') - spans[1].string = args['version'] # First span contain the version - spans[2].string = args['short description'] # Second span contain the short description + spans[1].string = version # First span contain the version + spans[2].string = short_desc # Second span contain the short description # Add it to our index and save it last_anchor.insert_after(new_anchor) @@ -93,52 +91,50 @@ def register(pkg_name, version, author, short_desc, long_desc, homepage, link): with open(TEMPLATE_FILE) as temp_file: template = temp_file.read() - template = template.replace("_package_name", args['package name']) - template = template.replace("_version", args['version']) - template = template.replace("_link", "{}#egg={}-{}".format(args['link'], n_package_name, args['version'])) - template = template.replace("_homepage", args['homepage']) - template = template.replace("_author", args['author']) - template = template.replace("_long_description", args['long description']) + template = template.replace("_package_name", pkg_name) + template = template.replace("_version", version) + template = template.replace("_link", "{}#egg={}-{}".format(link, norm_pkg_name, version)) + template = template.replace("_homepage", homepage) + template = template.replace("_author", author) + template = template.replace("_long_description", long_desc) - os.mkdir(n_package_name) - package_index = os.path.join(n_package_name, INDEX_FILE) + os.mkdir(norm_pkg_name) + package_index = os.path.join(norm_pkg_name, INDEX_FILE) with open(package_index, "w") as f: f.write(template) def update(pkg_name, version, link): - args = parse_issue(issue_ctx) - print_args(args) - check_args(args, ['package name', 'new version', 'link for the new version']) + # Read our index first with open(INDEX_FILE) as html_file: soup = BeautifulSoup(html_file, "html.parser") - n_package_name = normalize(args['package name']) + norm_pkg_name = normalize(pkg_name) - if not package_exists(soup, n_package_name): - raise ValueError("Package {} seems to not exists".format(n_package_name)) + if not package_exists(soup, norm_pkg_name): + raise ValueError("Package {} seems to not exists".format(norm_pkg_name)) # Change the version in the main page - anchor = soup.find('a', attrs={"href": "{}/".format(n_package_name)}) + anchor = soup.find('a', attrs={"href": "{}/".format(norm_pkg_name)}) spans = anchor.find_all('span') - spans[1].string = args['new version'] + spans[1].string = version with open(INDEX_FILE, 'wb') as index: index.write(soup.prettify("utf-8")) # Change the package page - index_file = os.path.join(n_package_name, INDEX_FILE) + index_file = os.path.join(norm_pkg_name, INDEX_FILE) with open(index_file) as html_file: soup = BeautifulSoup(html_file, "html.parser") # Create a new anchor element for our new version last_anchor = soup.find_all('a')[-1] # Copy the last anchor element new_anchor = copy.copy(last_anchor) - new_anchor['href'] = "{}#egg={}-{}".format(args['link for the new version'], n_package_name, args['new version']) + new_anchor['href'] = "{}#egg={}-{}".format(link, norm_pkg_name, version) # Add it to our index last_anchor.insert_after(new_anchor) # Change the latest version - soup.html.body.div.section.find_all('span')[1].contents[0].replace_with(args['new version']) + soup.html.body.div.section.find_all('span')[1].contents[0].replace_with(version) # Save it with open(index_file, 'wb') as index: @@ -146,21 +142,19 @@ def update(pkg_name, version, link): def delete(pkg_name): - args = parse_issue(issue_ctx) - print_args(args) - check_args(args, ['package name']) + # Read our index first with open(INDEX_FILE) as html_file: soup = BeautifulSoup(html_file, "html.parser") - n_package_name = normalize(args['package name']) + norm_pkg_name = normalize(pkg_name) - if not package_exists(soup, n_package_name): - raise ValueError("Package {} seems to not exists".format(n_package_name)) + if not package_exists(soup, norm_pkg_name): + raise ValueError("Package {} seems to not exists".format(norm_pkg_name)) # Remove the package directory - shutil.rmtree(n_package_name) + shutil.rmtree(norm_pkg_name) # Find and remove the anchor corresponding to our package - anchor = soup.find('a', attrs={"href": "{}/".format(n_package_name)}) + anchor = soup.find('a', attrs={"href": "{}/".format(norm_pkg_name)}) anchor.extract() with open(INDEX_FILE, 'wb') as index: index.write(soup.prettify("utf-8")) From 68ff4c20735e7cbd1a07ddfc4894129a3b901cb9 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 09:55:42 +0000 Subject: [PATCH 04/14] :fire: Remove unused code --- .github/actions.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/.github/actions.py b/.github/actions.py index fd602c0..7fe7c14 100644 --- a/.github/actions.py +++ b/.github/actions.py @@ -16,46 +16,6 @@ def normalize(name): return re.sub(r"[-_.]+", "-", name).lower() -def parse_issue(issue_ctx): - arguments = {} - - parts = issue_ctx['body'].split('- **')[1:] # Ignore the first one : it's the title - for text_arg in parts: - arg_name, arg_value = text_arg.split(':**') - arg_name, arg_value = arg_name.strip(), arg_value.strip() - - if arg_name == "Long description": - # Special case, where we have more than 1 line : it contain HTML code - arg_value = arg_value.split('```')[1] if '```' in arg_value else arg_value.split('`')[1] - - code_lang = arg_value.split('\n')[0].strip() - if code_lang != 'html': - raise ValueError("The {} argument should contain a HTML code section. But it contain {} code.".format(arg_name, code_lang)) - - arg_value = "\n".join(arg_value.split('\n')[1:]) - else: - if "\n" in arg_value: - raise ValueError("The {} argument should be a single line. Current value : {}".format(arg_name, arg_value)) - - arguments[arg_name.lower()] = arg_value - return arguments - - -def print_args(args): - print("\n--- Arguments detected from issue ---\n") - for arg_name, arg_value in args.items(): - print("\t{} : {}".format(arg_name, arg_value)) - print("\n") - - -def check_args(args, must_have): - for name in must_have: - if name not in args: - raise ValueError("Couldn't find argument {}".format(name)) - if args[name].strip() == "": - raise ValueError("Argument {} is empty. Please specify it".format(name)) - - def package_exists(soup, package_name): package_ref = package_name + "/" for anchor in soup.find_all('a'): From ad9d342cb72c776d1163de2279c04045e87ce1d5 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 13:18:09 +0000 Subject: [PATCH 05/14] :heavy_plus_sign: ADd pyyalm dependency --- .github/workflows/delete.yml | 2 +- .github/workflows/register.yml | 2 +- .github/workflows/update.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/delete.yml b/.github/workflows/delete.yml index 83b5add..46888de 100644 --- a/.github/workflows/delete.yml +++ b/.github/workflows/delete.yml @@ -30,7 +30,7 @@ jobs: PKG_ACTION: "DELETE" PKG_NAME: ${{ inputs.package_name }} run: | - pip install beautifulsoup4 + pip install beautifulsoup4 pyyaml python .github/actions.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml index 934d92f..176db5b 100644 --- a/.github/workflows/register.yml +++ b/.github/workflows/register.yml @@ -56,7 +56,7 @@ jobs: PKG_HOMEPAGE: ${{ inputs.homepage }} PKG_LINK: ${{ inputs.link }} run: | - pip install beautifulsoup4 + pip install beautifulsoup4 pyyaml python .github/actions.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 58302be..2c9b5ad 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -40,7 +40,7 @@ jobs: PKG_VERSION: ${{ inputs.version }} PKG_LINK: ${{ inputs.link }} run: | - pip install beautifulsoup4 + pip install beautifulsoup4 pyyaml python .github/actions.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 From 017520ec8ce8a772a4966e8b9e1a3a494e88e231 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 13:30:02 +0000 Subject: [PATCH 06/14] :sparkles: Properly update theinput of github actions --- .github/actions.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/actions.py b/.github/actions.py index 7fe7c14..8cf3229 100644 --- a/.github/actions.py +++ b/.github/actions.py @@ -5,10 +5,12 @@ import shutil from bs4 import BeautifulSoup +import yaml INDEX_FILE = "index.html" TEMPLATE_FILE = "pkg_template.html" +YAML_ACTION_FILES = [".github/workflows/delete.yml", ".github/workflows/update.yml"] def normalize(name): @@ -63,6 +65,16 @@ def register(pkg_name, version, author, short_desc, long_desc, homepage, link): with open(package_index, "w") as f: f.write(template) + # Finally, add the package in the github actions YAML files + for action_file in YAML_ACTION_FILES: + with open(action_file, "r") as f: + action = yaml.safe_load(f) + + action["on"]["workflow_dispatch"]["inputs"]["package_name"]["options"].append(pkg_name) + + with open(action_file, "w") as f: + yaml.dump(action, f, default_flow_style=False) + def update(pkg_name, version, link): # Read our index first @@ -119,6 +131,16 @@ def delete(pkg_name): with open(INDEX_FILE, 'wb') as index: index.write(soup.prettify("utf-8")) + # Finally, add the package in the github actions YAML files + for action_file in YAML_ACTION_FILES: + with open(action_file, "r") as f: + action = yaml.safe_load(f) + + action["on"]["workflow_dispatch"]["inputs"]["package_name"]["options"].remove(pkg_name) + + with open(action_file, "w") as f: + yaml.dump(action, f, default_flow_style=False) + def main(): # Call the right method, with the right arguments From 0eaadd6eb40dad84dbbe579888564cf4103d5fdd Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 14:26:33 +0000 Subject: [PATCH 07/14] :bug: Fix yaml issue with formatting --- .github/actions.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/actions.py b/.github/actions.py index 8cf3229..ee2a9ff 100644 --- a/.github/actions.py +++ b/.github/actions.py @@ -5,7 +5,7 @@ import shutil from bs4 import BeautifulSoup -import yaml +from ruamel.yaml import YAML INDEX_FILE = "index.html" @@ -66,14 +66,15 @@ def register(pkg_name, version, author, short_desc, long_desc, homepage, link): f.write(template) # Finally, add the package in the github actions YAML files + yaml = YAML() for action_file in YAML_ACTION_FILES: with open(action_file, "r") as f: - action = yaml.safe_load(f) + action = yaml.load(f) action["on"]["workflow_dispatch"]["inputs"]["package_name"]["options"].append(pkg_name) with open(action_file, "w") as f: - yaml.dump(action, f, default_flow_style=False) + yaml.dump(action, f) def update(pkg_name, version, link): @@ -132,14 +133,15 @@ def delete(pkg_name): index.write(soup.prettify("utf-8")) # Finally, add the package in the github actions YAML files + yaml = YAML() for action_file in YAML_ACTION_FILES: with open(action_file, "r") as f: - action = yaml.safe_load(f) + action = yaml.load(f) action["on"]["workflow_dispatch"]["inputs"]["package_name"]["options"].remove(pkg_name) with open(action_file, "w") as f: - yaml.dump(action, f, default_flow_style=False) + yaml.dump(action, f) def main(): From 5f059c036d5f4a6143b9e8294aea29a2e1395dad Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 14:36:16 +0000 Subject: [PATCH 08/14] :rocket: Fix github actions --- .github/workflows/delete.yml | 53 +++++++++++++++--------------- .github/workflows/register.yml | 57 ++++++++++++++++---------------- .github/workflows/update.yml | 60 ++++++++++++++++++---------------- 3 files changed, 87 insertions(+), 83 deletions(-) diff --git a/.github/workflows/delete.yml b/.github/workflows/delete.yml index 46888de..fe06fb1 100644 --- a/.github/workflows/delete.yml +++ b/.github/workflows/delete.yml @@ -1,16 +1,16 @@ name: delete -on: +on: workflow_dispatch: inputs: package_name: - description: 'Package name' - required: true + description: Package name type: choice options: - - mydependency - - private-hello - - public-hello + - private-hello + - public-hello + - mydependency + required: true jobs: delete: @@ -20,23 +20,24 @@ jobs: python-version: [3.6] steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Run Action - env: - PKG_ACTION: "DELETE" - PKG_NAME: ${{ inputs.package_name }} - run: | - pip install beautifulsoup4 pyyaml - python .github/actions.py - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - commit-message: ":package: [:robot:] Delete package from PyPi index" - title: "[🤖] Delete ${{ inputs.package_name }} from PyPi index" - body: "Automatically generated PR, deleting ${{ inputs.package_name }} from PyPi index." - branch-suffix: "random" - delete-branch: true + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Run Action + env: + PKG_ACTION: DELETE + PKG_NAME: ${{ inputs.package_name }} + run: | + pip install beautifulsoup4 ruamel.yaml + python .github/actions.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: ':package: [:robot:] Delete package from PyPi index' + title: '[🤖] Delete ${{ inputs.package_name }} from PyPi index' + body: Automatically generated PR, deleting ${{ inputs.package_name }} from + PyPi index. + branch-suffix: random + delete-branch: true diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml index 176db5b..9c8c4a8 100644 --- a/.github/workflows/register.yml +++ b/.github/workflows/register.yml @@ -1,6 +1,6 @@ name: register -on: +on: workflow_dispatch: inputs: package_name: @@ -33,36 +33,37 @@ on: type: string jobs: - register: + update: runs-on: ubuntu-latest strategy: matrix: python-version: [3.6] steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Run Action - env: - PKG_ACTION: "REGISTER" - PKG_NAME: ${{ inputs.package_name }} - PKG_VERSION: ${{ inputs.version }} - PKG_AUTHOR: ${{ inputs.author }} - PKG_SHORT_DESC: ${{ inputs.short_desc }} - PKG_LONG_DESC: ${{ inputs.long_desc }} - PKG_HOMEPAGE: ${{ inputs.homepage }} - PKG_LINK: ${{ inputs.link }} - run: | - pip install beautifulsoup4 pyyaml - python .github/actions.py - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - commit-message: ":package: [:robot:] Register package in PyPi index" - title: "[🤖] Register ${{ inputs.package_name }} in PyPi index" - body: "Automatically generated PR, registering ${{ inputs.package_name }} in PyPi index." - branch-suffix: "random" - delete-branch: true + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Run Action + env: + PKG_ACTION: "REGISTER" + PKG_NAME: ${{ inputs.package_name }} + PKG_VERSION: ${{ inputs.version }} + PKG_AUTHOR: ${{ inputs.author }} + PKG_SHORT_DESC: ${{ inputs.short_desc }} + PKG_LONG_DESC: ${{ inputs.long_desc }} + PKG_HOMEPAGE: ${{ inputs.homepage }} + PKG_LINK: ${{ inputs.link }} + run: | + pip install beautifulsoup4 ruamel.yaml + python .github/actions.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: ':package: [:robot:] Register package in PyPi index' + title: '[🤖] Register ${{ inputs.package_name }} in PyPi index' + body: Automatically generated PR, registering ${{ inputs.package_name }} in PyPi + index. + branch-suffix: random + delete-branch: true diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 2c9b5ad..6a8c836 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -1,22 +1,23 @@ name: update -on: +on: workflow_dispatch: inputs: package_name: - description: 'Package name' + description: Package name required: true type: choice options: - - mydependency - - private-hello - - public-hello + - private-hello + - public-hello + - mydependency version: - description: 'New version of the package' + description: New version of the package required: true type: string link: - description: 'Link used for `pip`. For example, for a github-hosted package refered by the tag `v3.0.2`, it would be : git+https://github.com/huggingface/transformers@v3.0.2' + description: 'Link used for `pip`. For example, for a github-hosted package + refered by the tag `v3.0.2`, it would be : git+https://github.com/huggingface/transformers@v3.0.2' required: true type: string @@ -28,25 +29,26 @@ jobs: python-version: [3.6] steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Run Action - env: - PKG_ACTION: "DELETE" - PKG_NAME: ${{ inputs.package_name }} - PKG_VERSION: ${{ inputs.version }} - PKG_LINK: ${{ inputs.link }} - run: | - pip install beautifulsoup4 pyyaml - python .github/actions.py - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - commit-message: ":package: [:robot:] Update package in PyPi index" - title: "[🤖] Update ${{ inputs.package_name }} in PyPi index" - body: "Automatically generated PR, updating ${{ inputs.package_name }} in PyPi index." - branch-suffix: "random" - delete-branch: true + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + - name: Run Action + env: + PKG_ACTION: DELETE + PKG_NAME: ${{ inputs.package_name }} + PKG_VERSION: ${{ inputs.version }} + PKG_LINK: ${{ inputs.link }} + run: | + pip install beautifulsoup4 ruamel.yaml + python .github/actions.py + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + commit-message: ':package: [:robot:] Update package in PyPi index' + title: '[🤖] Update ${{ inputs.package_name }} in PyPi index' + body: Automatically generated PR, updating ${{ inputs.package_name }} in PyPi + index. + branch-suffix: random + delete-branch: true From 4ec53765c7b010702bde41d19a06ead4ee456bec Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 14:36:57 +0000 Subject: [PATCH 09/14] :fire: Delete unused file --- .github/ISSUE_TEMPLATE/delete.md | 9 -------- .github/ISSUE_TEMPLATE/register.md | 18 --------------- .github/ISSUE_TEMPLATE/update.md | 11 --------- .github/workflows/register_update.yml | 32 --------------------------- 4 files changed, 70 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/delete.md delete mode 100644 .github/ISSUE_TEMPLATE/register.md delete mode 100644 .github/ISSUE_TEMPLATE/update.md delete mode 100644 .github/workflows/register_update.yml diff --git a/.github/ISSUE_TEMPLATE/delete.md b/.github/ISSUE_TEMPLATE/delete.md deleted file mode 100644 index 26c12ac..0000000 --- a/.github/ISSUE_TEMPLATE/delete.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -name: 🔴 Delete a package -about: Use this template for deleting an existing package of your PyPi index. -title: "🔴 Delete package :" ---- - -## 🔴 Package deletion form - -- **Package name :** diff --git a/.github/ISSUE_TEMPLATE/register.md b/.github/ISSUE_TEMPLATE/register.md deleted file mode 100644 index 9995e83..0000000 --- a/.github/ISSUE_TEMPLATE/register.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: 🟢 Register a new package -about: Use this template for registering a new package in your PyPi index. -title: "🟢 New package :" ---- - -## 🟢 New package registration form - -- **Package name :** -- **Version :** -- **Author :** -- **Short description :** -- **Long description :** -```html - -``` -- **Homepage :** -- **Link :** diff --git a/.github/ISSUE_TEMPLATE/update.md b/.github/ISSUE_TEMPLATE/update.md deleted file mode 100644 index 75f9c56..0000000 --- a/.github/ISSUE_TEMPLATE/update.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: 🔵 Update a package -about: Use this template for adding a new version of an existing package in your PyPi index. -title: "🔵 Update package :" ---- - -## 🔵 Package update form - -- **Package name :** -- **New version :** -- **Link for the new version :** diff --git a/.github/workflows/register_update.yml b/.github/workflows/register_update.yml deleted file mode 100644 index cee9688..0000000 --- a/.github/workflows/register_update.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: register_update - -on: - issues: - types: [opened, edited] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.6] - - steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Run Action - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: | - pip install beautifulsoup4 - python .github/actions.py - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - commit-message: ":package: [:robot:] Modify package in PyPi index" - title: "[🤖] ${{ github.event.issue.title }}" - body: "Fix #${{ github.event.issue.number }}" - branch: "pr/patch-${{ github.event.issue.number }}" From 1bf5737d6bc81310b04f82a19e487f3f67b88bfa Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:26:38 +0000 Subject: [PATCH 10/14] :fire: Remove the ability to choose package, use string type instead --- .github/actions.py | 23 ----------------------- .github/workflows/delete.yml | 8 ++------ .github/workflows/register.yml | 2 +- .github/workflows/update.yml | 8 ++------ 4 files changed, 5 insertions(+), 36 deletions(-) diff --git a/.github/actions.py b/.github/actions.py index ee2a9ff..4523c82 100644 --- a/.github/actions.py +++ b/.github/actions.py @@ -5,7 +5,6 @@ import shutil from bs4 import BeautifulSoup -from ruamel.yaml import YAML INDEX_FILE = "index.html" @@ -65,17 +64,6 @@ def register(pkg_name, version, author, short_desc, long_desc, homepage, link): with open(package_index, "w") as f: f.write(template) - # Finally, add the package in the github actions YAML files - yaml = YAML() - for action_file in YAML_ACTION_FILES: - with open(action_file, "r") as f: - action = yaml.load(f) - - action["on"]["workflow_dispatch"]["inputs"]["package_name"]["options"].append(pkg_name) - - with open(action_file, "w") as f: - yaml.dump(action, f) - def update(pkg_name, version, link): # Read our index first @@ -132,17 +120,6 @@ def delete(pkg_name): with open(INDEX_FILE, 'wb') as index: index.write(soup.prettify("utf-8")) - # Finally, add the package in the github actions YAML files - yaml = YAML() - for action_file in YAML_ACTION_FILES: - with open(action_file, "r") as f: - action = yaml.load(f) - - action["on"]["workflow_dispatch"]["inputs"]["package_name"]["options"].remove(pkg_name) - - with open(action_file, "w") as f: - yaml.dump(action, f) - def main(): # Call the right method, with the right arguments diff --git a/.github/workflows/delete.yml b/.github/workflows/delete.yml index fe06fb1..51a611e 100644 --- a/.github/workflows/delete.yml +++ b/.github/workflows/delete.yml @@ -5,12 +5,8 @@ on: inputs: package_name: description: Package name - type: choice - options: - - private-hello - - public-hello - - mydependency required: true + type: string jobs: delete: @@ -30,7 +26,7 @@ jobs: PKG_ACTION: DELETE PKG_NAME: ${{ inputs.package_name }} run: | - pip install beautifulsoup4 ruamel.yaml + pip install beautifulsoup4 python .github/actions.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml index 9c8c4a8..09371a3 100644 --- a/.github/workflows/register.yml +++ b/.github/workflows/register.yml @@ -56,7 +56,7 @@ jobs: PKG_HOMEPAGE: ${{ inputs.homepage }} PKG_LINK: ${{ inputs.link }} run: | - pip install beautifulsoup4 ruamel.yaml + pip install beautifulsoup4 python .github/actions.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 6a8c836..37824e3 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -6,11 +6,7 @@ on: package_name: description: Package name required: true - type: choice - options: - - private-hello - - public-hello - - mydependency + type: string version: description: New version of the package required: true @@ -41,7 +37,7 @@ jobs: PKG_VERSION: ${{ inputs.version }} PKG_LINK: ${{ inputs.link }} run: | - pip install beautifulsoup4 ruamel.yaml + pip install beautifulsoup4 python .github/actions.py - name: Create Pull Request uses: peter-evans/create-pull-request@v3 From 18ed779f99c2bd726b045323397a241ff0651ab8 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:30:21 +0000 Subject: [PATCH 11/14] :bug: Fix typo --- .github/workflows/register.yml | 2 +- .github/workflows/update.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml index 09371a3..3d9d6a7 100644 --- a/.github/workflows/register.yml +++ b/.github/workflows/register.yml @@ -47,7 +47,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Run Action env: - PKG_ACTION: "REGISTER" + PKG_ACTION: REGISTER PKG_NAME: ${{ inputs.package_name }} PKG_VERSION: ${{ inputs.version }} PKG_AUTHOR: ${{ inputs.author }} diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 37824e3..80985c2 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -32,7 +32,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Run Action env: - PKG_ACTION: DELETE + PKG_ACTION: UPDATE PKG_NAME: ${{ inputs.package_name }} PKG_VERSION: ${{ inputs.version }} PKG_LINK: ${{ inputs.link }} From d5e92d67c2f653b9dc621872dae54179fc0ecf7c Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:35:22 +0000 Subject: [PATCH 12/14] :art: Better formatting --- .github/workflows/delete.yml | 4 ++-- .github/workflows/register.yml | 4 ++-- .github/workflows/update.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/delete.yml b/.github/workflows/delete.yml index 51a611e..91d8b12 100644 --- a/.github/workflows/delete.yml +++ b/.github/workflows/delete.yml @@ -32,8 +32,8 @@ jobs: uses: peter-evans/create-pull-request@v3 with: commit-message: ':package: [:robot:] Delete package from PyPi index' - title: '[🤖] Delete ${{ inputs.package_name }} from PyPi index' - body: Automatically generated PR, deleting ${{ inputs.package_name }} from + title: '[🤖] Delete `${{ inputs.package_name }}` from PyPi index' + body: Automatically generated PR, deleting `${{ inputs.package_name }}` from PyPi index. branch-suffix: random delete-branch: true diff --git a/.github/workflows/register.yml b/.github/workflows/register.yml index 3d9d6a7..abb17cb 100644 --- a/.github/workflows/register.yml +++ b/.github/workflows/register.yml @@ -62,8 +62,8 @@ jobs: uses: peter-evans/create-pull-request@v3 with: commit-message: ':package: [:robot:] Register package in PyPi index' - title: '[🤖] Register ${{ inputs.package_name }} in PyPi index' - body: Automatically generated PR, registering ${{ inputs.package_name }} in PyPi + title: '[🤖] Register `${{ inputs.package_name }}` in PyPi index' + body: Automatically generated PR, registering `${{ inputs.package_name }}` in PyPi index. branch-suffix: random delete-branch: true diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 80985c2..ca66a54 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -43,8 +43,8 @@ jobs: uses: peter-evans/create-pull-request@v3 with: commit-message: ':package: [:robot:] Update package in PyPi index' - title: '[🤖] Update ${{ inputs.package_name }} in PyPi index' - body: Automatically generated PR, updating ${{ inputs.package_name }} in PyPi + title: '[🤖] Update `${{ inputs.package_name }}` in PyPi index' + body: Automatically generated PR, updating `${{ inputs.package_name }}` in PyPi index. branch-suffix: random delete-branch: true From d0e115ed4c56369c25250e4bd89e277b74db8534 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:44:36 +0000 Subject: [PATCH 13/14] :memo: Update README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5d8d268..6451b50 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ _It will not work, because it's private and only me can access it !_ ## Get started -* Use this template and create your own repository : [![Generic badge](https://img.shields.io/badge/Use%20this%20template-blueviolet.svg)](https://github.com/astariul/github-hosted-pypi/generate) +* Use this template and create your own repository : [![Generic badge](https://img.shields.io/badge/%20-Use%20this%20template-green?style=for-the-badge&color=347d39)](https://github.com/astariul/github-hosted-pypi/generate) * Go to `Settings` of your repository, and enable Github Page * Customize `index.html` and `pkg_template.html` to your liking * You're ready to go ! Visit `.github.io/` to see your PyPi index @@ -82,8 +82,9 @@ Now that your PyPi index is setup, you can register / update / delete packages i _Github actions are setup to do it automatically for you._ You just have to : -* Open an issue with the appropriate template -* Fill the information of the template (replace the comments) +* Go to the `Actions` tab of your repository +* Click the right workflow (`register` / `update` / `delete`) and trigger it manually +* Fill the form and start the workflow * Wait a bit * Check the new PR opened (ensure the code added correspond to what you want) * Merge the PR From 64be1eafc8055875ec0bcd8d2094035c808ab131 Mon Sep 17 00:00:00 2001 From: Astariul <43774355+astariul@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:45:58 +0000 Subject: [PATCH 14/14] :memo: Update README --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6451b50..dde670b 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,12 @@ _It will not work, because it's private and only me can access it !_ ## Get started -* Use this template and create your own repository : [![Generic badge](https://img.shields.io/badge/%20-Use%20this%20template-green?style=for-the-badge&color=347d39)](https://github.com/astariul/github-hosted-pypi/generate) +* Use this template and create your own repository : + +

+ Use template +

+ * Go to `Settings` of your repository, and enable Github Page * Customize `index.html` and `pkg_template.html` to your liking * You're ready to go ! Visit `.github.io/` to see your PyPi index