Skip to content

Commit

Permalink
fix: workflow and readme sync
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Ortega <[email protected]>
  • Loading branch information
M0NsTeRRR committed Nov 17, 2024
1 parent 556a412 commit e8e006e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 49 deletions.
3 changes: 1 addition & 2 deletions Pulumi.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ config:
configs: []
# custom file available in the repository to add to renovatebot config
additionnal_configs: []
# enable changelog workflow
changelog: true
# set repository language if there is one
language: python
versions: ["3.9", "3.10", "3.11", "3.12", "3.13"]
Expand All @@ -58,6 +56,7 @@ config:
workflow:
lint: false
test: false
changelog: true
# enable pages
# pages:
# branch: "gh-pages"
Expand Down
2 changes: 1 addition & 1 deletion Pulumi.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ config:
renovatebot:
configs: []
additionnal_configs: []
changelog: true
language: python
versions: ["3.9", "3.10", "3.11", "3.12", "3.13"]
gitignore: true
devcontainer: true
workflow:
lint: true
test: true
changelog: true
44 changes: 21 additions & 23 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
owner = pulumi.Config("github").require("owner")

for repository_config in config.get_object("repositories"):
workflow = False
workflow_lint = False
workflow_test = False
workflow_package = False
workflow_changelog = False
if "workflow" in repository_config:
workflow = {
"lint": "lint" not in repository_config["workflow"]
or repository_config["workflow"]["lint"],
"test": "test" not in repository_config["workflow"]
or repository_config["workflow"]["test"],
"package": "package" not in repository_config["workflow"]
or repository_config["workflow"]["package"],
}
else:
workflow = None

changelog = repository_config.get("changelog", False)

workflow = True
workflow_lint = "lint" not in repository_config["workflow"] or repository_config["workflow"]["lint"]
workflow_test = "test" not in repository_config["workflow"] or repository_config["workflow"]["test"]
workflow_package = "package" not in repository_config["workflow"] or repository_config["workflow"]["package"]
workflow_changelog = "changelog" not in repository_config["workflow"] or repository_config["workflow"]["changelog"]

devcontainer = repository_config.get("devcontainer", False)
helm = repository_config.get("helm", False)
package = "package_name" in repository_config and repository_config["package_name"]
Expand All @@ -44,7 +42,7 @@
pages=repository_config.get("pages", None),
)

repository.sync_repository_ruleset(language, versions, workflow["lint"], workflow["test"])
repository.sync_repository_ruleset(versions, workflow_lint, workflow_test)

if "license" in repository_config and repository_config["license"]:
repository.sync_licence(repository_config["license"])
Expand Down Expand Up @@ -108,22 +106,22 @@
repository_config.get("documentation_url", None),
"logo" in repository_config and repository_config["logo"],
language,
workflow,
changelog,
workflow_lint,
workflow_test,
workflow_package,
workflow_changelog,
docker,
helm,
repository_config.get("package", None),
workflow["lint"],
workflow["test"],
dev,
)

