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

Fix typing #11

Merged
merged 2 commits into from
Sep 5, 2023
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
2 changes: 1 addition & 1 deletion .ci/assets/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ FROM ghcr.io/pulp/pulp-ci-centos:${FROM_TAG}
ARG PULP_MAVEN_VERSION=""

RUN pip3 install --upgrade \
pulp_maven${PULP_OSTREE_VERSION} \
pulp_maven${PULP_MAVEN_VERSION} \
requests
4 changes: 4 additions & 0 deletions .ci/assets/release_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bump2version
gitpython
python-redmine
towncrier
94 changes: 94 additions & 0 deletions .ci/scripts/collect_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import itertools
import os
import re

import toml
from git import GitCommandError, Repo
from pkg_resources import parse_version

# Read Towncrier settings
tc_settings = toml.load("pyproject.toml")["tool"]["towncrier"]

CHANGELOG_FILE = tc_settings.get("filename", "NEWS.rst")
START_STRING = tc_settings.get(
"start_string",
"<!-- towncrier release notes start -->\n"
if CHANGELOG_FILE.endswith(".md")
else ".. towncrier release notes start\n",
)
TITLE_FORMAT = tc_settings.get("title_format", "{name} {version} ({project_date})")


NAME_REGEX = r".*"
VERSION_REGEX = r"([0-9]+\.[0-9]+\.[0-9][0-9ab]*)"
DATE_REGEX = r"[0-9]{4}-[0-9]{2}-[0-9]{2}"
TITLE_REGEX = (
"("
+ re.escape(
TITLE_FORMAT.format(name="NAME_REGEX", version="VERSION_REGEX", project_date="DATE_REGEX")
)
.replace("NAME_REGEX", NAME_REGEX)
.replace("VERSION_REGEX", VERSION_REGEX)
.replace("DATE_REGEX", DATE_REGEX)
+ ")"
)


def get_changelog(repo, branch):
return repo.git.show(f"{branch}:{CHANGELOG_FILE}") + "\n"


