Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cwa/close-191-use-ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Oct 27, 2023
2 parents ee89b67 + f2b7644 commit 08591d7
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
if [ -n "${{ inputs.build_libs }}" ]; then
pip install ${{ inputs.build_libs }}
fi
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.2
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.3
- name: Parse changelog configuration
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_cd_updated_default_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ jobs:
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install ${EDITABLE}.${{ inputs.doc_extras }}
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.2
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.3
- name: Set up git user
if: env.RELEASE_RUN == 'false'
Expand Down
42 changes: 37 additions & 5 deletions .github/workflows/ci_check_pyproject_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ on:
required: false
type: string
default: ""
debug:
description: "Whether to run the workflow in debug mode, printing extra debug information."
required: false
type: boolean
default: false
secrets:
PAT:
description: "A personal access token (PAT) with rights to update the `permanent_dependencies_branch`. This will fallback on `GITHUB_TOKEN`."
Expand All @@ -75,18 +80,36 @@ jobs:

- name: Install Python dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install .${{ inputs.install_extras }}
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.2
if [ "${{ inputs.debug }}" == "true" ]; then
set -x
VERBOSE=-vvv
else
VERBOSE=
fi
python -m pip install -U ${VERBOSE} pip
pip install -U ${VERBOSE} setuptools wheel
pip install ${VERBOSE} .${{ inputs.install_extras }}
pip install ${VERBOSE} git+https://github.com/SINTEF/ci-cd.git@v2.5.3
- name: Set up git user
run: |
if [ "${{ inputs.debug }}" == "true" ]; then
set -x
fi
git config --global user.name "${{ inputs.git_username }}"
git config --global user.email "${{ inputs.git_email }}"
- name: Run ci-cd task
run: |
if [ "${{ inputs.debug }}" == "true" ]; then
set -x
VERBOSE=--verbose
else
VERBOSE=
fi
if [ "${{ inputs.fail_fast }}" == "true" ]; then
FAIL_FAST=--fail-fast
else
Expand All @@ -98,10 +121,15 @@ jobs:
if [ -n "${line}" ]; then IGNORE_OPTIONS+=(--ignore="${line}"); fi
done <<< "${{ inputs.ignore }}"
ci-cd update-deps ${FAIL_FAST} \
ci-cd update-deps ${FAIL_FAST} ${VERBOSE} \
--root-repo-path="${PWD}" \
--ignore-separator="..." \
"${IGNORE_OPTIONS[@]}"
if [ "${{ inputs.debug }}" == "true" ]; then
git status
fi
if [ -n "$(git status --porcelain pyproject.toml)" ]; then
echo "UPDATE_DEPS=true" >> $GITHUB_ENV
git add pyproject.toml
Expand All @@ -113,6 +141,10 @@ jobs:
- name: Set PR body
if: env.UPDATE_DEPS == 'true'
run: |
if [ "${{ inputs.debug }}" == "true" ]; then
set -x
fi
if [ -z "${{ inputs.pr_body_file }}" ] || [ ! -f "${{ inputs.pr_body_file }}" ]; then
PR_BODY_FILE=.tmp_pr-body_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
echo "PR_BODY_FILE=${PR_BODY_FILE}" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ jobs:
python -m pip install -U pip
pip install -U setuptools wheel
pip install ${EDITABLE}.${{ inputs.install_extras }}
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.2
pip install git+https://github.com/SINTEF/ci-cd.git@v2.5.3
- name: Update API Reference
if: env.framework == 'mkdocs' && inputs.update_python_api_ref
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## [Unreleased](https://github.com/SINTEF/ci-cd/tree/HEAD)

