diff --git a/README.md b/README.md index d49f02e..b83f8a9 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ pipeline: source_name: myproject max_retries: 2 force_overwrite: true + debug: false ``` **Parameters:** @@ -58,6 +59,7 @@ pipeline: - **source_name:** Name of the source package to publish (optional, default: all `changes` files are will be publish) - **max_retries:** The number of retry in case of error calling the Aptly API (optional, default: no retry) - **force_overwrite:** When publishing, overwrite files in `pool/` directory without notice (optional, default: false) +- **debug:** Enable debug mode (optional, default: false) ## With Gitlab CI @@ -94,6 +96,7 @@ publish: APTLY_SOURCE_NAME: "myproject" APTLY_MAX_RETRIES: 2 APTLY_FORCE_OVERWRITE: true + APTLY_DEBUG: false script: - echo "Publish Bullseye debian packages on APT repository..." - aptly-publish @@ -154,6 +157,7 @@ jobs: source_name: myproject max_retries: 2 force_overwrite: true + debug: false ``` The parameters are passed using environment variables as designed with a Woodpecker CI plugin. Consequently, you could refer to the previous section for details about these parameters. For the password to request Aptly API, you have to set the `APTLY_API_PASSWORD` Actions secret in your Forgejo project configuration. diff --git a/aptly-publish b/aptly-publish index 85b19ba..39899b1 100755 --- a/aptly-publish +++ b/aptly-publish @@ -80,21 +80,30 @@ def get_published_distribution_other_components_sources(args, distribution): result.status_code, ) sys.exit(1) - for data in result.json(): - if data["Prefix"] != args.prefix: + data = result.json() + logging.debug( + "get_published_distribution_other_components_sources(%s): API return (%d): %s", + distribution, + result.status_code, + data, + ) + for publish in data: + if publish["Prefix"] != args.prefix: continue - if data["Distribution"] != distribution: + if publish["Distribution"] != distribution: continue - if data["SourceKind"] != "snapshot": + if publish["SourceKind"] != "snapshot": logging.error( "The distribution %s currently published on prefix '%s' do not sourcing packages " "from snapshot(s) but from %s.", distribution, args.prefix, - data["SourceKind"], + publish["SourceKind"], ) sys.exit(1) - return [source for source in data["Sources"] if source["Component"] != args.repo_component] + return [ + source for source in publish["Sources"] if source["Component"] != args.repo_component + ] logging.error( "Distribution %s seem not currently published on prefix '%s'. Please manually publish it " "a first time before using %s.", @@ -110,10 +119,11 @@ def upload_file(session, package_name, filepath): url = f"{args.api_url}/files/{package_name}" with open(filepath, "rb") as file_desc: result = session.post(url, files={"file": file_desc}) - return ( - result.status_code == 200 - and f"{package_name}/{os.path.basename(filepath)}" in result.json() + data = result.json() + logging.debug( + "upload_file(%s, %s): API return (%d): %s", package_name, filepath, result.status_code, data ) + return result.status_code == 200 and f"{package_name}/{os.path.basename(filepath)}" in data def include_changes_file(repo_name, package_name, changes_file): @@ -124,6 +134,14 @@ def include_changes_file(repo_name, package_name, changes_file): ) result = session.post(url) data = result.json() + logging.debug( + "include_changes_file(%s, %s, %s): API return (%d): %s", + repo_name, + package_name, + changes_file, + result.status_code, + data, + ) if data.get("FailedFiles"): logging.error( "Some error occurred including %s:\nFailed files:\n - %s\nWarnings: - %s", @@ -149,7 +167,11 @@ def include_deb_package(repo_name, package_name, path): data = result.json() logging.debug( "include_deb_package(%s, %s, %s): API return (%d): %s", - repo_name, package_name, path, result.status_code, data + repo_name, + package_name, + path, + result.status_code, + data, ) if data.get("FailedFiles"): logging.error( @@ -162,9 +184,7 @@ def include_deb_package(repo_name, package_name, path): ) return False if not (result.status_code == 200 and data.get("Report", {}).get("Added")): - logging.error( - "Unknown error occurred including %s. See APTLY API logs for details.", path - ) + logging.error("Unknown error occurred including %s. See APTLY API logs for details.", path) return False return True @@ -267,7 +287,21 @@ def publish_repo(args, session, distribution, repo_name, other_components_source result = session.post(url, json=payload) try: data = result.json() + logging.debug( + "publish_repo(%s, %s): API return (%d): %s", + distribution, + repo_name, + result.status_code, + data, + ) except ValueError: + logging.debug( + "publish_repo(%s, %s): API return (%d), fail to decode JSON result: '%s'", + distribution, + repo_name, + result.status_code, + result.text, + ) data = {} error = ( result.status_code < 200 @@ -339,7 +373,13 @@ parser.add_argument( action="store_true", default=from_env("FORCE_OVERWRITE", "false").lower() in ["1", "true", "yes", "on"], ) -parser.add_argument("-d", "--debug", action="store_true", help="Enable debug mode") +parser.add_argument( + "-d", + "--debug", + action="store_true", + help="Enable debug mode", + default=from_env("DEBUG", "false").lower() in ["1", "true", "yes", "on"], +) args = parser.parse_args()