Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit d6429921 authored by Dorian Turba's avatar Dorian Turba
Browse files

Merge branch 'trunk' into 'main'

Bump version: 0.4.1 → 0.4.2

See merge request !1
parents 72e65387 2358c4e7
No related branches found
No related tags found
1 merge request!1Bump version: 0.4.1 → 0.4.2
Pipeline #63501 passed
[tool.bumpversion] [tool.bumpversion]
commit = true commit = true
current_version = "0.4.1" current_version = "0.4.2"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)" parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
replace = "{new_version}" replace = "{new_version}"
search = "{current_version}" search = "{current_version}"
......
include: include:
- project: 'swepy/cicd-templates/release-by-changelog' - component: $CI_SERVER_FQDN/swepy/cicd-templates/release-by-changelog/release-by-changelog@1.0.0
ref: '0.4.3'
file: 'templates/release-by-changelog.yml'
- project: 'swepy/cicd-templates/pypi-to-docker-missing-version' - project: 'swepy/cicd-templates/pypi-to-docker-missing-version'
ref: $CI_COMMIT_SHA ref: $CI_COMMIT_SHA
file: 'templates/pypi-to-docker-missing-version.yml' file: 'templates/pypi-to-docker-missing-version.yml'
inputs:
pypi-to-docker-missing-version: image-name: swepy/ruff
stage: test package-name: ruff
variables: stage: test
PACKAGE_NAME: ruff
IMAGE_NAME: swepy/ruff
...@@ -9,6 +9,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,6 +9,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/trunk/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=trunk) [![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/trunk/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=trunk)
## [0.4.2] - 2025-03-01
[![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/0.4.2/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=0.4.2)
* Update CICD
### Changed
* 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.
* stage: Stage of the job.
* tag-exclude: Image Tags to consider as already built. Used to exclude specific versions.
* Variable `BLOCKING`
## [0.4.1] - 2024-07-16 ## [0.4.1] - 2024-07-16
[![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/0.4.1/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=0.4.1) [![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/0.4.1/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=0.4.1)
......
# PyPI to Docker missing version # PyPI to Docker missing version
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/blob/main/LICENSE) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/blob/main/LICENSE)
[![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/0.4.1/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=0.4.1) [![Pipeline](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/badges/0.4.2/pipeline.svg)](https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/pipelines?ref=0.4.2)
## Objective ## Objective
...@@ -12,70 +12,38 @@ used for other jobs to build the image. ...@@ -12,70 +12,38 @@ used for other jobs to build the image.
## How to use it ## How to use it
### Include the component/template
Add the following to your `.gitlab-ci.yml` file. Add the following to your `.gitlab-ci.yml` file.
#### As a Local component
Recommended if the component is local to the instance:
```yaml ```yaml
include: include:
- component: $CI_SERVER_FQDN/swepy/cicd-templates/pypi-to-docker-missing-version/pypi-to-docker-missing-version@0.4.1 - component: $CI_SERVER_FQDN/swepy/cicd-templates/pypi-to-docker-missing-version/pypi-to-docker-missing-version@0.4.2
``` ```
If your GitLab instance version is lower than `16.10`, use `$CI_SERVER_HOST` instead ### Inputs
of `$CI_SERVER_FQDN`. Don't forget to add the port if necessary.
#### As a Remote template
Recommended if the template is not local to the instance: You can customize the job through [inputs](https://docs.gitlab.com/ci/components/#use-a-component).
##### Source: lab.frogg.it | Name | Description | Default |
|------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------|
```yaml | `blocking` | When no new version to publish, job fails, otherwise consider last release. | `false` |
include: | `container_registry_api_url` | URL of the API to retrieve the container registry. | `https://registry.hub.docker.com/v2/repositories` |
- remote: 'https://lab.frogg.it/swepy/cicd-templates/pypi-to-docker-missing-version/-/raw/0.4.1/templates/pypi-to-docker-missing-version.yml' | `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` |
##### Mirror: GitLab.com | `sort_cmd` | Command to sort versions. | `sort -V` |
| `stage` | Stage of the job. | `build` |
```yaml | `tag-exclude` | Image tags to consider as already built. Used to exclude specific versions. | `""` |
include:
- remote: 'https://gitlab.com/swepy/cicd-templates/pypi-to-docker-missing-version/-/raw/0.4.1/templates/pypi-to-docker-missing-version.yml'
```
#### As a Local template
If the template is local to the instance:
```yaml
include:
- project: 'swepy/cicd-templates/pypi-to-docker-missing-version'
ref: '0.4.1'
file: 'templates/pypi-to-docker-missing-version.yml'
```
### Customize job
You can customize the job by overriding specific keys. For example:
```yaml
pypi_to_docker_missing_version:
variables:
SORT_CMD: grep -E "^[0-9]+(\.[0-9]+)*$" | sort -t. -k1,1n -k2,2n -k3,3n
```
## Variables ## Variables
You can customize the job by overriding the following variables: You can further customize the job by overriding the following variables:
| Name | Description | Default | | Name | Description | Default |
|-------------------------|----------------------------------------------------------------------------------------|---------------------------------------------------| |------------------------------|---------------------------------------------------------------------------------|--------------------------------------------|
| `IMAGE_NAME` | **Mandatory** The name of the image. Should be "<org\|user>/\<repo>". | `""` | | `BLOCKING` | When no new version to publish, job fails, otherwise consider last release. | `$[[ inputs.blocking ]]` |
| `PACKAGE_INDEX_API_URL` | The URL of the API to retrieve the package index. | `https://pypi.org/pypi` | | `CONTAINER_REGISTRY_API_URL` | URL of the API to retrieve the container registry. | `$[[ inputs.container-registry-api-url ]]` |
| `PACKAGE_NAME` | The name of the package. | `"$CI_PROJECT_NAME"` | | `IMAGE_NAME` | **Mandatory** Image name on Container Registry. https://regex101.com/r/f0jdQS/1 | `$[[ inputs.image-name ]]` |
| `REPOSITORIES_API_URL` | The URL of the API to retrieve the repositories. | `https://registry.hub.docker.com/v2/repositories` | | `PACKAGE_INDEX_API_URL` | URL of the API to retrieve the package index. | `$[[ inputs.package-index-api-url ]]` |
| `SORT_CMD` | The command to sort the versions. | `sort -V` | | `PACKAGE_NAME` | Name of the package on Package Registry. | `$[[ inputs.package-name ]]` |
| `TAGS` | The tags of the image to consider as already built. Used to exclude specific versions. | `""` | | `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 ]]` |
spec:
inputs:
blocking:
description: When no new version to publish, job fails, otherwise consider last release.
type: boolean
default: false
container-registry-api-url:
description: URL of the API to retrieve the container registry.
default: https://registry.hub.docker.com/v2/repositories
image-name:
description: Image name on Container Registry. Should be "<org|user>/<repo>".
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:
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
tag-exclude:
description: Image Tags to consider as already built. Used to exclude specific versions.
default: ""
---
pypi-to-docker-missing-version: pypi-to-docker-missing-version:
stage: build stage: $[[ inputs.stage ]]
image: alpine:3.20.1 image: alpine:3.21.3
variables: variables:
IMAGE_NAME: "" BLOCKING: $[[ inputs.blocking ]]
PACKAGE_INDEX_API_URL: https://pypi.org/pypi CONTAINER_REGISTRY_API_URL: $[[ inputs.container-registry-api-url ]]
PACKAGE_NAME: $CI_PROJECT_NAME IMAGE_NAME: $[[ inputs.image-name ]]
REPOSITORIES_API_URL: https://registry.hub.docker.com/v2/repositories PACKAGE_INDEX_API_URL: $[[ inputs.package-index-api-url ]]
SORT_CMD: sort -V PACKAGE_NAME: $[[ inputs.package-name ]]
TAGS: "" SORT_CMD: $[[ inputs.sort-cmd ]]
script: TAG_EXCLUDE: $[[ inputs.tag-exclude ]]
#!/bin/bash script:
- apk update #!/bin/bash
- apk add --no-cache curl jq - apk update
- apk add --no-cache curl jq
# get docker tags # get docker tags
- echo "Image name=$IMAGE_NAME" - echo "Image name=$IMAGE_NAME"
- docker_url="$REPOSITORIES_API_URL/$IMAGE_NAME/tags" - docker_url="$CONTAINER_REGISTRY_API_URL/$IMAGE_NAME/tags"
# get all tags # get all tags
- while [ -n "$docker_url" ]; do - while [ -n "$docker_url" ]; do
- docker_response=$(curl -s "$docker_url") - docker_response=$(curl -s "$docker_url")
- if [ "$(echo "$docker_response" | jq -r '.results | length')" -eq 0 ]; then - if [ "$(echo "$docker_response" | jq -r '.results | length')" -eq 0 ]; then
- break - break
- fi - 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') - docker_url=$(echo "$docker_response" | jq -r '.next')
- if [ "$docker_url" = "null" ]; then - if [ "$docker_url" = "null" ]; then
- docker_url="" - docker_url=""
- fi - fi
- done - done
- echo "tags on docker=$TAGS" - echo "tags on docker=$TAG_EXCLUDE"
# pypi # pypi
- pypi_url="$PACKAGE_INDEX_API_URL/$PACKAGE_NAME/json" - pypi_url="$PACKAGE_INDEX_API_URL/$PACKAGE_NAME/json"
- pypi_response=$(curl -s "$pypi_url") - pypi_response=$(curl -s "$pypi_url")
- releases=$(echo "$pypi_response" | jq -r '.releases | keys[]') - pypi_releases=$(echo "$pypi_response" | jq -r '.releases | keys[]')
- pypi_releases=$(printf "%s\n" $pypi_releases | $SORT_CMD)
- echo "releases on pypi:" - echo "releases on pypi:"
- printf "%s " $releases - printf "%s " $pypi_releases
# find missing releases # find missing releases
- missing_releases="" - missing_releases=""
- eval 'for release in $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) - missing_releases=$(echo $missing_releases)
- echo "missing tags=$missing_releases" - echo "missing tags=$missing_releases"
- sorted_releases=$(printf "%s\n" $missing_releases | $SORT_CMD) - sorted_releases=$(printf "%s\n" $missing_releases | $SORT_CMD)
# print the sorted versions # print the sorted versions
- echo "Sorted releases:" - echo "Sorted releases:"
- printf "%s " $sorted_releases - printf "%s " $sorted_releases
- version_to_publish=$(echo $sorted_releases | awk '{print $1}') - version_to_publish=$(echo $sorted_releases | awk '{print $1}')
- 'echo "Version to publish: $version_to_publish"' - 'echo "Version to publish: $version_to_publish"'
- if [ -n "$version_to_publish" ]; then - if [ -n "$version_to_publish" ]; then
- echo "Version to publish=$version_to_publish" - echo "Version to publish=$version_to_publish"
- else - elif [ "$BLOCKING" = true ]; then
- version_to_publish=$(echo $releases | awk '{print $NF}') - printf "Nothing to publish, stop here\n"
- echo "Version to publish=$version_to_publish" - exit 1
- fi - else
- printf "No new publication, publish last"
- version_to_publish=$(echo $pypi_releases | awk '{print $NF}')
- echo "Version to publish=$version_to_publish"
- fi
- echo "$version_to_publish" > version.txt - echo "$version_to_publish" > version.txt
- cat version.txt - cat version.txt
artifacts: artifacts:
name: "version" name: "version"
paths: paths:
- version.txt - version.txt
expire_in: 1 day expire_in: 1 day
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment