Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release workflow #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Grub4K
Copy link
Member

@Grub4K Grub4K commented Aug 17, 2024

Following changes:

  • Migrates plugin to hatch for easy access to metadata and consistency with main project
  • Support for automated release workflow
  • Support for automated™ plugin bundling
  • Readme adjustments to reflect changes
    • In the future, the import should be moved to plugin systems responsibility

Upon merge this will create a dummy release if actions are activated. The same goes for when creating a repository with this as template, and actions enabled. Is this a problem?

Demo release: https://github.com/Grub4K/yt-dlp-sample-plugins/releases/tag/v2023.1.2

Fixes #2

version = "2023.01.02"
readme = "README.md"
requires-python = ">=3.8"
license = "MIT"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
license = "MIT"
license = "Unlicense"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a discrepancy between wanting people to NOT use Unlicense by default, and us licensing the code as Unlicense... But I'll make it Unlicense for the time being

Copy link

@grqz grqz Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
license = "MIT"
license = {file = "LICENSE"}

why not let the plugin developer decide which license to use theirself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair

@@ -1,4 +1,4 @@
This repository contains a sample plugin package for [yt-dlp](https://github.com/yt-dlp/yt-dlp#readme).
This repository contains a sample plugin package for [yt-dlp](https://github.com/yt-dlp/yt-dlp#readme).

See [yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#plugins) for more details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expand on the installation instructions

Perhaps something like

1. Download the latest release zip from [releases](https://github.com/yt-dlp/yt-dlp-sample-plugins/releases) 

2. Add the zip to one of the [yt-dlp plugin locations](https://github.com/yt-dlp/yt-dlp#installing-plugins)

    - User Plugins
        - `${XDG_CONFIG_HOME}/yt-dlp/plugins` (recommended on Linux/MacOS)
        - `~/.yt-dlp/plugins/`
        - `${APPDATA}/yt-dlp/plugins/` (recommended on Windows)
    
    - System Plugins
       -  `/etc/yt-dlp/plugins/`
       -  `/etc/yt-dlp-plugins/`
    
    - Executable location
        - Binary: where `<root-dir>/yt-dlp.exe`, `<root-dir>/yt-dlp-plugins/`

For more locations and methods, see [installing yt-dlp plugins](https://github.com/yt-dlp/yt-dlp#installing-plugins) 

- name: Set variables
id: set_variables
run: |
tag="$(git describe --tags --abbrev=0)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to assume a git tag already exists

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right I forgot I tested with a failed tag existing

Copy link

@grqz grqz Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tag="$(git describe --tags --abbrev=0)"
tag=$(git for-each-ref refs/tags --sort=-creatordate --format='%(refname:strip=2)' --count=1)

This gives an empty string when no tags are present. It works without problem creating the first release of the repo.
Refer to https://stackoverflow.com/a/5261470

name: Create release
on: [push]

jobs:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps could be useful to add pypi publishing too (might be out of scope for this pr)


import_path = str(pathlib.Path(__file__).parent.parent.parent)

sys.path.insert(0, import_path)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong:

Suggested change
sys.path.insert(0, import_path)
sys.path.append(import_path)

while IFS=';' read -r name path; do
if [[ ! "${name}" =~ ^(pip|setuptools|wheel)$ ]]; then
package_name="$(tr '[:upper:]' '[:lower:]' <<<"${name}" | sed 's/-/_/g')"
cp -r "${path}/${package_name}" bundle/
Copy link

@grqz grqz Sep 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some projects don't have it's code in this path. For example a normal yt-dlp plugin or yt-dlp itself. not sure if we can run pip install . and change installation path to bundle/ and remove .dist-info if necessary, probably like pip install -t bundle/ .?

example log from shell
$ pip install -t bundle/ .; ls -al bundle/
Processing /home/user/tmp
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting yt-dlp-get-pot>=0.0.2
  Using cached yt_dlp_get_pot-0.0.2-py3-none-any.whl (6.8 kB)
Building wheels for collected packages: definitely_not_bgutil-ytdlp-pot-provider_to_distinguish_from_it
  Building wheel for definitely_not_bgutil-ytdlp-pot-provider_to_distinguish_from_it (pyproject.toml) ... done
  Created wheel for definitely_not_bgutil-ytdlp-pot-provider_to_distinguish_from_it: filename=definitely_not_bgutil_ytdlp_pot_provider_to_distinguish_from_it-0.2.22-py3-none-any.whl size=1243 sha256=25788b6ccab2676493a4fdb39808dc3833a7699963d504e1137f2d2fde310794
  Stored in directory: /tmp/pip-ephem-wheel-cache-yh0ca0qt/wheels/c5/5b/dd/eba17e133d5a684b348375bea715fd011a6e07e4630222c11b
Successfully built definitely_not_bgutil-ytdlp-pot-provider_to_distinguish_from_it
Installing collected packages: yt-dlp-get-pot, definitely_not_bgutil-ytdlp-pot-provider_to_distinguish_from_it
Successfully installed definitely_not_bgutil-ytdlp-pot-provider_to_distinguish_from_it-0.2.22 yt-dlp-get-pot-0.0.2
total 20
drwxr-xr-x 5 user user 4096 Sep  2 19:42 .
drwxr-xr-x 5 user user 4096 Sep  2 19:42 ..
drwxr-xr-x 2 user user 4096 Sep  2 19:42 definitely_not_bgutil_ytdlp_pot_provider_to_distinguish_from_it-0.2.22.dist-info
drwxr-xr-x 3 user user 4096 Sep  2 19:42 yt_dlp_get_pot-0.0.2.dist-info
drwxr-xr-x 3 user user 4096 Sep  2 19:42 yt_dlp_plugins

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will look into it; it's def cleaner than copying.

Perhaps we could use something like hatch dep show requirements, or something with --no-deps? There's room to cook something here, I just can't see it quite yet

cp -r yt_dlp_plugins bundle/

while IFS=';' read -r name path; do
if [[ ! "${name}" =~ ^(pip|setuptools|wheel)$ ]]; then
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also exclude yt-dlp?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested this originally too, but found you'd need to specify all of yt-dlp's dependencies too (until yt-dlp switches to not requiring deps by default)

@@ -0,0 +1,65 @@
name: Create release
on: [push]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
on: [push]
on:
push:
branches:
- 'master'
paths:
- 'pyproject.toml'

maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike having the branch hardcoded, as I tend to use main for my branches, but I guess if people use the template they will get this name...

Copy link

@grqz grqz Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    if: format('refs/heads/{0}', github.event.repository.default_branch) == github.ref

maybe use this at job level instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll make it show up as a run but just be skipped. Your previous suggestion is the way to go I think

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use something like this?

    branches:
      - ${{ github.event.repository.default_branch }}

if: |
env.tag != env.version
run: |
project_name="$(hatch project metadata | jq -r .name)"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to the set_variables step?

Comment on lines +63 to +65
gh release create "${version}" --latest \
--title "${project_name} ${version}" \
"${project_name}.zip"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider generating a simple changelog

run: |
tag="$(git describe --tags --abbrev=0)"
echo "::group::Variables"
cat << EOF | tee -a "$GITHUB_OUTPUT"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a basic release GH action
3 participants