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