Stop moving protected release tags during version bump.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -0,0 +1,4 @@
1
version.env
2
package.env
3
.gradle/
4
build/
@@ -0,0 +1,4 @@1
version.env2
package.env3
.gradle/4
build/@@ -7,7 +7,7 @@
7
7
#
8
8
# Flow:
9
9
# 1. validate — reject invalid or non-increasing versions
10
# 2. bump — update version in project files, push, retarget tag (ci.skip)
10
# 2. bump — update version in project files and push commit (ci.skip; tag unchanged)
11
11
# 3. build — produce ContainerPipes-<version>.jar and upload to Package Registry
12
12
# 4. release — publish a GitLab Release with the jar attached
13
13
# 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable
@@ -7,7 +7,7 @@7
#7
#8
# Flow:8
# Flow:9
# 1. validate — reject invalid or non-increasing versions9
# 1. validate — reject invalid or non-increasing versions10
# 2. bump — update version in project files, push, retarget tag (ci.skip)10
# 2. bump — update version in project files and push commit (ci.skip; tag unchanged)11
# 3. build — produce ContainerPipes-<version>.jar and upload to Package Registry11
# 3. build — produce ContainerPipes-<version>.jar and upload to Package Registry12
# 4. release — publish a GitLab Release with the jar attached12
# 4. release — publish a GitLab Release with the jar attached13
# 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable13
# 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable@@ -89,18 +89,46 @@ bump_files() {
89
89
echo "Updated project files to version ${version}"
90
90
}
91
91
92
require_push_token() {
93
if [[ -n "${CI_PUSH_TOKEN:-}" ]]; then
94
return 0
95
fi
96
97
cat <<'EOF' >&2
98
ERROR: CI_PUSH_TOKEN is not available in this job.
99
100
The variable may exist in Settings → CI/CD → Variables but still be hidden here if:
101
1. It is Protected, while this tag/branch is not protected
102
→ Protect tag pattern (e.g. *) or uncheck Protected on the variable
103
2. Its Environment scope is not "*"
104
3. The key is misspelled (must be exactly CI_PUSH_TOKEN)
105
106
EOF
107
exit 1
108
}
109
92
110
bump_and_push() {
93
111
local version="${1:?version required}"
94
112
local tag="${2:?tag required}"
95
local token="${CI_PUSH_TOKEN:?Set CI/CD variable CI_PUSH_TOKEN (Project Access Token with write_repository)}"
96
local branch="${CI_DEFAULT_BRANCH:?CI_DEFAULT_BRANCH is required}"
113
local token branch
114
115
require_push_token
116
token="${CI_PUSH_TOKEN}"
117
branch="${CI_DEFAULT_BRANCH:?CI_DEFAULT_BRANCH is required}"
97
118
98
119
git config user.email "gitlab-ci@${CI_SERVER_HOST:-gitlab.com}"
99
120
git config user.name "GitLab CI"
100
121
101
122
bump_files "$version"
102
123
103
git add -A
124
# Stage only versioned project files (never CI artifacts like version.env).
125
git add -- \
126
build.gradle.kts \
127
src/main/resources/plugin.yml \
128
README.md \
129
src/main/java/nl/timfalken/containerpipes/ContainerPipesPlugin.java
130
git add -A -- src/README-*.md 2>/dev/null || true
131
104
132
if git diff --cached --quiet; then
105
133
echo "No version file changes to commit (already at ${version})."
106
134
else
@@ -109,12 +137,10 @@ bump_and_push() {
109
137
110
138
git remote set-url origin "https://oauth2:${token}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
111
139
112
# Push commit and retarget the release tag without starting a new pipeline.
140
# Push version bump only. Protected tags cannot be moved/updated.
113
141
git push origin "HEAD:refs/heads/${branch}" -o ci.skip
114
git tag -f "$tag"
115
git push origin "refs/tags/${tag}" --force -o ci.skip
116
142
117
echo "Pushed version bump to ${branch} and moved tag ${tag} (ci.skip)."
143
echo "Pushed version bump for ${tag} to ${branch} (ci.skip). Tag left unchanged."
118
144
}
119
145
120
146
upload_package() {
@@ -141,8 +167,10 @@ upload_package() {
141
167
# Requires scopes: write_repository + self_rotate (or api), and api to update variables.
142
168
# Project access token role should be Maintainer (needed to edit CI/CD variables).
143
169
rotate_push_token() {
144
local old_token="${CI_PUSH_TOKEN:?Set CI/CD variable CI_PUSH_TOKEN}"
145
local expires_at response new_token var_meta protected masked raw scope
170
local old_token expires_at response new_token var_meta protected masked raw scope
171
172
require_push_token
173
old_token="${CI_PUSH_TOKEN}"
146
174
147
175
expires_at="$(date -u -d '+365 days' +%Y-%m-%d)"
148
176
echo "Rotating CI_PUSH_TOKEN (new expiry ${expires_at})..."
@@ -89,18 +89,46 @@ bump_files() {89
echo "Updated project files to version ${version}"89
echo "Updated project files to version ${version}"90
}90
}91
91
92
require_push_token() {93
if [[ -n "${CI_PUSH_TOKEN:-}" ]]; then94
return 095
fi96
97
cat <<'EOF' >&298
ERROR: CI_PUSH_TOKEN is not available in this job.99
100
The variable may exist in Settings → CI/CD → Variables but still be hidden here if:101
1. It is Protected, while this tag/branch is not protected102
→ Protect tag pattern (e.g. *) or uncheck Protected on the variable103
2. Its Environment scope is not "*"104
3. The key is misspelled (must be exactly CI_PUSH_TOKEN)105
106
EOF107
exit 1108
}109
92
bump_and_push() {110
bump_and_push() {93
local version="${1:?version required}"111
local version="${1:?version required}"94
local tag="${2:?tag required}"112
local tag="${2:?tag required}"95
local token="${CI_PUSH_TOKEN:?Set CI/CD variable CI_PUSH_TOKEN (Project Access Token with write_repository)}"113
local token branch96
local branch="${CI_DEFAULT_BRANCH:?CI_DEFAULT_BRANCH is required}"114
115
require_push_token116
token="${CI_PUSH_TOKEN}"117
branch="${CI_DEFAULT_BRANCH:?CI_DEFAULT_BRANCH is required}"97
118
98
git config user.email "gitlab-ci@${CI_SERVER_HOST:-gitlab.com}"119
git config user.email "gitlab-ci@${CI_SERVER_HOST:-gitlab.com}"99
git config user.name "GitLab CI"120
git config user.name "GitLab CI"100
121
101
bump_files "$version"122
bump_files "$version"102
123
103
git add -A124
# Stage only versioned project files (never CI artifacts like version.env).125
git add -- \126
build.gradle.kts \127
src/main/resources/plugin.yml \128
README.md \129
src/main/java/nl/timfalken/containerpipes/ContainerPipesPlugin.java130
git add -A -- src/README-*.md 2>/dev/null || true131
104
if git diff --cached --quiet; then132
if git diff --cached --quiet; then105
echo "No version file changes to commit (already at ${version})."133
echo "No version file changes to commit (already at ${version})."106
else134
else@@ -109,12 +137,10 @@ bump_and_push() {109
137
110
git remote set-url origin "https://oauth2:${token}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"138
git remote set-url origin "https://oauth2:${token}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"111
139
112
# Push commit and retarget the release tag without starting a new pipeline.140
# Push version bump only. Protected tags cannot be moved/updated.113
git push origin "HEAD:refs/heads/${branch}" -o ci.skip141
git push origin "HEAD:refs/heads/${branch}" -o ci.skip114
git tag -f "$tag"115
git push origin "refs/tags/${tag}" --force -o ci.skip116
142
117
echo "Pushed version bump to ${branch} and moved tag ${tag} (ci.skip)."143
echo "Pushed version bump for ${tag} to ${branch} (ci.skip). Tag left unchanged."118
}144
}119
145
120
upload_package() {146
upload_package() {@@ -141,8 +167,10 @@ upload_package() {141
# Requires scopes: write_repository + self_rotate (or api), and api to update variables.167
# Requires scopes: write_repository + self_rotate (or api), and api to update variables.142
# Project access token role should be Maintainer (needed to edit CI/CD variables).168
# Project access token role should be Maintainer (needed to edit CI/CD variables).143
rotate_push_token() {169
rotate_push_token() {144
local old_token="${CI_PUSH_TOKEN:?Set CI/CD variable CI_PUSH_TOKEN}"170
local old_token expires_at response new_token var_meta protected masked raw scope145
local expires_at response new_token var_meta protected masked raw scope171
172
require_push_token173
old_token="${CI_PUSH_TOKEN}"146
174
147
expires_at="$(date -u -d '+365 days' +%Y-%m-%d)"175
expires_at="$(date -u -d '+365 days' +%Y-%m-%d)"148
echo "Rotating CI_PUSH_TOKEN (new expiry ${expires_at})..."176
echo "Rotating CI_PUSH_TOKEN (new expiry ${expires_at})..."@@ -1,2 +0,0 @@
1
VERSION=1.7.0
2
TAG=1.7.0
@@ -1,2 +0,0 @@1
VERSION=1.7.02
TAG=1.7.0