chore: pre-commit improvements (#348)

##### SUMMARY

- Speed up pre-commit by moving some tasks out of pre-commit
- Move network related hooks out of pre-commit (allow enabling
pre-commit.ci)
- Some optimization
- Use pre-commit.ci
This commit is contained in:
Jonas L 2023-10-06 16:02:46 +02:00 committed by GitHub
parent 7f4e4e96cc
commit 9eab32cf3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 311 additions and 306 deletions

View file

@ -6,7 +6,7 @@ on:
pull_request:
jobs:
pre-commit:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@ -15,9 +15,11 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.x
cache: pip
cache-dependency-path: requirements.txt
- name: Install dependencies
run: pip install pre-commit
run: make venv
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure
- name: Lint docs
run: make lint-docs

26
.github/workflows/vendor.yml vendored Normal file
View file

@ -0,0 +1,26 @@
name: Vendor
on:
push:
branches: [main, stable-1]
paths:
- plugins/module_utils/vendor/**
- scripts/vendor.py
pull_request:
paths:
- plugins/module_utils/vendor/**
- scripts/vendor.py
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Ensure vendors are not diverging
run: make vendor-check

View file

@ -25,7 +25,6 @@ repos:
hooks:
- id: prettier
files: \.(md|ya?ml)$
exclude: ^changelogs/changelog.yaml$
- repo: https://github.com/asottile/pyupgrade
rev: v3.14.0
@ -49,22 +48,12 @@ repos:
- id: antsibull-changelog-lint
- id: antsibull-changelog-lint-changelog-yaml
- repo: local
hooks:
- id: antsibull-docs-lint-collection
name: antsibull-docs lint-collection
description: Lint the collection docs
language: python
entry: antsibull-docs lint-collection-docs --plugin-docs .
pass_filenames: false
additional_dependencies:
- antsibull-docs==2.3.1
- repo: https://github.com/ansible/ansible-lint
rev: v6.20.3
hooks:
- id: ansible-lint
name: ansible-lint
args: [--offline]
- repo: local
hooks:
@ -83,14 +72,6 @@ repos:
- repo: local
hooks:
- id: check-hcloud-vendor
name: check hcloud vendor
description: Ensure the hcloud vendored files are in sync
language: python
entry: python3 scripts/vendor.py
pass_filenames: false
files: ^scripts/vendor.py$
- id: check-integration-test-files
name: check integration test files
description: Ensure the integration test files are in sync

View file

@ -4,6 +4,9 @@ SHELL := bash
vendor:
python3 scripts/vendor.py
vendor-check:
python3 scripts/vendor.py --check
venv:
python3 -m venv venv
venv/bin/pip install -r requirements.txt
@ -11,6 +14,9 @@ venv:
lint: venv
venv/bin/pylint plugins
lint-docs:
venv/bin/antsibull-docs lint-collection-docs --plugin-docs .
clean:
git clean -xdf \
-e tests/integration/cloud-config-hcloud.ini

View file

@ -4,25 +4,27 @@ releases:
modules:
- description: Create and manage cloud Floating IPs on the Hetzner Cloud.
name: hcloud_floating_ip
namespace: ''
namespace: ""
- description: Create and manage cloud Load Balancers on the Hetzner Cloud.
name: hcloud_load_balancer
namespace: ''
- description: Manage the relationship between Hetzner Cloud Networks and Load
namespace: ""
- description:
Manage the relationship between Hetzner Cloud Networks and Load
Balancers
name: hcloud_load_balancer_network
namespace: ''
- description: Create and manage the services of cloud Load Balancers on the Hetzner
namespace: ""
- description:
Create and manage the services of cloud Load Balancers on the Hetzner
Cloud.
name: hcloud_load_balancer_service
namespace: ''
namespace: ""
- description: Manage Hetzner Cloud Load Balancer targets
name: hcloud_load_balancer_target
namespace: ''
namespace: ""
- description: Gather infos about the Hetzner Cloud Load Balancer types.
name: hcloud_load_balancer_type_info
namespace: ''
release_date: '2020-06-29'
namespace: ""
release_date: "2020-06-29"
0.2.0:
changes:
bugfixes:
@ -30,7 +32,7 @@ releases:
was removed by error within the migration from build-in ansible to our collection
fragments:
- inventory-allow-usage-of-pre-migration-configuration-fuiles.yml
release_date: '2020-06-30'
release_date: "2020-06-30"
1.0.0:
changes:
minor_changes:
@ -39,7 +41,7 @@ releases:
fragments:
- gh7-allow-enabling-of-backups-on-server-creation.yml
- lb-allow-change-type.yml
release_date: '2020-08-11'
release_date: "2020-08-11"
1.1.0:
changes:
bugfixes:
@ -53,7 +55,7 @@ releases:
fragments:
- fix-idempotency-floating-ip.yml
- gh-28-allow-setting-of-protection-on-creation.yml
release_date: '2020-10-05'
release_date: "2020-10-05"
1.10.0:
changes:
breaking_changes:
@ -75,7 +77,7 @@ releases:
- inventory-ipv6-adress-variable.yml
- inventory-private-network-info.yml
- server-private-networks-info.yml
release_date: '2023-02-01'
release_date: "2023-02-01"
1.10.1:
changes:
bugfixes:
@ -84,7 +86,7 @@ releases:
fragments:
- server-fix-backups.yml
- server-race-condition-pg-attach.yml
release_date: '2023-04-03'
release_date: "2023-04-03"
1.11.0:
changes:
minor_changes:
@ -96,7 +98,7 @@ releases:
- inventory plugin - Add cpu architecture to server variables.
fragments:
- arm-features.yaml
release_date: '2023-04-11'
release_date: "2023-04-11"
1.12.0:
changes:
breaking_changes:
@ -105,7 +107,7 @@ releases:
- hcloud_server_type_info - Add field included_traffic to returned server types
fragments:
- server-type-included-traffic.yml
release_date: '2023-05-16'
release_date: "2023-05-16"
1.13.0:
changes:
bugfixes:
@ -118,7 +120,7 @@ releases:
- create_primary_ip_info.yml
- server-type-deprecation.yml
- server_error_deprecated_image.yml
release_date: '2023-06-20'
release_date: "2023-06-20"
1.14.0:
changes:
minor_changes:
@ -126,7 +128,7 @@ releases:
- hcloud_network_info Return expose_routes_to_vswitch for network.
fragments:
- add-field-expose_routes_to_vswitch.yml
release_date: '2023-06-22'
release_date: "2023-06-22"
1.15.0:
changes:
bugfixes:
@ -139,31 +141,22 @@ releases:
fragments:
- add-hcloud_iso_info-module.yml
- fix-facts-modules-deprecation.yml
release_date: '2023-07-04'
release_date: "2023-07-04"
1.16.0:
changes:
minor_changes:
- Bundle hcloud python dependency inside the collection.
- 'python-dateutil >= 2.7.5 is now required by the collection. If you already
have the hcloud package installed, this dependency should also be installed.
'
- 'requests >= 2.20 is now required by the collection. If you already have the
hcloud package installed, this dependency should also be installed.
'
release_summary: 'This release bundles the hcloud dependency in the collection,
this allows us to ship
new features or bug fixes without having to release new major versions and
require the
users to upgrade their version of the hcloud dependency.
'
- "python-dateutil >= 2.7.5 is now required by the collection. If you already
have the hcloud package installed, this dependency should also be installed."
- "requests >= 2.20 is now required by the collection. If you already have the
hcloud package installed, this dependency should also be installed."
release_summary:
"This release bundles the hcloud dependency in the collection,
this allows us to ship new features or bug fixes without having to release new major versions and
require the users to upgrade their version of the hcloud dependency."
fragments:
- vendor-hcloud-python-dependency.yml
release_date: '2023-07-13'
release_date: "2023-07-13"
1.2.0:
changes:
minor_changes:
@ -175,13 +168,13 @@ releases:
modules:
- description: Gather infos about your Hetzner Cloud load_balancers.
name: hcloud_load_balancer_info
namespace: ''
release_date: '2020-12-01'
namespace: ""
release_date: "2020-12-01"
1.2.1:
changes:
bugfixes:
- Inventory Restore Python 2.7 compatibility
release_date: '2020-12-16'
release_date: "2020-12-16"
1.3.0:
changes:
minor_changes:
@ -189,8 +182,8 @@ releases:
modules:
- description: Manage Hetzner Cloud Firewalls
name: hcloud_firewall
namespace: ''
release_date: '2021-03-11'
namespace: ""
release_date: "2021-03-11"
1.3.1:
changes:
bugfixes:
@ -198,7 +191,7 @@ releases:
``state=stopped`` (https://github.com/ansible-collections/hetzner.hcloud/issues/54).
fragments:
- 64-hcloud_server_fix_checkmode_state_started.yml
release_date: '2021-03-18'
release_date: "2021-03-18"
1.4.0:
changes:
bugfixes:
@ -213,7 +206,7 @@ releases:
- 70-no_log_security_fixes.yml
- 71-hcloud_firewall_fix_idempotence.yml
- 73-hcloud_load_balancer_service_fix_wrong_import.yml
release_date: '2021-04-06'
release_date: "2021-04-06"
1.4.1:
changes:
minor_changes:
@ -223,7 +216,7 @@ releases:
- inventory - support jinjia templating within `token`
fragments:
- 74-hcloud_server-improve-error-message-images.yml
release_date: '2021-04-07'
release_date: "2021-04-07"
1.4.2:
changes:
bugfixes:
@ -231,7 +224,7 @@ releases:
type
fragments:
- inventory-fix-server-type-wrong-value.yml
release_date: '2021-04-14'
release_date: "2021-04-14"
1.4.3:
changes:
bugfixes:
@ -240,7 +233,7 @@ releases:
fragments:
- hcloud-server-py36.yaml
- hcloud-server-server-type.yaml
release_date: '2021-04-22'
release_date: "2021-04-22"
1.4.4:
changes:
bugfixes:
@ -250,7 +243,7 @@ releases:
fragments:
- hcloud_server-improve-error-message-on-not-existing-firewall.yml
- hcloud_volume-force-detach-before-deletion.yml
release_date: '2021-07-19'
release_date: "2021-07-19"
1.5.0:
changes:
bugfixes:
@ -265,21 +258,21 @@ releases:
- hcloud_placement_group.yml
- hcloud_rdns-improve-validation-of-input.yml
- hcloud_server_default-backups-to-none.yml
release_date: '2021-08-16'
release_date: "2021-08-16"
1.6.0:
changes:
minor_changes:
- hcloud_rdns Add support for load balancer
fragments:
- hcloud_rdns-add-support-for-load-balancers.yml
release_date: '2021-08-17'
release_date: "2021-08-17"
1.7.0:
changes:
minor_changes:
- inventory - support jinjia templating within `network`
fragments:
- inventory-network-templating.yml
release_date: '2022-06-09'
release_date: "2022-06-09"
1.7.1:
changes:
bugfixes:
@ -289,15 +282,15 @@ releases:
fragments:
- hcloud_server_network-alias-ips.yaml
- inventory-filter-by-status.yaml
release_date: '2022-06-13'
release_date: "2022-06-13"
1.8.0:
modules:
- description: Create and manage cloud Primary IPs on the Hetzner Cloud.
name: hcloud_primary_ip
namespace: hetzner.hcloud
release_date: '2022-06-29'
release_date: "2022-06-29"
1.8.1:
release_date: '2022-06-29'
release_date: "2022-06-29"
1.8.2:
changes:
bugfixes:
@ -308,7 +301,7 @@ releases:
fragments:
- flexible-networks-hcloud-server-info.yml
- inventory.yml
release_date: '2022-09-14'
release_date: "2022-09-14"
1.9.0:
changes:
bugfixes:
@ -331,7 +324,7 @@ releases:
- hcloud_inventory.yml
- hcloud_server_backup_window.yml
- hcloud_volume_server_none.yml
release_date: '2022-11-10'
release_date: "2022-11-10"
1.9.1:
changes:
bugfixes:
@ -339,35 +332,24 @@ releases:
were removed when not specified in the hcloud_server resource
fragments:
- hcloud_server-removed-networks.yml
release_date: '2022-12-20'
release_date: "2022-12-20"
2.0.0:
changes:
breaking_changes:
- Drop support for ansible-core 2.12
- Drop support for python 3.7
- 'inventory plugin - Don''t set the server image variables (`image_id`, `image_os_flavor`
and `image_name`) when the server image is not defined.
'
- "inventory plugin - Don't set the server image variables (`image_id`, `image_os_flavor`
and `image_name`) when the server image is not defined."
minor_changes:
- Bundle hcloud python dependency inside the collection.
- 'python-dateutil >= 2.7.5 is now required by the collection. If you already
have the hcloud package installed, this dependency should also be installed.
'
- 'requests >= 2.20 is now required by the collection. If you already have the
hcloud package installed, this dependency should also be installed.
'
release_summary: 'This release bundles the hcloud dependency in the collection,
this allows us to ship
new features or bug fixes without having to release new major versions and
require the
users to upgrade their version of the hcloud dependency.
'
- "python-dateutil >= 2.7.5 is now required by the collection. If you already
have the hcloud package installed, this dependency should also be installed."
- "requests >= 2.20 is now required by the collection. If you already have the
hcloud package installed, this dependency should also be installed."
release_summary:
"This release bundles the hcloud dependency in the collection,
this allows us to ship new features or bug fixes without having to release new major versions and
require the users to upgrade their version of the hcloud dependency."
removed_features:
- hcloud_datacenter_facts Removed deprecated facts module
- hcloud_floating_ip_facts Removed deprecated facts module
@ -383,11 +365,11 @@ releases:
- drop-support-for-python-3.7.yml
- remove-deprecated-facts-modules.yml
- vendor-hcloud-python-dependency.yml
release_date: '2023-07-24'
release_date: "2023-07-24"
2.1.0:
changes:
bugfixes:
- '`*_info` - Consistently fail on invalid ID in `*_info` modules.'
- "`*_info` - Consistently fail on invalid ID in `*_info` modules."
minor_changes:
- Use the collection version in the hcloud user-agent instead of the ansible-core
version.
@ -400,24 +382,22 @@ releases:
- consistently-fail-on-invalid-id.yml
- query-hcloud_floating_ip_info-by-name.yml
- use-collection-version-in-user-agent.yml
release_date: '2023-08-17'
release_date: "2023-08-17"
2.1.1:
changes:
bugfixes:
- hcloud_server - Fix string formatting error on deprecated server type warning
fragments:
- fix-string-formatting-error-on-deprecated-server-type-warning.yml
release_date: '2023-08-23'
release_date: "2023-08-23"
2.1.2:
changes:
bugfixes:
- hcloud_firewall - The port argument is required when the firewall rule protocol
is `udp` or `tcp`.
- 'hcloud_load_balancer_service - In the returned data, the invalid `health_check.http.certificates`
field was renamed to `health_check.http.status_codes`.
'
- "hcloud_load_balancer_service - In the returned data, the invalid `health_check.http.certificates`
field was renamed to `health_check.http.status_codes`."
fragments:
- rename-load-balancer-service-http-health-check-dict.yaml
- require-firewall-port-argument-on-tcp-or-udp-protocol.yaml
release_date: '2023-10-05'
release_date: "2023-10-05"

View file

@ -9,3 +9,4 @@ requests
# Development requirements
pylint
antsibull-docs>=2.5.0,<2.6

View file

@ -10,6 +10,7 @@ move the modified files at the vendor location `HCLOUD_VENDOR_PATH`.
import logging
import re
from argparse import ArgumentParser
from pathlib import Path
from shutil import move, rmtree
from subprocess import check_call
@ -80,7 +81,7 @@ def apply_code_modifications(source_path: Path):
file.write_text(content)
def main() -> int:
def main(check: bool = False) -> int:
with TemporaryDirectory() as tmp_dir:
tmp_dir_path = Path(tmp_dir)
logger.info("Created temporary directory %s", tmp_dir_path)
@ -95,9 +96,17 @@ def main() -> int:
move(tmp_dir_path / "hcloud", HCLOUD_VENDOR_PATH)
logger.info("Bundled the modified sources files in the collection")
if check:
check_call(["git", "diff", "--exit-code", "--", HCLOUD_VENDOR_PATH])
return 0
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(levelname)-8s: %(message)s")
raise SystemExit(main())
parser = ArgumentParser()
parser.add_argument("--check", action="store_true", default=False)
args = parser.parse_args()
raise SystemExit(main(check=args.check))