diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e8cdf122b8518046c54845eeb2cd473d3c01cfef..7563fe3892fc6dd6ade77b775be5195bd6f13679 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,6 @@ include: ref: $CI_COMMIT_SHA file: 'templates/pypi-to-docker-missing-version.yml' inputs: - image_name: swepy/ruff - package_name: ruff + image-name: swepy/ruff + package-name: ruff stage: test diff --git a/CHANGELOG.md b/CHANGELOG.md index 2182b91bd104a060d706230eeee43c962bc33ad6..174bb42286aa6975eb4f6ee4526838c4297728c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,18 +17,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -* Variable `REPOSITORIES_API_URL` renamed `CONTAINER_REGISTRY_API_URL` +* Variable rename: + * `REPOSITORIES_API_URL` renamed `CONTAINER_REGISTRY_API_URL` + * `TAGS` renamed `TAG_EXCLUDE` ### Added * Support [inputs](https://docs.gitlab.com/ci/yaml/inputs/): * blocking: When no new version to publish, job fails, otherwise consider last release. - * container_registry_api_url: URL of the API to retrieve the container registry. - * image_name: Image name on Container Registry. Should be "<org|user>/<repo>". - * package_index_api_url: URL of the API to retrieve the package index. - * package_name: Name of the package on Package Registry. + * container-registry-api-url: URL of the API to retrieve the container registry. + * image-name: Image name on Container Registry. Should be "<org|user>/<repo>". + * package-index-api-url: URL of the API to retrieve the package index. + * package-name: Name of the package on Package Registry. * stage: Stage of the job. - * tags: Image Tags to consider as already built. Used to exclude specific versions. + * tag-exclude: Image Tags to consider as already built. Used to exclude specific versions. * Variable `BLOCKING` ## [0.4.1] - 2024-07-16 diff --git a/README.md b/README.md index ca2162c2541e58f3fec85cdbd964afecfe42f692..61acad911c0bd6de8aac3ac84bf9b3d449642040 100644 --- a/README.md +++ b/README.md @@ -21,29 +21,29 @@ include: ### Inputs -You can customize the job by overriding specific inputs. - -| Name | Description | Default | -|------------------------------|----------------------------------------------------------------------------------|---------------------------------------------------| -| `blocking` | When no new version to publish, job fails, otherwise consider last release. | `false` | -| `container_registry_api_url` | URL of the API to retrieve the container registry. | `https://registry.hub.docker.com/v2/repositories` | -| `image_name` | **Mandatory** Image name on Container Registry. Should be "<org\|user>/\<repo>". | `""` | -| `package_index_api_url` | URL of the API to retrieve the package index. | `https://pypi.org/pypi` | -| `package_name` | Name of the package on Package Registry. | `$CI_PROJECT_NAME` | -| `sort_cmd` | The command to sort the versions. | `sort -V` | -| `stage` | Stage of the job. | `build` | -| `tags` | Image tags to consider as already built. Used to exclude specific versions. | `""` | +You can customize the job through [inputs](https://docs.gitlab.com/ci/components/#use-a-component). + +| Name | Description | Default | +|------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------| +| `blocking` | When no new version to publish, job fails, otherwise consider last release. | `false` | +| `container_registry_api_url` | URL of the API to retrieve the container registry. | `https://registry.hub.docker.com/v2/repositories` | +| `image_name` | **Mandatory** Image name on Container Registry. https://regex101.com/r/f0jdQS/1 | `""` | +| `package_index_api_url` | URL of the API to retrieve the package index. | `https://pypi.org/pypi` | +| `package_name` | Name of the package on Package Registry. | `$CI_PROJECT_NAME` | +| `sort_cmd` | Command to sort versions. | `sort -V` | +| `stage` | Stage of the job. | `build` | +| `tag-exclude` | Image tags to consider as already built. Used to exclude specific versions. | `""` | ## Variables You can further customize the job by overriding the following variables: -| Name | Description | Default | -|------------------------------|----------------------------------------------------------------------------------|---------------------------------------------------| -| `BLOCKING` | When no new version to publish, job fails, otherwise consider last release. | `false` | -| `CONTAINER_REGISTRY_API_URL` | URL of the API to retrieve the container registry. | `https://registry.hub.docker.com/v2/repositories` | -| `IMAGE_NAME` | **Mandatory** Image name on Container Registry. Should be "<org\|user>/\<repo>". | `$[[ inputs.image_name ]]` | -| `PACKAGE_INDEX_API_URL` | URL of the API to retrieve the package index. | `$[[ inputs.package_index_api_url ]]` | -| `PACKAGE_NAME` | Name of the package on Package Registry. | `$[[ inputs.package_name ]]` | -| `SORT_CMD` | The command to sort the versions. | `sort -V` | -| `TAGS` | Image tags to consider as already built. Used to exclude specific versions. | `""` | +| Name | Description | Default | +|------------------------------|---------------------------------------------------------------------------------|--------------------------------------------| +| `BLOCKING` | When no new version to publish, job fails, otherwise consider last release. | `$[[ inputs.blocking ]]` | +| `CONTAINER_REGISTRY_API_URL` | URL of the API to retrieve the container registry. | `$[[ inputs.container-registry-api-url ]]` | +| `IMAGE_NAME` | **Mandatory** Image name on Container Registry. https://regex101.com/r/f0jdQS/1 | `$[[ inputs.image-name ]]` | +| `PACKAGE_INDEX_API_URL` | URL of the API to retrieve the package index. | `$[[ inputs.package-index-api-url ]]` | +| `PACKAGE_NAME` | Name of the package on Package Registry. | `$[[ inputs.package-name ]]` | +| `SORT_CMD` | The command to sort the versions. | `$[[ inputs.sort-cmd ]]` | +| `TAG_EXCLUDE` | Image tags to consider as already built. Used to exclude specific versions. | `$[[ inputs.tags ]]` | diff --git a/templates/pypi-to-docker-missing-version.yml b/templates/pypi-to-docker-missing-version.yml index 921aa1f8fdc91d590abf6c676647f2acf775b371..dd07d5f726a0eeecd0b5bcb8b13bbd01a3e3bdb8 100644 --- a/templates/pypi-to-docker-missing-version.yml +++ b/templates/pypi-to-docker-missing-version.yml @@ -4,21 +4,25 @@ spec: description: When no new version to publish, job fails, otherwise consider last release. type: boolean default: false - container_registry_api_url: + container-registry-api-url: description: URL of the API to retrieve the container registry. default: https://registry.hub.docker.com/v2/repositories - image_name: + image-name: description: Image name on Container Registry. Should be "<org|user>/<repo>". - package_index_api_url: + regex: ^(?<image>[a-z0-9.\-_]+(?:/[a-z0-9.\-_]+|))(:(?<tag>[\w.\-_]{1,127})|)$ + package-index-api-url: description: URL of the API to retrieve the package index. default: https://pypi.org/pypi - package_name: + package-name: description: Name of the package on Package Registry. default: $CI_PROJECT_NAME + sort-cmd: + description: Command to sort versions. + default: sort -V stage: description: Stage of the job. default: build - tags: + tag-exclude: description: Image Tags to consider as already built. Used to exclude specific versions. default: "" @@ -28,12 +32,12 @@ pypi-to-docker-missing-version: image: alpine:3.21.3 variables: BLOCKING: $[[ inputs.blocking ]] - CONTAINER_REGISTRY_API_URL: $[[ inputs.container_registry_api_url ]] - IMAGE_NAME: $[[ inputs.image_name ]] - PACKAGE_INDEX_API_URL: $[[ inputs.package_index_api_url ]] - PACKAGE_NAME: $[[ inputs.package_name ]] - SORT_CMD: sort -V - TAGS: $[[ inputs.tags ]] + CONTAINER_REGISTRY_API_URL: $[[ inputs.container-registry-api-url ]] + IMAGE_NAME: $[[ inputs.image-name ]] + PACKAGE_INDEX_API_URL: $[[ inputs.package-index-api-url ]] + PACKAGE_NAME: $[[ inputs.package-name ]] + SORT_CMD: $[[ inputs.sort-cmd ]] + TAG_EXCLUDE: $[[ inputs.tag-exclude ]] script: #!/bin/bash - apk update @@ -49,13 +53,13 @@ pypi-to-docker-missing-version: - if [ "$(echo "$docker_response" | jq -r '.results | length')" -eq 0 ]; then - break - fi - - TAGS="$TAGS $(echo "$docker_response" | jq -r '.results[].name')" + - TAG_EXCLUDE="$TAG_EXCLUDE $(echo "$docker_response" | jq -r '.results[].name')" - docker_url=$(echo "$docker_response" | jq -r '.next') - if [ "$docker_url" = "null" ]; then - docker_url="" - fi - done - - echo "tags on docker=$TAGS" + - echo "tags on docker=$TAG_EXCLUDE" # pypi - pypi_url="$PACKAGE_INDEX_API_URL/$PACKAGE_NAME/json" @@ -68,7 +72,7 @@ pypi-to-docker-missing-version: # find missing releases - missing_releases="" - - eval 'for release in $pypi_releases; do found=0; for tag in $TAGS; do if [ "$release" = "$tag" ]; then found=1; break; fi; done; if [ $found -eq 0 ]; then missing_releases="$missing_releases $release"; fi; done' + - eval 'for release in $pypi_releases; do found=0; for tag in $TAG_EXCLUDE; do if [ "$release" = "$tag" ]; then found=1; break; fi; done; if [ $found -eq 0 ]; then missing_releases="$missing_releases $release"; fi; done' - missing_releases=$(echo $missing_releases) - echo "missing tags=$missing_releases"