if workflow or changelog:
if workflow:
repository.sync_workflow(
language,
versions,
workflow,
changelog,
package,
workflow_lint,
workflow_test,
workflow_package,
workflow_changelog,
docker,
)
36 changes: 18 additions & 18 deletions src/git_automation/GitRepositoryComponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,18 +338,17 @@ def sync_readme(
documentation_url: str,
logo: bool,
language: str,
workflow: Dict[str, Any],
lint: bool,
test: bool,
package: bool,
changelog: bool,
docker: bool,
helm: bool,
package: str,
lint: bool,
test: bool,
dev: List[str],
):
# check if a readme already exist
r = requests.get(
f"https://api.github.com/repos/{self.owner}/{self.name}/contents/README.md?ref={self.branch_name}",
f"https://api.github.com/repos/{self.owner}/{self.name}/contents/README.md",
headers = {
"Accept": "application/vnd.github.raw+json",
"Authorization": f"Bearer {os.environ["GITHUB_TOKEN"]}"
Expand All @@ -370,13 +369,12 @@ def sync_readme(
repository_description=repository_description,
logo=logo,
language=language,
workflow=workflow,
lint=lint,
test=test,
package=package,
changelog=changelog,
docker=docker,
helm=helm,
package=package,
lint=lint,
test=test,
dev=dev,
),
)
Expand All @@ -385,13 +383,16 @@ def sync_workflow(
self,
language: str,
versions: List[str],
workflow: Dict[str, str],
changelog: bool,
lint: bool,
test: bool,
package: bool,
changelog: bool,
docker: bool,
):
template = env.get_template(os.path.join("workflow", "lint-pr.yml.j2"))



self._repository_file(
"workflow",
".github/workflows/lint-pr.yml",
Expand All @@ -412,22 +413,22 @@ def sync_workflow(
),
)

if workflow["lint"]:
if lint:
template = env.get_template(os.path.join("workflow", "lint.yml.j2"))

self._repository_file(
"workflow",
".github/workflows/lint.yml",
template.render(language=language, workflow=workflow),
template.render(language=language),
)

if workflow["test"]:
if test:
template = env.get_template(os.path.join("workflow", "test.yml.j2"))

self._repository_file(
"workflow",
".github/workflows/test.yml",
template.render(language=language, versions=versions, workflow=workflow),
template.render(language=language, versions=versions),
)

if changelog:
Expand All @@ -446,14 +447,13 @@ def sync_workflow(
".github/workflows/release.yml",
template.render(
language=language,
workflow=workflow,
changelog=changelog,
package=package,
changelog=changelog,
docker=docker,
),
)

def sync_repository_ruleset(self, language: str, versions: List[str], lint: bool, test: bool):
def sync_repository_ruleset(self, versions: List[str], lint: bool, test: bool):
required_checks = [
github.RepositoryRulesetRulesRequiredStatusChecksRequiredCheckArgs(
context="DCO"
Expand Down
6 changes: 3 additions & 3 deletions src/git_automation/templates/readme/sections/header.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ _{{ repository_description }}_
</div>
<div align="center">

{% if workflow["lint"] and language in ["python"] %}
{% if lint and language in ["python"] %}
[![Lint](https://img.shields.io/github/actions/workflow/status/{{ repository_name }}/lint.yml?branch=main&label=&logo=ruff&style=for-the-badge&logoColor=D7FF64&color=black)](https://github.com/{{ repository_name }}/tree/main/.github/workflows/lint.yml)
{%- endif %}
{%- if workflow["test"] and language in ["python"] %}
{%- if test and language in ["python"] %}
[![Test](https://img.shields.io/github/actions/workflow/status/{{ repository_name }}/test.yml?branch=main&label=&logo=pytest&style=for-the-badge&logoColor=white&color=0A9EDC)](https://github.com/{{ repository_name }}/tree/main/.github/workflows/test.yml)
{%- endif %}
{%- if changelog or package or docker %}
Expand All @@ -25,7 +25,7 @@ _{{ repository_description }}_

<div align="center">

{% if language == "python" and package is defined %}
{% if language == "python" and package %}
[![Pypi](https://img.shields.io/pypi/v/{{ package }}?label=&logo=pypi&style=for-the-badge&logoColor=yellow&color=3776AB)](https://pypi.python.org/pypi/{{ package_name }})
[![Python](https://img.shields.io/pypi/pyversions/{{ package }}?label=&logo=python&style=for-the-badge&logoColor=yellow&color=3776AB)](https://pypi.python.org/pypi/{{ package_name }})
{%- endif %}
Expand Down
4 changes: 2 additions & 2 deletions src/git_automation/templates/workflow/release.yml.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# THIS FILE IS GENERATED! DO NOT EDIT! Maintained by Pulumi
{%- set included_content -%}
{%- if package %}
{% include "workflow/{}/package.yml.j2".format(language) %}
{%- include "workflow/{}/package.yml.j2".format(language) %}
{%- endif %}
{%- if docker %}
{%- include "workflow/docker.yml.j2" -%}
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
publish_release:
name: Publish release
runs-on: ubuntu-latest
needs: [create_draft_release{%- if changelog %}, changelog{% endif -%}{{ needs }}]
needs: [create_draft_release{{ needs }}]
{%- raw %}
steps:
- name: Checkout
Expand Down

0 comments on commit e8e006e

Please sign in to comment.