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 13631d46 authored by Dorian Turba's avatar Dorian Turba
Browse files

move to specs

parent 7ebaef89
No related branches found
No related tags found
No related merge requests found
spec:
inputs:
stage:
description: The stage of the job.
default: deploy
changelog file path:
description: The path to the CHANGELOG.md file.
default: CHANGELOG.md
prefix:
description: Value to prepend to the tag and release name.
default: ''
suffix:
description: Value to append to the tag and release name.
default: ''
---
release_by_changelog:
variables:
CHANGELOG_FILEPATH: CHANGELOG.md
PREFIX: ''
SUFFIX: ''
TAG_PREFIX: $PREFIX
TAG_SUFFIX: $SUFFIX
NAME_PREFIX: $PREFIX
NAME_SUFFIX: $SUFFIX
image: registry.gitlab.com/gitlab-org/release-cli:v0.18.0
stage: deploy
script:
# Use grep to find version headers and store them in a variable
- 'headers=$(grep -nE "^## \[([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?\] - [0-9]{4}-[0-9]{2}-[0-9]{2}$" "$CHANGELOG_FILEPATH")'
variables:
CHANGELOG_FILEPATH: $[[ inputs.changelog file path ]]
PREFIX: $[[ inputs.prefix ]]
SUFFIX: $[[ inputs.suffix ]]
TAG_PREFIX: $PREFIX
TAG_SUFFIX: $SUFFIX
NAME_PREFIX: $PREFIX
NAME_SUFFIX: $SUFFIX
image: registry.gitlab.com/gitlab-org/release-cli:v0.18.0
stage: $[[ inputs.stage ]]
script:
# Use grep to find version headers and store them in a variable
- 'headers=$(grep -nE "^## \[([0-9]+)\.([0-9]+)\.([0-9]+)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?\] - [0-9]{4}-[0-9]{2}-[0-9]{2}$" "$CHANGELOG_FILEPATH")'
# Extract first header line number
- 'first_line=$(echo "$headers" | head -1 | cut -d: -f1)'
# Extract first header line number
- 'first_line=$(echo "$headers" | head -1 | cut -d: -f1)'
# Check if we have a header, else exit
- if [ -z "$first_line" ]; then
- echo "No version headers found."
- exit 1
- fi
# Check if we have a header, else exit
- if [ -z "$first_line" ]; then
- echo "No version headers found."
- exit 1
- fi
# Extract version and date from the first header
- version=$(echo "$headers" | head -1 | grep -oE "\[([0-9]+)\.([0-9]+)\.([0-9]+)\]" | tr -d "[]")
- date=$(echo "$headers" | head -1 | grep -oE "[0-9]{4}-[0-9]{2}-[0-9]{2}")
# If date is different from today, format it
- if [ "$date" != "$(date +%Y-%m-%d)" ]; then
- formatted_date=$(date -u -d "$date" +"%Y-%m-%dT%H:%M:%SZ")
- fi
# Extract version and date from the first header
- version=$(echo "$headers" | head -1 | grep -oE "\[([0-9]+)\.([0-9]+)\.([0-9]+)\]" | tr -d "[]")
- date=$(echo "$headers" | head -1 | grep -oE "[0-9]{4}-[0-9]{2}-[0-9]{2}")
# If date is different from today, format it
- if [ "$date" != "$(date +%Y-%m-%d)" ]; then
- formatted_date=$(date -u -d "$date" +"%Y-%m-%dT%H:%M:%SZ")
- fi
# Extract second header line number for end of text range
- 'second_line=$(echo "$headers" | sed -n "2p" | cut -d: -f1)'
# Extract second header line number for end of text range
- 'second_line=$(echo "$headers" | sed -n "2p" | cut -d: -f1)'
# Determine end line
- if [ -n "$second_line" ]; then
- end_line=$((second_line - 1))
- else
# If there's no second header, use the end of the file
- end_line=$(wc -l < "$CHANGELOG_FILEPATH")
- fi
# Determine end line
- if [ -n "$second_line" ]; then
- end_line=$((second_line - 1))
- else
# If there's no second header, use the end of the file
- end_line=$(wc -l < "$CHANGELOG_FILEPATH")
- fi
- start_line=$((first_line + 2))
- if [ "$start_line" -le "$end_line" ]; then
# Use sed to extract the text between the first and the potential second version header
- text=$(sed -n "$start_line,$end_line p" "$CHANGELOG_FILEPATH")
- echo "Text = $text"
- else
- echo "No text to extract, start line exceeds end line."
- fi
- start_line=$((first_line + 2))
- if [ "$start_line" -le "$end_line" ]; then
# Use sed to extract the text between the first and the potential second version header
- text=$(sed -n "$start_line,$end_line p" "$CHANGELOG_FILEPATH")
- echo "Text = $text"
- else
- echo "No text to extract, start line exceeds end line."
- fi
# Output the results
- echo "Version = $version"
- echo "Date = $date"
- echo "Formatted Date = $formatted_date"
- echo "Text:"
- echo "$text"
# Output the results
- echo "Version = $version"
- echo "Date = $date"
- echo "Formatted Date = $formatted_date"
- echo "Text:"
- echo "$text"
# Set the tag and name
- tag="$TAG_PREFIX$version$TAG_SUFFIX"
- name="$NAME_PREFIX$version$NAME_SUFFIX"
# Set the tag and name
- tag="$TAG_PREFIX$version$TAG_SUFFIX"
- name="$NAME_PREFIX$version$NAME_SUFFIX"
# Create the release
- release-cli create --name "$name" --tag-name "$tag" --description "$text" --released-at "$formatted_date"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Create the release
- release-cli create --name "$name" --tag-name "$tag" --description "$text" --released-at "$formatted_date"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
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