Skip to content

Commit

Permalink
WIP Add cookiecutter templates for CI
Browse files Browse the repository at this point in the history
This should help to keep the CI consistent across multiple cli plugin
repositories.

[noissue]
  • Loading branch information
mdellweg committed Jan 21, 2024
1 parent 5e5de8f commit 3c55d63
Show file tree
Hide file tree
Showing 39 changed files with 1,234 additions and 43 deletions.
38 changes: 38 additions & 0 deletions .ci/scripts/apply_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sys
from pathlib import Path

import toml
from cookiecutter.main import cookiecutter

if __name__ == "__main__":
sections = ["ci"]

if len(sys.argv) == 2:
config = {
"app_label": sys.argv[1],
"glue": True,
"docs": False,
"translations": False,
}
sections.insert(0, "bootstrap")
else:
with open("pyproject.toml") as fp:
config = toml.load(fp)["tool"]["pulp_cli_template"]

if config["docs"]:
sections.append("docs")

print(sections)
exit

cutter_path = Path(__file__).parent.parent.parent / "cookiecutter"

for section in sections:
print(f"Apply {section} template")
cookiecutter(
str(cutter_path / section),
no_input=True,
extra_context=config,
overwrite_if_exists=True,
output_dir="..",
)
2 changes: 1 addition & 1 deletion .ci/scripts/create_release_branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ find CHANGES/ \( -name "*.feature" -o -name "*.bugfix" -o -name "*.doc" -o -name
sed -i -e "1 i \\${NEW_BRANCH}" docs/versions.txt
git add docs/versions.txt

bumpversion minor --commit --message $'Bump version to {new_version}\n\n[noissue]' --allow-dirty
bump2version minor --commit --message $'Bump version to {new_version}\n\n[noissue]' --allow-dirty

git push origin "${NEW_BRANCH}"
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}"
restore-keys: |
${{ runner.os }}-pip-
- name: "Set up Python"
uses: "actions/setup-python@v5"
with:
Expand Down
43 changes: 22 additions & 21 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@ name: "CodeQL"
on:
push:
branches:
- main
- "main"
workflow_call:

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
name: "Analyze"
runs-on: "ubuntu-latest"
permissions:
actions: read
contents: read
security-events: write
actions: "read"
contents: "read"
security-events: "write"

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/cache@v4
- name: "Checkout repository"
uses: "actions/checkout@v4"
- uses: "actions/cache@v4"
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}
path: "~/.cache/pip"
key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}"
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python
uses: actions/setup-python@v5
- name: "Set up Python"
uses: "actions/setup-python@v5"
with:
python-version: '3.11'
- name: Manually install from sources
python-version: "3.11"
- name: "Manually install from sources"
run: |
python -m pip install -e . -e ./pulp-glue
echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
echo "CODEQL_PYTHON=$(which python)" >> "$GITHUB_ENV"
- name: "Initialize CodeQL"
uses: "github/codeql-action/init@v3"
with:
languages: python
languages: "python"
setup-python-dependencies: false

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: "Perform CodeQL Analysis"
uses: "github/codeql-action/analyze@v3"
with:
category: "/language:python"
18 changes: 9 additions & 9 deletions .github/workflows/collect_changes.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
name: Collect changes
name: "Collect changes"
on:
workflow_call:
workflow_dispatch:

jobs:
collect-changes:
runs-on: ubuntu-latest
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- uses: "actions/checkout@v4"
with:
ref: "main"
fetch-depth: 0
- uses: actions/setup-python@v5
- uses: "actions/setup-python@v5"
with:
python-version: "3.11"
- name: Setup git
- name: "Setup git"
run: |
git config user.name pulpbot
git config user.email [email protected]
- name: Collect changes
- name: "Collect changes"
run: |
pip install GitPython packaging toml
python3 .ci/scripts/collect_changes.py
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
- name: "Create Pull Request"
uses: "peter-evans/create-pull-request@v5"
with:
token: ${{ secrets.RELEASE_TOKEN }}
token: "${{ secrets.RELEASE_TOKEN }}"
title: "Update Changelog"
body: ""
branch: "update_changes"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}"
restore-keys: |
${{ runner.os }}-pip-
- name: "Download wheels"
uses: "actions/download-artifact@v4"
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- name: Set up Python
uses: actions/setup-python@v5
- name: "Set up Python"
uses: "actions/setup-python@v5"
with:
python-version: 3.11
python-version: "3.11"
- name: "Run publish docs script"
env:
PULP_DOCS_KEY: "${{ secrets.PULP_DOCS_KEY }}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}"
restore-keys: |
${{ runner.os }}-pip-
- name: "Download wheels"
uses: "actions/download-artifact@v4"
with:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

