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 cookiecutter templates for CI #879

Merged
merged 1 commit into from
Jan 30, 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
28 changes: 28 additions & 0 deletions .ci/scripts/apply_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path

import toml
from cookiecutter.main import cookiecutter

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

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=overwrite,
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))
17 changes: 17 additions & 0 deletions cookiecutter/ci/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"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": [
".github/workflows/collect_changes.yml",
".github/workflows/pr.yml",
".github/workflows/release.yml",
".github/workflows/release_branch.yml",
".github/workflows/pr_checks.yml"
]
}
8 changes: 8 additions & 0 deletions cookiecutter/ci/templates/cache_action
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{%- raw %}
- uses: "actions/cache@v4"
with:
path: "~/.cache/pip"
key: "${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/*constraints.lock', '**/setup.py', '**/pyproject.toml') }}"
restore-keys: |
${{ runner.os }}-pip-
{%- endraw %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/sh

# This file is shared between some projects please keep all copies in sync
# Known places:
# - https://github.com/pulp/pulp-cli/blob/main/.ci/run_container.sh
# - https://github.com/pulp/pulp-cli-deb/blob/main/.ci/run_container.sh
# - https://github.com/pulp/pulp-cli-gem/blob/main/.ci/run_container.sh
# - https://github.com/pulp/pulp-cli-maven/blob/main/.ci/run_container.sh
# - https://github.com/pulp/pulp-cli-ostree/blob/main/.ci/run_container.sh
# - https://github.com/pulp/squeezer/blob/develop/tests/run_container.sh

set -eu

BASEPATH="$(dirname "$(readlink -f "$0")")"
export BASEPATH

if [ -z "${CONTAINER_RUNTIME:+x}" ]
then
if ls /usr/bin/podman
then
CONTAINER_RUNTIME=podman
else
CONTAINER_RUNTIME=docker
fi
fi
export CONTAINER_RUNTIME

if [ -z "${KEEP_CONTAINER:+x}" ]
then
RM="yes"
else
RM=""
fi

IMAGE_TAG="${IMAGE_TAG:-latest}"
FROM_TAG="${FROM_TAG:-latest}"

if [ "${CONTAINER_FILE:+x}" ]
then
IMAGE_TAG="ephemeral-build"
"${CONTAINER_RUNTIME}" build --file "${BASEPATH}/assets/${CONTAINER_FILE}" --build-arg FROM_TAG="${FROM_TAG}" --tag ghcr.io/pulp/pulp:"${IMAGE_TAG}" .
fi

if [ "$(getenforce)" = "Enforcing" ]; then
SELINUX="yes"
else
SELINUX=""
fi;

"${CONTAINER_RUNTIME}" run ${RM:+--rm} --env S6_KEEP_ENV=1 ${PULP_API_ROOT:+--env PULP_API_ROOT} --detach --name "pulp-ephemeral" --volume "${BASEPATH}/settings:/etc/pulp${SELINUX:+:Z}" --publish "8080:80" "ghcr.io/pulp/pulp:${IMAGE_TAG}"

# shellcheck disable=SC2064
trap "${CONTAINER_RUNTIME} stop pulp-ephemeral" EXIT
# shellcheck disable=SC2064
trap "${CONTAINER_RUNTIME} stop pulp-ephemeral" INT

echo "Wait for pulp to start."
for counter in $(seq 40 -1 0)
do
if [ "$counter" = "0" ]
then
echo "FAIL."
"${CONTAINER_RUNTIME}" images
"${CONTAINER_RUNTIME}" ps -a
"${CONTAINER_RUNTIME}" logs "pulp-ephemeral"
exit 1
fi

sleep 3
if curl --fail "http://localhost:8080${PULP_API_ROOT:-/pulp/}api/v3/status/" > /dev/null 2>&1
then
echo "SUCCESS."
break
fi
echo "."
done

# show pulpcore/plugin versions we're using
curl -s "http://localhost:8080${PULP_API_ROOT:-/pulp/}api/v3/status/" | jq '.versions|map({key: .component, value: .version})|from_entries'

# Set admin password
"${CONTAINER_RUNTIME}" exec "pulp-ephemeral" pulpcore-manager reset-admin-password --password password

if [ -d "${BASEPATH}/container_setup.d/" ]
then
run-parts --regex '^[0-9]+-[-_[:alnum:]]*\.sh$' "${BASEPATH}/container_setup.d/"
fi

PULP_LOGGING="${CONTAINER_RUNTIME}" "$@"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/env python3

import sys

import click
from packaging.version import parse

if parse(click.__version__) < parse("8.1.1") or parse(click.__version__) >= parse("8.2"):
print("🚧 Linting with mypy is currently only supported with click~=8.1.1. 🚧")
Comment on lines +8 to +9
Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me again what was the mypy issue with click>=8.2?

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 think they changed some annotations in incompatible ways. I found no way to lint with 8.1.1 and 8.2 simultaneously. Maybe it's time to try again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hah, the answer is much simpler: The latest version of click is 8.1.7.

print("🔧 Please run `pip install click~=8.1.1` first. 🔨")
sys.exit(1)
Loading
Loading