Skip to content

Commit

Permalink
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 25, 2024
1 parent 207b3d8 commit 32519a1
Show file tree
Hide file tree
Showing 39 changed files with 1,243 additions and 47 deletions.
43 changes: 43 additions & 0 deletions .ci/scripts/apply_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys
from pathlib import Path

import toml
from cookiecutter.main import cookiecutter

if __name__ == "__main__":
sections = []
overwrite = True

if len(sys.argv) == 2:
config = {
"app_label": sys.argv[1],
"glue": True,
"docs": False,
"translations": False,
}
sections.append("bootstrap")
overwrite = False

print("Bootstrapping a plugin is not yet supported.")
print("Remove these lines in order to continue.")
exit(1)
else:
with open("pyproject.toml") as fp:
config = toml.load(fp)["tool"]["pulp_cli_template"]

sections.append("ci")

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

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
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
python:
- "3.9"
- "3.8"
- "3.11"
steps:
- uses: "actions/checkout@v4"
Expand All @@ -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
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ jobs:
- python: "3.11"
image_tag: "latest"
- python: "3.6"
image_tag: "3.28"
image_tag: "3.39"
- python: "3.7"
image_tag: "3.21"
image_tag: "3.28"
lower_bounds: true
- python: "3.8"
image_tag: "3.22"
- python: "3.9"
image_tag: "3.39"
image_tag: "3.21"
pulp_api_root: "/relocated/djnd/"
- python: "3.10"
image_tag: "3.18"
Expand All @@ -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)

Loading

0 comments on commit 32519a1

Please sign in to comment.