LANGUAGES=de
GLUE_PLUGINS=$(notdir $(wildcard pulp-glue/pulp_glue/*))
CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*))
Expand All @@ -18,7 +19,7 @@ black:
black .

lint:
find . -name '*.sh' -print0 | xargs -0 shellcheck -x
find tests .ci -name '*.sh' -print0 | xargs -0 shellcheck -x
isort -c --diff .
cd pulp-glue; isort -c --diff .
black --diff --check .
Expand Down Expand Up @@ -65,6 +66,5 @@ $(foreach LANGUAGE,$(LANGUAGES),pulpcore/cli/%/locale/$(LANGUAGE)/LC_MESSAGES/me
msgfmt -o $@ $<

compile_messages: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo))

.PHONY: build info black lint test servedocs site
.PRECIOUS: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po))
12 changes: 12 additions & 0 deletions cookiecutter/bootstrap/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"app_label": "noname",
"glue": true,
"docs": false,
"translations": false,
"test_matrix": "- python: \"3.11\"\nimage_tag: \"nightly\"\npulp_api_root: \"/relocated/djnd/\"\n- python: \"3.6\"\nimage_tag: \"latest\"\nlower_bounds: true",
"__app_label_suffix": "{{ cookiecutter.app_label and '-' + cookiecutter.app_label }}",
"__project_name": "pulp-cli{{ cookiecutter.__app_label_suffix }}",
"__project_slug": "{{ cookiecutter.__project_name | lower | replace(' ', '_') }}",
"_copy_without_render": [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

[//]: # (You should *NOT* be adding new change log entries to this file, this)
[//]: # (file is managed by towncrier. You *may* edit previous change logs to)
[//]: # (fix problems like typo corrections or such.)
[//]: # (To add a new change log entry, please see)
[//]: # (https://docs.pulpproject.org/contributing/git.html#changelog-update)

[//]: # (WARNING: Don't drop the towncrier directive!)

[//]: # (towncrier release notes start)

Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "{{ cookiecutter.__project_slug }}"
version = "0.0.1.dev"
description = "Command line interface to talk to pulpcore's REST API. ({{ cookiecutter.app_label | capitalize }} plugin commands)"
readme = "README.md"
requires-python = ">=3.6"
license = {text = "GPLv2+"}
authors = [
{name = "Pulp Team", email = "[email protected]"},
]
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: System :: Software Distribution",
"Typing :: Typed",
]
dependencies = [
"pulp-cli>=0.23.1,<0.24.0.dev",
"pulp-glue-{{ cookiecutter.app_label }}==0.0.1.dev",
]

[project.urls]
repository = "https://github.com/pulp/{{ cookiecutter.__project_slug }}"
changelog = "https://github.com/pulp/{{ cookiecutter.__project_slug }}/blob/main/CHANGES.md"

[project.entry-points."pulp_cli.plugins"]
{{ cookiecutter.app_label }} = "pulpcore.cli.{{ cookiecutter.app_label }}"

[tool.setuptools.packages.find]
where = ["."]
include = ["pulpcore.cli.*"]
namespaces = true

[tool.setuptools.package-data]
"*" = ["py.typed", "locale/*/LC_MESSAGES/*.mo"]

[tool.pulp_cli_template]
app_label = "{{ cookiecutter.app_label }}"
glue = true
docs = false
translations = false
test_matrix = """
- python: "3.11"
image_tag: "nightly"
pulp_api_root: "/relocated/djnd/"
- python: "3.6"
image_tag: "latest"
lower_bounds: true
"""

[tool.towncrier]
filename = "CHANGES.md"
directory = "CHANGES/"
title_format = "## {version} ({project_date})"
template = "CHANGES/.TEMPLATE.md"
issue_format = "[#{issue}](https://github.com/pulp/{{ cookiecutter.__project_slug }}/issues/{issue})"
start_string = "[//]: # (towncrier release notes start)\n"
underlines = ["", "", ""]

[[tool.towncrier.section]]
path = ""
name = ""

[[tool.towncrier.section]]
path = "pulp-glue-{{ cookiecutter.app_label }}"
name = "Pulp-{{ cookiecutter.app_label }} GLUE"

[[tool.towncrier.type]]
directory = "feature"
name = "Features"
showcontent = true

[[tool.towncrier.type]]
directory = "bugfix"
name = "Bugfixes"
showcontent = true

[[tool.towncrier.type]]
directory = "doc"
name = "Improved Documentation"
showcontent = true

[[tool.towncrier.type]]
directory = "removal"
name = "Deprecations and Removals"
showcontent = true

[[tool.towncrier.type]]
directory = "translation"
name = "Translations"
showcontent = true

[[tool.towncrier.type]]
directory = "devel"
name = "Developer Notes"
showcontent = true

[[tool.towncrier.type]]
directory = "misc"
name = "Misc"
showcontent = false

[tool.black]
target = "py36"
line-length = 100

[tool.isort]
profile = "black"
line_length = 100
skip = ["pulp-glue-{{ cookiecutter.app_label }}"]

[tool.pytest.ini_options]
markers = [
"script: tests provided as shell scripts",
"help_page: tests that render help pages",
"pulp_{{ cookiecutter.app_label }}: pulp_{{ cookiecutter.app_label }} tests",
]

[tool.mypy]
strict = true
show_error_codes = true
files = "pulpcore/**/*.py"
namespace_packages = true
explicit_package_bases = true

[[tool.mypy.overrides]]
module = [
"click_shell.*",
"schema.*",
]
ignore_missing_imports = true
Loading

0 comments on commit 3c55d63

Please sign in to comment.