@@ -497,30 +497,62 @@ upload:tag-version:
497
497
extends :
498
498
- .upload
499
499
script :
500
+ # Print key environment variables for debugging
501
+ - echo "CI_API_V4_URL=${CI_API_V4_URL}"
502
+ - echo "CI_PROJECT_ID=${CI_PROJECT_ID}"
503
+ - echo "CI_COMMIT_SHA=${CI_COMMIT_SHA}"
504
+ - echo "ADD_RELEASES_TOKEN is ${ADD_RELEASES_TOKEN:+set}"
505
+
506
+ # Check if token can access the project
507
+ - |
508
+ STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
509
+ --header "PRIVATE-TOKEN: ${ADD_RELEASES_TOKEN}" \
510
+ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}")
511
+ if [ "$STATUS" != "200" ]; then
512
+ echo "Token cannot access project (HTTP $STATUS)"
513
+ exit 1
514
+ else
515
+ echo "Token access verified"
516
+ fi
517
+
500
518
# Find the latest version tag in the git log (ignore failure since we handle it inside this script)
501
519
- latest_version_tag=$(git describe --tags --match "v*" --abbrev=0 2>/dev/null) || true
502
- # If no version tags are found, start with v0.0.0
503
- # Else get the version number from the latest version tag
504
520
- |
505
- if [ -z "$latest_version_tag" ]; then
506
- latest_version="0.0.0"
507
- else
508
- latest_version=$(echo "$latest_version_tag" | tail -c +2)
509
- fi
510
- - echo "New version tag is ${new_version}"
521
+ if [ -z "$latest_version_tag" ]; then
522
+ latest_version="0.0.0"
523
+ else
524
+ latest_version=$(echo "$latest_version_tag" | tail -c +2)
525
+ fi
526
+ - echo "Latest version tag=${latest_version_tag:-none}"
527
+ - echo "Parsed latest version number=${latest_version}"
528
+
529
+ # Check if HEAD is already tagged
511
530
- |
512
- if git tag --points-at HEAD | grep -q "v[0-9]\+\.[0-9]\+\.[0-9]\+"; then
513
- echo "Latest commit already has a version tag '$latest_version_tag'"
514
- echo "TAG=${latest_version_tag}" >> variables.env
515
- else
516
- echo "Bump patch number"
517
- patch=$(echo "$latest_version" | awk -F. '{print $3}')
518
- ((new_patch = patch + 1))
519
- new_version=$(printf "v%s.%s.%s" "$(echo "$latest_version" | head -c 1)" "$(echo "$latest_version" | cut -d "." -f 2)" "$new_patch")
520
- echo "TAG=${new_version}" >> variables.env
521
- echo "Push new tag '$new_version' to git."
522
- curl --fail --header "PRIVATE-TOKEN: ${ADD_RELEASES_TOKEN}" --request POST "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/tags?tag_name=${new_version}&ref=${CI_COMMIT_SHA}"
523
- fi
531
+ if git tag --points-at HEAD | grep -q "v[0-9]\+\.[0-9]\+\.[0-9]\+"; then
532
+ echo "HEAD already tagged with '${latest_version_tag}'"
533
+ echo "TAG=${latest_version_tag}" >> variables.env
534
+ else
535
+ echo "HEAD not tagged yet. Bumping patch version..."
536
+ patch=$(echo "$latest_version" | awk -F. '{print $3}')
537
+ ((new_patch = patch + 1))
538
+ new_version=$(printf "v%s.%s.%s" "$(echo "$latest_version" | cut -d "." -f 1)" "$(echo "$latest_version" | cut -d "." -f 2)" "$new_patch")
539
+ echo "New version to create=${new_version}"
540
+ echo "TAG=${new_version}" >> variables.env
541
+
542
+ # Print curl debug info
543
+ echo "POST ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/tags"
544
+ echo "tag_name=${new_version}"
545
+ echo "ref=${CI_COMMIT_SHA}"
546
+
547
+ # Upload new tag
548
+ curl --fail -v \
549
+ --header "Content-Type: application/json" \
550
+ --header "PRIVATE-TOKEN: ${ADD_RELEASES_TOKEN}" \
551
+ --request POST \
552
+ --data "{\"tag_name\": \"${new_version}\", \"ref\": \"${CI_COMMIT_SHA}\"}" \
553
+ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/repository/tags"
554
+ fi
555
+ dependencies : []
524
556
artifacts :
525
557
reports :
526
558
dotenv : variables.env
0 commit comments