Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cwa/fix-141-utilize-i…
Browse files Browse the repository at this point in the history
…gnore
  • Loading branch information
CasperWA committed Oct 27, 2023
2 parents 05067a8 + f2b7644 commit 0e2fdac
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 54 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
49 changes: 43 additions & 6 deletions .github/workflows/ci_check_pyproject_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ on:
required: false
type: string
default: ""
branch_name_extension:
description: "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`."
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 @@ -70,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 @@ -93,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 @@ -108,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 Expand Up @@ -140,7 +177,7 @@ jobs:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
committer: "${{ inputs.git_username }} <${{ inputs.git_email }}>"
author: "${{ inputs.git_username }} <${{ inputs.git_email }}>"
branch: ci/update-pyproject
branch: ci/update-pyproject${{ inputs.branch_name_extension && format('/{0}', inputs.branch_name_extension) || ''}}
delete-branch: true
title: "[Auto-generated] Check & update dependencies (`pyproject.toml`)"
body: ${{ steps.pr_body.outputs.result }}
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"
24 changes: 19 additions & 5 deletions ci_cd/tasks/update_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def _format_and_update_dependency(
"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 @@ -100,6 +101,7 @@ def update_deps( # pylint: disable=too-many-branches,too-many-locals,too-many-s
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 @@ -108,10 +110,16 @@ def update_deps( # pylint: disable=too-many-branches,too-many-locals,too-many-s
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.")

try:
ignore_rules = parse_ignore_entries(ignore, ignore_separator)
except InputError as exc:
Expand Down Expand Up @@ -162,6 +170,10 @@ def update_deps( # pylint: disable=too-many-branches,too-many-locals,too-many-s
" in 'pyproject.toml'."
)

# Skip package if it is this project (this can happen for inter-relative extra
# dependencies)
already_handled_packages: set[str] = {project_name}

# Build the list of dependencies listed in pyproject.toml
dependencies: list[str] = pyproject.get("project", {}).get("dependencies", [])
for optional_deps in (
Expand All @@ -170,7 +182,6 @@ def update_deps( # pylint: disable=too-many-branches,too-many-locals,too-many-s
dependencies.extend(optional_deps)

# Placeholder and default variables
already_handled_packages = set()
updated_packages = {}
error = False

Expand Down Expand Up @@ -405,11 +416,14 @@ def update_deps( # pylint: disable=too-many-branches,too-many-locals,too-many-s
)
LOGGER.debug("Updated dependency: %r", updated_dependency)

pattern_sub_line = re.escape(dependency)
replacement_sub_line = updated_dependency.replace('"', "'")

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

# Update pyproject.toml
update_file(
pyproject_path,
(re.escape(dependency), updated_dependency.replace('"', "'")),
)
update_file(pyproject_path, (pattern_sub_line, replacement_sub_line))
already_handled_packages.add(parsed_requirement)
updated_packages[parsed_requirement.name] = ",".join(
str(_)
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
10 changes: 8 additions & 2 deletions docs/workflows/ci_check_pyproject_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ The reason for having this workflow and not using [Dependabot](https://github.co
If a PAT is not passed through for the `PAT` secret and `GITHUB_TOKEN` is used, beware that any other CI/CD jobs that run for, e.g., pull request events, may not run since `GITHUB_TOKEN`-generated PRs are designed to not start more workflows to avoid escalation.
Hence, if it is important to run CI/CD workflows for pull requests, consider passing a PAT as a secret to this workflow represented by the `PAT` secret.

!!! info
The generated PR will be created from a new branch named `ci/update-pyproject`.
If you wish to change this value, see the [`branch_name_extension`](#inputs) input option.

## Ignoring dependencies

To ignore or configure how specific dependencies should be updated, the `ignore` input option can be utilized.
Expand All @@ -33,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 @@ -65,6 +69,8 @@ The repository contains the following:
| `fail_fast` | Whether the task to update dependencies should fail if any error occurs. | No | `false` | _boolean_ |
| `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 @@ -88,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 0e2fdac

Please sign in to comment.