Skip to content
Source
Sign inSign up

Protect release tags

CI / Rules

Protect release tags

Every person with write access can push a tag. So a person can move v1.2.0 to another commit, or delete it, and the tag no longer points to what you released. A tag rule protects the tags that match a pattern, like v*. Only an admin, or a CI job of a protected run, can then create, move or delete them.

2 min read

You need admin access to the repository.

1. Add a tag rule

  1. Open the repository, then Settings, then Branches under Code (/@<owner>/<repo>/settings/branches).
  2. Under Tag rules, enter a Tag name pattern, like v*.
  3. Click Add rule.

With the src CLI:

src ci tag-rule set 'v*'

Over REST, with the pattern URL-encoded:

curl -X PUT "$TSS_FORGE_URL/repos/acme/app/tag-rules/v%2A" \
  -H "Authorization: Bearer $TSS_TOKEN"

Over MCP, call the tool set_tag_rule with pattern.

  • A pattern is a tag name or a glob, without refs/tags/. It cannot start with !.
  • A repository has at most 100 tag rules.

2. Tag your releases from CI

Push the tag from a job that runs after a merge into main. Give the job the permission to push tags:

import { defineWorkflow, push } from '@tanstack-source/ci'

export default defineWorkflow('release', { on: [push({ branches: ['main'] })] })
  .job('tag', {
    permissions: { push: ['tags'] },
    steps: [{ name: 'Tag the version', run: './scripts/tag-release.sh' }],
  })
#!/bin/sh
# scripts/tag-release.sh
set -e
version="v$(node -p "require('./package.json').version")"
git tag "$version"
git push origin "$version"
  • The run must be protected. A push to main gives a protected run only when the branch rule of main requires a pull request.
  • A trusted run cannot push the tag. See Trust levels.

3. See a refused push

Push a protected tag as a person who is not an admin:

git tag v1.0.0
git push origin v1.0.0
 ! [remote rejected] v1.0.0 -> v1.0.0 (tag rule "v*" protects v1.0.0: only an admin or a protected CI run may create, move or delete it)

A move with --force and a delete with git push origin :v1.0.0 get the same answer.

Done

The tags that match v* change only through an admin or your release job. Every other push of them is refused.

Who can change a protected tag

  • An admin of the repository.
  • A job of a protected run, when its push permission has 'tags'.

Nobody else can: a person with write access, a trusted run and an agent all get the refusal.

List and delete tag rules

src ci tag-rule list
src ci tag-rule list --json
src ci tag-rule delete 'v*'
  • Over REST: GET /repos/{owner}/{repo}/tag-rules and DELETE /repos/{owner}/{repo}/tag-rules/{pattern}.
  • Over MCP: the tools list_tag_rules and delete_tag_rule.
  • Everyone who can read the repository can list the tag rules. Only admins add and delete them.
  • On the web, click Delete beside a rule under Tag rules.