def _tokenize_changes(splits):
assert len(splits) % 3 == 0
for i in range(len(splits) // 3):
title = splits[3 * i]
version = parse_version(splits[3 * i + 1])
yield [version, title + splits[3 * i + 2]]


def split_changelog(changelog):
preamble, rest = changelog.split(START_STRING, maxsplit=1)
split_rest = re.split(TITLE_REGEX, rest)
return preamble + START_STRING + split_rest[0], list(_tokenize_changes(split_rest[1:]))


def main():
repo = Repo(os.getcwd())
remote = repo.remotes[0]
branches = [ref for ref in remote.refs if re.match(r"^([0-9]+)\.([0-9]+)$", ref.remote_head)]
branches.sort(key=lambda ref: parse_version(ref.remote_head), reverse=True)
branches = [ref.name for ref in branches]

with open(CHANGELOG_FILE, "r") as f:
main_changelog = f.read()
preamble, main_changes = split_changelog(main_changelog)
old_length = len(main_changes)

for branch in branches:
print(f"Looking at branch {branch}")
try:
changelog = get_changelog(repo, branch)
except GitCommandError:
print("No changelog found on this branch.")
continue
dummy, changes = split_changelog(changelog)
new_changes = sorted(main_changes + changes, key=lambda x: x[0], reverse=True)
# Now remove duplicates (retain the first one)
main_changes = [new_changes[0]]
for left, right in itertools.pairwise(new_changes):
if left[0] != right[0]:
main_changes.append(right)

new_length = len(main_changes)
if old_length < new_length:
print(f"{new_length - old_length} new versions have been added.")
with open(CHANGELOG_FILE, "w") as fp:
fp.write(preamble)
for change in main_changes:
fp.write(change[1])

repo.git.commit("-m", "Update Changelog", "-m" "[noissue]", CHANGELOG_FILE)


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions .ci/scripts/create_release_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -eu -o pipefail

BRANCH="$(git branch --show-current)"

if ! [[ "${BRANCH}" = "main" ]]
then
echo ERROR: This is not the main branch!
exit 1
fi

NEW_BRANCH="$(bump2version --dry-run --list release | sed -Ene 's/^new_version=([[:digit:]]+\.[[:digit:]]+)\..*$/\1/p')"

if [[ -z "${NEW_BRANCH}" ]]
then
echo ERROR: Could not parse new version.
exit 1
fi

git branch "${NEW_BRANCH}"

# Clean changelog snippets.
find CHANGES/ \( -name "*.feature" -o -name "*.bugfix" -o -name "*.doc" -o -name "*.translation" -o -name "*.devel" -o -name "*.misc" \) -exec git rm -f \{\} +

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

git push origin "${NEW_BRANCH}"
26 changes: 26 additions & 0 deletions .ci/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -eu -o pipefail

BRANCH=$(git branch --show-current)

if ! [[ "${BRANCH}" =~ ^[0-9]+\.[0-9]+$ ]]
then
echo ERROR: This is not a release branch!
exit 1
fi

NEW_VERSION="$(bump2version --dry-run --list release | sed -ne 's/^new_version=//p')"
echo "Release ${NEW_VERSION}"

if ! [[ "${NEW_VERSION}" == "${BRANCH}"* ]]
then
echo ERROR: Version does not match release branch
exit 1
fi

towncrier build --yes --version "${NEW_VERSION}"
bumpversion release --commit --message "Release {new_version}" --tag --tag-name "{new_version}" --tag-message "Release {new_version}" --allow-dirty
bumpversion patch --commit

git push origin "${BRANCH}" "${NEW_VERSION}"
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: 🐛 Bug report
about: Create a report to help us improve the cli
labels: bug, Triage-Needed

---

## Summary
<!-- A clear and concise description of what the bug is. -->

## Steps to reproduce
<!-- Steps to reproduce the behavior. Please list actual cli commands. -->

## Expected behavior
<!-- A clear and concise description of what you expected to happen. -->

## Stacktrace/Error log
<!-- If possible, add a stacktrace and/or logs -->

## Pulp and pulp-cli version info
<!-- Verbatim output of `pulp --version` and `pulp status` -->

## Additonal context
<!-- Add any other context about the problem here. -->
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: ✨ Feature request
about: Suggest an idea for this project
labels: feature request, Triage-Needed

---

## Summary
<!-- Include any api information. Pulpcore features should be opened against pulpcore, not here. -->

## Examples
<!-- If applicable, include some proposed cli command examples -->
<!-- If applicable, include some related httpie call examples -->

44 changes: 44 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "CodeQL"

on:
push:
branches:
- main
workflow_call:

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

steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/cache@v3
with:
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@v4
with:
python-version: '3.11'
- name: Manually install from sources
run: |
python -m pip install -e . -e ./pulp-glue-maven
echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: python
setup-python-dependencies: false

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

jobs:
collect-changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: "main"
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Setup git
run: |
git config user.name pulpbot
git config user.email [email protected]
- name: Collect changes
run: |
pip install GitPython toml
python3 .ci/scripts/collect_changes.py
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.RELEASE_TOKEN }}
title: "Update Changelog"
body: ""
branch: "update_changes"
delete-branch: true
10 changes: 5 additions & 5 deletions .github/workflows/kanban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Add issue to Free-to-take list
uses: leonsteinhaeuser/project-beta-automations@v2.0.1
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.RELEASE_TOKEN }}
organization: pulp
Expand All @@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Move an issue to the In Progress column
uses: leonsteinhaeuser/project-beta-automations@v2.0.1
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.RELEASE_TOKEN }}
organization: pulp
Expand All @@ -55,7 +55,7 @@ jobs:
linked-issues: ${{ steps.linked-issues.outputs.issues }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Get Linked Issues Action
uses: kin/[email protected]
id: linked-issues
Expand All @@ -73,7 +73,7 @@ jobs:
issues: ${{ fromJSON(needs.find-linked-issues.outputs.linked-issues) }}
steps:
- name: Move to Needs Review
uses: leonsteinhaeuser/project-beta-automations@v2.0.1
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.RELEASE_TOKEN }}
organization: pulp
Expand All @@ -87,7 +87,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Move an issue to the Done column
uses: leonsteinhaeuser/project-beta-automations@v2.0.1
uses: leonsteinhaeuser/project-beta-automations@v2.1.0
with:
gh_token: ${{ secrets.RELEASE_TOKEN }}
organization: pulp
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Lint

on:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- "3.8"
- "3.11"
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
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@v4
with:
python-version: ${{ matrix.python }}
- name: Install python dependencies
run: pip install -r lint_requirements.txt
- name: Lint code
run: make lint
Loading
Loading