[Full Changelog](https://github.com/SINTEF/ci-cd/compare/v2.5.3...HEAD)

**Fixed bugs:**

- A PR is not opened for CI - Check dependencies [\#195](https://github.com/SINTEF/ci-cd/issues/195)

## [v2.5.3](https://github.com/SINTEF/ci-cd/tree/v2.5.3) (2023-10-25)

[Full Changelog](https://github.com/SINTEF/ci-cd/compare/v2.5.2...v2.5.3)

**Implemented enhancements:**

- Avoid warning for inter-relative extra dependencies [\#198](https://github.com/SINTEF/ci-cd/issues/198)
- Allow branch name customization [\#196](https://github.com/SINTEF/ci-cd/issues/196)

**Fixed bugs:**

- Ignore options not parseable [\#194](https://github.com/SINTEF/ci-cd/issues/194)

**Merged pull requests:**

- Add project name by default to `already_handled_packages` [\#202](https://github.com/SINTEF/ci-cd/pull/202) ([CasperWA](https://github.com/CasperWA))
- Customize branch name [\#201](https://github.com/SINTEF/ci-cd/pull/201) ([CasperWA](https://github.com/CasperWA))
- Handle package-specifier spacing [\#197](https://github.com/SINTEF/ci-cd/pull/197) ([CasperWA](https://github.com/CasperWA))

## [v2.5.2](https://github.com/SINTEF/ci-cd/tree/v2.5.2) (2023-10-04)

[Full Changelog](https://github.com/SINTEF/ci-cd/compare/v2.5.1...v2.5.2)
Expand Down
2 changes: 1 addition & 1 deletion ci_cd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""CI/CD Tools. Tiny package to run invoke tasks as a standalone program."""
__version__ = "2.5.2"
__version__ = "2.5.3"
__author__ = "Casper Welzel Andersen"
__author_email__ = "casper.w.andersen@sintef.no"
41 changes: 31 additions & 10 deletions ci_cd/tasks/update_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"Value to use instead of ellipsis (`...`) as a separator in `--ignore` "
"key/value-pairs."
),
"verbose": "Whether or not to print debug statements.",
},
iterable=["ignore"],
)
Expand All @@ -61,6 +62,7 @@ def update_deps(
pre_commit=False,
ignore=None,
ignore_separator="...",
verbose=False,
):
"""Update dependencies in specified Python package's `pyproject.toml`."""
if TYPE_CHECKING: # pragma: no cover
Expand All @@ -69,10 +71,16 @@ def update_deps(
fail_fast: bool = fail_fast # type: ignore[no-redef]
pre_commit: bool = pre_commit # type: ignore[no-redef]
ignore_separator: str = ignore_separator # type: ignore[no-redef]
verbose: bool = verbose # type: ignore[no-redef]

if not ignore:
ignore: list[str] = [] # type: ignore[no-redef]

if verbose:
LOGGER.setLevel(logging.DEBUG)
LOGGER.addHandler(logging.StreamHandler(sys.stdout))
LOGGER.debug("Verbose logging enabled.")

VersionSpec = namedtuple(
"VersionSpec",
[
Expand All @@ -83,6 +91,7 @@ def update_deps(
"version",
"extra_operator_version",
"environment_marker",
"spacing",
],
)

Expand Down Expand Up @@ -133,7 +142,8 @@ def update_deps(
error = False
for line in dependencies:
match = re.match(
r"^(?P<full_dependency>(?P<package>[a-zA-Z0-9_.-]+)(?:\s*\[.*\])?)\s*"
r"^(?P<full_dependency>(?P<package>[a-zA-Z0-9_.-]+)(?:\s*\[.*\])?)"
r"(?P<spacing>\s*)"
r"(?:"
r"(?P<url_version>@\s*\S+)|"
r"(?P<operator>>|<|<=|>=|==|!=|~=)\s*"
Expand Down Expand Up @@ -266,16 +276,27 @@ def update_deps(
escaped_full_dependency_name = version_spec.full_dependency.replace(
"[", r"\["
).replace("]", r"\]")
update_file(
pyproject_path,
(
rf'"{escaped_full_dependency_name} {version_spec.operator}.*"',
f'"{version_spec.full_dependency} '
f"{version_spec.operator}{updated_version}"
f'{version_spec.extra_operator_version if version_spec.extra_operator_version else ""}' # noqa: E501
f'{version_spec.environment_marker if version_spec.environment_marker else ""}"', # noqa: E501
),

LOGGER.debug("updated_version: %s", updated_version)
LOGGER.debug(
"escaped_full_dependency_name: %s", escaped_full_dependency_name
)

pattern_sub_line = (
rf'"{escaped_full_dependency_name}{version_spec.spacing}'
rf'{version_spec.operator}.*"'
)
replacement_sub_line = (
f'"{version_spec.full_dependency}{version_spec.spacing}'
f"{version_spec.operator}{updated_version}"
f'{version_spec.extra_operator_version if version_spec.extra_operator_version else ""}' # noqa: E501
f'{version_spec.environment_marker if version_spec.environment_marker else ""}"' # noqa: E501
)

LOGGER.debug("pattern_sub_line: %s", pattern_sub_line)
LOGGER.debug("replacement_sub_line: %s", replacement_sub_line)

update_file(pyproject_path, (pattern_sub_line, replacement_sub_line))
already_handled_packages.add(version_spec.package)
updated_packages[version_spec.full_dependency] = (
f"{version_spec.operator}{updated_version}"
Expand Down
2 changes: 1 addition & 1 deletion docs/hooks/docs_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ It is meant to be complete as is.
```yaml
repos:
- repo: https://github.com/SINTEF/ci-cd
rev: v2.5.2
rev: v2.5.3
hooks:
- id: docs-api-reference
args:
Expand Down
2 changes: 1 addition & 1 deletion docs/hooks/docs_landing_page.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ It is meant to be complete as is.
```yaml
repos:
- repo: https://github.com/SINTEF/ci-cd
rev: v2.5.2
rev: v2.5.3
hooks:
- id: docs-landing-page
args:
Expand Down
3 changes: 2 additions & 1 deletion docs/hooks/update_pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Any of these options can be given through the `args` key when defining the hook.
| `--fail-fast` | Fail immediately if an error occurs. Otherwise, print and ignore all non-critical errors. | No | `False` | _boolean_ |
| `--ignore` | Ignore-rules based on the `ignore` config option of Dependabot.</br></br>It should be of the format: `key=value...key=value`, i.e., an ellipsis (`...`) separator and then equal-sign-separated key/value-pairs.</br>Alternatively, the `--ignore-separator` can be set to something else to overwrite the ellipsis.</br></br>The only supported keys are: `dependency-name`, `versions`, and `update-types`.</br></br>Can be supplied multiple times per `dependency-name`. | No | | _string_ |
| `--ignore-separator` | Value to use instead of ellipsis (`...`) as a separator in `--ignore` key/value-pairs. | No | | _string_ |
| `--verbose` | Whether or not to print debug statements. | No | `False` | _boolean_ |

## Usage example

Expand All @@ -64,7 +65,7 @@ It is meant to be complete as is.
```yaml
repos:
- repo: https://github.com/SINTEF/ci-cd
rev: v2.5.2
rev: v2.5.3
hooks:
- id: update-pyproject
args:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CI/CD tools

**Current version to use:** `v2.5.2`
**Current version to use:** `v2.5.3`

Use tried and tested continuous integration (CI) and continuous deployment (CD) tools from this repository.

Expand Down
4 changes: 2 additions & 2 deletions docs/workflows/cd_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ See the [proper section](../hooks/docs_api_reference.md#using-it-together-with-c
The content of repository files can be updated to use the new version where necessary.
This is done through the `version_update_changes` (and `version_update_changes_separator`) inputs.

To see an example of how to use the `version_update_changes` (and `version_update_changes_separator`) see for example the [workflow used by the SINTEF/ci-cd repository](https://github.com/SINTEF/ci-cd/blob/v2.5.2/.github/workflows/_local_cd_release.yml) calling the _CD Release_ workflow.
To see an example of how to use the `version_update_changes` (and `version_update_changes_separator`) see for example the [workflow used by the SINTEF/ci-cd repository](https://github.com/SINTEF/ci-cd/blob/v2.5.3/.github/workflows/_local_cd_release.yml) calling the _CD Release_ workflow.

Some notes to consider and respect when using `version_update_changes` are:

Expand Down Expand Up @@ -139,7 +139,7 @@ on:
jobs:
publish:
name: Publish package and documentation
uses: SINTEF/ci-cd/.github/workflows/cd_release.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/cd_release.yml@v2.5.3
if: github.repository == 'SINTEF/my-python-package' && startsWith(github.ref, 'refs/tags/v')
with:
git_username: "Casper Welzel Andersen"
Expand Down
6 changes: 3 additions & 3 deletions docs/workflows/ci_automerge_prs.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ on:
jobs:
update-dependency-branch:
name: Call external workflow
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.5.3
if: github.repository_owner == 'SINTEF' && ( ( startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]' ) || ( github.event.pull_request.head.ref == 'ci/update-pyproject' && github.actor == 'CasperWA' ) )
secrets:
PAT: ${{ secrets.RELEASE_PAT }}
Expand All @@ -76,7 +76,7 @@ on:
jobs:
update-dependency-branch:
name: Call external workflow
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.5.3
if: github.repository_owner == 'SINTEF' && ( ( startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]' ) || ( github.event.pull_request.head.ref == 'ci/update-pyproject' && github.actor == 'CasperWA' ) )
with:
perform_changes: true
Expand All @@ -100,7 +100,7 @@ on:
jobs:
update-dependency-branch:
name: Call external workflow
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_automerge_prs.yml@v2.5.3
if: github.repository_owner == 'SINTEF' && ( ( startsWith(github.event.pull_request.head.ref, 'dependabot/') && github.actor == 'dependabot[bot]' ) || ( github.event.pull_request.head.ref == 'ci/update-pyproject' && github.actor == 'CasperWA' ) )
with:
perform_changes: true
Expand Down
2 changes: 1 addition & 1 deletion docs/workflows/ci_cd_updated_default_branch.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ on:
jobs:
updates-to-stable:
name: Call external workflow
uses: SINTEF/ci-cd/.github/workflows/ci_cd_updated_default_branch.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_cd_updated_default_branch.yml@v2.5.3
if: github.repository_owner == 'SINTEF'
with:
git_username: "Casper Welzel Andersen"
Expand Down
5 changes: 3 additions & 2 deletions docs/workflows/ci_check_pyproject_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Here is an example of different lines given as value for the `ignore` option tha
# ...
jobs:
check-dependencies:
uses: SINTEF/ci-cd/.github/workflows/ci_check_pyproject_dependencies.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_check_pyproject_dependencies.yml@v2.5.3
with:
# ...
# For Sphinx, ignore all updates for/from version 4.5.0 and up / keep the minimum version for Sphinx at 4.5.0.
Expand Down Expand Up @@ -70,6 +70,7 @@ The repository contains the following:
| `pr_labels` | A comma separated list of strings of GitHub labels to use for the created PR. | No | _Empty string_ | _string_ |
| `ignore` | Create ignore conditions for certain dependencies. A multi-line string of ignore rules, where each line is an ellipsis-separated (`...`) string of key/value-pairs. One line per dependency. This option is similar to [the `ignore` option of Dependabot](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file#ignore).</br></br>See also [Single vs multi-line input](index.md#single-vs-multi-line-input). | No | _Empty string_ | _string_
| `branch_name_extension` | A string to append to the branch name of the created PR. Example: `'-my-branch'`. It will be appended after a forward slash, so the final branch name will be `ci/update-pyproject/-my-branch`. | No | _Empty string_ | _string_ |
| `debug` | Whether to run the workflow in debug mode, printing extra debug information. | No | `false` | _boolean_ |

## Secrets

Expand All @@ -93,7 +94,7 @@ on:
jobs:
check-dependencies:
name: Call external workflow
uses: SINTEF/ci-cd/.github/workflows/ci_check_pyproject_dependencies.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_check_pyproject_dependencies.yml@v2.5.3
if: github.repository_owner == 'SINTEF'
with:
git_username: "Casper Welzel Andersen"
Expand Down
4 changes: 2 additions & 2 deletions docs/workflows/ci_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ on:
jobs:
tests:
name: Run basic tests
uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v2.5.3
with:
python_version_pylint_safety: "3.8"
python_version_docs: "3.7"
Expand Down Expand Up @@ -191,7 +191,7 @@ on:
jobs:
tests:
name: Run basic tests
uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_tests.yml@v2.5.3
with:
python_version_pylint_safety: "3.8"
python_version_docs: "3.7"
Expand Down
2 changes: 1 addition & 1 deletion docs/workflows/ci_update_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ on:
jobs:
check-dependencies:
name: Call external workflow
uses: SINTEF/ci-cd/.github/workflows/ci_update_dependencies.yml@v2.5.2
uses: SINTEF/ci-cd/.github/workflows/ci_update_dependencies.yml@v2.5.3
if: github.repository_owner == 'SINTEF'
with:
git_username: "Casper Welzel Andersen"
Expand Down
Loading

0 comments on commit 08591d7

Please sign in to comment.