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 support of node packages #17

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions .github/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ docker:
auto_login: true
images:
- name: camptocamp/tag-publish
repository:
github:
server: ghcr.io
versions:
- version_tag
- version_branch
- rebuild
helm:
folders:
- tests
packages:
- folder: tests
node:
packages:
- folder: tests
dispatch:
- {}
19 changes: 16 additions & 3 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _Tag Publish configuration file_
- **`tag_to_version_re`**: Refer to _[#/definitions/version_transform](#definitions/version_transform)_.
- **`docker`**: Refer to _[#/definitions/docker](#definitions/docker)_.
- **`pypi`**: Refer to _[#/definitions/pypi](#definitions/pypi)_.
- **`node`**: Refer to _[#/definitions/node](#definitions/node)_.
- **`helm`**: Refer to _[#/definitions/helm](#definitions/helm)_.
- **`dispatch`** _(array)_: Default: `[]`.
- **Items** _(object)_: Send a dispatch event to an other repository. Default: `{}`.
Expand All @@ -25,7 +26,7 @@ _Tag Publish configuration file_
- **`name`** _(string)_: The image name.
- **`tags`** _(array)_: The tag name, will be formatted with the version=<the version>, the image with version=latest should be present when we call the tag-publish script. Default: `["{version}"]`.
- **Items** _(string)_
- **`repository`** _(object)_: The repository where we should publish the images. Can contain additional properties. Default: `{"github": {"server": "ghcr.io", "versions": ["version_tag", "version_branch", "rebuild"]}, "dockerhub": {}}`.
- **`repository`** _(object)_: The repository where we should publish the images. Can contain additional properties. Default: `{"github": {"server": "ghcr.io", "versions": ["version_tag", "version_branch", "rebuild"]}}`.
- **Additional properties** _(object)_
- **`server`** _(string)_: The server URL.
- **`versions`** _(array)_: The kind or version that should be published, tag, branch or value of the --version argument of the tag-publish script. Default: `["version_tag", "version_branch", "rebuild", "feature_branch"]`.
Expand All @@ -51,9 +52,21 @@ _Tag Publish configuration file_
- **Items** _(string)_
- **`versions`** _(array)_: The kind or version that should be published, tag, branch or value of the --version argument of the tag-publish script. Default: `["version_tag"]`.
- **Items** _(string)_
- <a id="definitions/helm"></a>**`helm`** _(object)_: Configuration to publish Helm charts on GitHub release.
- **`folders`** _(array)_: The folders that will be published.
- <a id="definitions/node"></a>**`node`** _(object)_: Configuration to publish on node.
- **`packages`** _(array)_: The configuration of packages that will be published.
- **Items** _(object)_: The configuration of package that will be published.
- **`group`** _(string)_: The image is in the group, should be used with the --group option of tag-publish script. Default: `"default"`.
- **`folder`** _(string)_: The folder of the node package. Default: `"."`.
- **`versions`** _(array)_: The kind or version that should be published, tag, branch or value of the --version argument of the tag-publish script. Default: `["version_tag"]`.
- **Items** _(string)_
- **`repository`** _(object)_: The packages repository where we should publish the packages. Can contain additional properties. Default: `{"github": {"server": "npm.pkg.github.com"}}`.
- **Additional properties** _(object)_
- **`server`** _(string)_: The server URL.
- <a id="definitions/helm"></a>**`helm`** _(object)_: Configuration to publish Helm charts on GitHub release.
- **`packages`** _(array)_: The configuration of packages that will be published.
- **Items** _(object)_: The configuration of package that will be published.
- **`group`** _(string)_: The image is in the group, should be used with the --group option of tag-publish script. Default: `"default"`.
- **`folder`** _(string)_: The folder of the pypi package. Default: `"."`.
- **`versions`** _(array)_: The kind or version that should be published, tag, branch or value of the --version argument of the tag-publish script. Default: `["version_tag"]`.
- **Items** _(string)_
- <a id="definitions/version_transform"></a>**`version_transform`** _(array)_: A version transformer definition.
Expand Down
60 changes: 52 additions & 8 deletions tag_publish/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ def main() -> None:
success &= _handle_pypi_publish(
args.group, args.dry_run, config, version, version_type, github, published_payload
)
success &= _handle_node_publish(
args.group, args.dry_run, config, version, version_type, published_payload
)
success &= _handle_docker_publish(
args.group,
args.dry_run,
Expand All @@ -195,7 +198,9 @@ def main() -> None:
published_payload,
local,
)
success &= _handle_helm_publish(args.dry_run, config, version, version_type, github, published_payload)
success &= _handle_helm_publish(
args.group, args.dry_run, config, version, version_type, github, published_payload
)
_trigger_dispatch_events(config, version, version_type, published_payload, github)

if not success:
Expand Down Expand Up @@ -232,6 +237,38 @@ def _handle_pypi_publish(
return success


def _handle_node_publish(
group: str,
dry_run: bool,
config: tag_publish.configuration.Configuration,
version: str,
version_type: str,
published_payload: list[tag_publish.PublishedPayload],
) -> bool:
success = True
node_config = config.get("node", {})
if node_config:
for package in node_config.get("packages", []):
if package.get("group", tag_publish.configuration.PIP_PACKAGE_GROUP_DEFAULT) == group:
publish = version_type in node_config.get(
"versions", tag_publish.configuration.PYPI_VERSIONS_DEFAULT
)
folder = package.get("folder", tag_publish.configuration.PYPI_PACKAGE_FOLDER_DEFAULT)
for repo_name, repo_config in node_config.get("repository", {}).items():
if dry_run:
print(
f"{'Publishing' if publish else 'Checking'} '{folder}' to {repo_name}, "
"skipping (dry run)"
)
else:
success &= tag_publish.publish.node(
package, version, version_type, repo_config, publish
)
if publish:
published_payload.append({"type": "node", "folder": folder})
return success


def _handle_docker_publish(
group: str,
dry_run: bool,
Expand Down Expand Up @@ -451,6 +488,7 @@ def _handle_docker_publish(


def _handle_helm_publish(
group: str,
dry_run: bool,
config: tag_publish.configuration.Configuration,
version: str,
Expand Down Expand Up @@ -496,13 +534,19 @@ def _handle_helm_publish(
versions[-1] = str(int(versions[-1]) + 1)
version = ".".join(versions)

for folder in helm_config["folders"]:
if dry_run:
print(f"Publishing '{folder}' to helm, skipping (dry run)")
else:
token = os.environ["GITHUB_TOKEN"]
success &= tag_publish.publish.helm(folder, version, owner, repo, commit_sha, token)
published_payload.append({"type": "helm", "folder": folder})
for package in helm_config["packages"]:
if package.get("group", tag_publish.configuration.PIP_PACKAGE_GROUP_DEFAULT) == group:
publish = version_type in helm_config.get(
"versions", tag_publish.configuration.PYPI_VERSIONS_DEFAULT
)
if publish:
folder = package.get("folder", tag_publish.configuration.HELM_PACKAGE_FOLDER_DEFAULT)
if dry_run:
print(f"Publishing '{folder}' to helm, skipping (dry run)")
else:
token = os.environ["GITHUB_TOKEN"]
success &= tag_publish.publish.helm(folder, version, owner, repo, commit_sha, token)
published_payload.append({"type": "helm", "folder": folder})
return success


Expand Down
130 changes: 125 additions & 5 deletions tag_publish/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class Configuration(TypedDict, total=False):
Configuration to publish on pypi
"""

node: "Node"
"""
node.

Configuration to publish on node
"""

helm: "Helm"
"""
helm.
Expand Down Expand Up @@ -82,8 +89,7 @@ class Configuration(TypedDict, total=False):


DOCKER_REPOSITORY_DEFAULT = {
"github": {"server": "ghcr.io", "versions": ["version_tag", "version_branch", "rebuild"]},
"dockerhub": {},
"github": {"server": "ghcr.io", "versions": ["version_tag", "version_branch", "rebuild"]}
}
""" Default value of the field path 'Docker repository' """

Expand Down Expand Up @@ -152,7 +158,6 @@ class Docker(TypedDict, total=False):
The repository where we should publish the images

default:
dockerhub: {}
github:
server: ghcr.io
versions:
Expand Down Expand Up @@ -220,6 +225,14 @@ class DockerRepository(TypedDict, total=False):
"""


HELM_PACKAGE_FOLDER_DEFAULT = "."
""" Default value of the field path 'helm package folder' """


HELM_PACKAGE_GROUP_DEFAULT = "default"
""" Default value of the field path 'helm package group' """


HELM_VERSIONS_DEFAULT = ["version_tag"]
""" Default value of the field path 'helm versions' """

Expand All @@ -231,8 +244,8 @@ class Helm(TypedDict, total=False):
Configuration to publish Helm charts on GitHub release
"""

folders: List[str]
""" The folders that will be published """
packages: List["HelmPackage"]
""" The configuration of packages that will be published """

versions: List[str]
"""
Expand All @@ -245,6 +258,113 @@ class Helm(TypedDict, total=False):
"""


class HelmPackage(TypedDict, total=False):
"""
helm package.

The configuration of package that will be published
"""

group: str
"""
helm package group.

The image is in the group, should be used with the --group option of tag-publish script

default: default
"""

folder: str
"""
helm package folder.

The folder of the pypi package

default: .
"""


NODE_PACKAGE_FOLDER_DEFAULT = "."
""" Default value of the field path 'node package folder' """


NODE_PACKAGE_GROUP_DEFAULT = "default"
""" Default value of the field path 'node package group' """


NODE_REPOSITORY_DEFAULT = {"github": {"server": "npm.pkg.github.com"}}
""" Default value of the field path 'node repository' """


NODE_VERSIONS_DEFAULT = ["version_tag"]
""" Default value of the field path 'node versions' """


class Node(TypedDict, total=False):
"""
node.

Configuration to publish on node
"""

packages: List["NodePackage"]
""" The configuration of packages that will be published """

versions: List[str]
"""
node versions.

The kind or version that should be published, tag, branch or value of the --version argument of the tag-publish script

default:
- version_tag
"""

repository: Dict[str, "NodeRepository"]
"""
Node repository.

The packages repository where we should publish the packages

default:
github:
server: npm.pkg.github.com
"""


class NodePackage(TypedDict, total=False):
"""
node package.

The configuration of package that will be published
"""

group: str
"""
node package group.

The image is in the group, should be used with the --group option of tag-publish script

default: default
"""

folder: str
"""
node package folder.

The folder of the node package

default: .
"""


class NodeRepository(TypedDict, total=False):
"""Node repository."""

server: str
""" The server URL """


PIP_PACKAGE_GROUP_DEFAULT = "default"
""" Default value of the field path 'pypi package group' """

Expand Down
Loading