Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix: make releases immutable and gate main promotions

Juan Denis92e1862f32f6
diff --git a/.github/workflows/main-promotion.yml b/.github/workflows/main-promotion.yml
new file mode 100644
index 00000000..f95d013d
--- /dev/null
+++ b/.github/workflows/main-promotion.yml
@@ -0,0 +1,29 @@
+name: Main Promotion
+
+on:
+ pull_request:
+ branches: [main]
+ types: [opened, synchronize, reopened, ready_for_review]
+
+permissions:
+ contents: read
+
+jobs:
+ source-branch:
+ name: Require dev source
+ runs-on: ubuntu-latest
+ steps:
+ - name: Reject non-dev promotions
+ env:
+ BASE_BRANCH: ${{ github.base_ref }}
+ HEAD_BRANCH: ${{ github.head_ref }}
+ HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
+ REPOSITORY: ${{ github.repository }}
+ run: |
+ if [ "$BASE_BRANCH" != "main" ] \
+ || [ "$HEAD_BRANCH" != "dev" ] \
+ || [ "$HEAD_REPOSITORY" != "$REPOSITORY" ]; then
+ echo "::error::main only accepts pull requests from this repository's dev branch. Open feature work against dev first, then promote dev to main."
+ exit 1
+ fi
+ echo "Verified $HEAD_REPOSITORY:$HEAD_BRANCH → $BASE_BRANCH"
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index ef820aea..1317a7a5 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -23,13 +23,50 @@ concurrency:
permissions:
contents: write
+ pull-requests: read
env:
DOCKER_IMAGE: jhd3197/serverkit
jobs:
+ promotion-gate:
+ name: Verify dev promotion
+ runs-on: ubuntu-latest
+ steps:
+ - name: Require a merged dev to main pull request
+ uses: actions/github-script@v9
+ with:
+ script: |
+ if (context.eventName !== 'push' || context.ref !== 'refs/heads/main') {
+ core.info('Manual and tag-triggered releases do not use the branch promotion gate.');
+ return;
+ }
+
+ const { owner, repo } = context.repo;
+ const { data: pulls } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
+ owner,
+ repo,
+ commit_sha: context.sha,
+ });
+ const promotion = pulls.find((pull) => (
+ pull.merged_at
+ && pull.base.ref === 'main'
+ && pull.head.ref === 'dev'
+ && pull.head.repo?.full_name === `${owner}/${repo}`
+ ));
+
+ if (!promotion) {
+ core.setFailed(
+ 'Releases from main require a merged pull request from this repository\'s dev branch.'
+ );
+ return;
+ }
+
+ core.info(`Verified dev → main promotion via PR #${promotion.number}.`);
+
ci-gate:
name: CI Gate
+ needs: promotion-gate
uses: ./.github/workflows/backend-ci.yml
version:
@@ -60,18 +97,29 @@ jobs:
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Releasing ServerKit version: $VERSION"
+ - name: Require an unused release version
+ if: github.event_name != 'push' || github.ref_type != 'tag'
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ TAG: ${{ steps.version.outputs.tag }}
+ run: |
+ if git show-ref --verify --quiet "refs/tags/$TAG"; then
+ echo "::error::Refusing to overwrite existing tag $TAG. Bump VERSION before promoting dev to main."
+ exit 1
+ fi
+ if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
+ echo "::error::Refusing to overwrite existing release $TAG. Bump VERSION before promoting dev to main."
+ exit 1
+ fi
+
- name: Create and push tag
if: github.event_name == 'push' && github.ref_type != 'tag'
run: |
TAG="${{ steps.version.outputs.tag }}"
- if git rev-parse "$TAG" >/dev/null 2>&1; then
- echo "Tag $TAG already exists, skipping"
- else
- git config user.name "github-actions[bot]"
- git config user.email "github-actions[bot]@users.noreply.github.com"
- git tag -a "$TAG" -m "Release $TAG"
- git push origin "$TAG"
- fi
+ git config user.name "github-actions[bot]"
+ git config user.email "github-actions[bot]@users.noreply.github.com"
+ git tag -a "$TAG" -m "Release $TAG"
+ git push origin "refs/tags/$TAG"
build-release:
name: Build Release Tarball
@@ -211,12 +259,13 @@ jobs:
cat checksums.txt
- name: Create GitHub Release
- uses: softprops/action-gh-release@v2
+ uses: softprops/action-gh-release@v3
with:
tag_name: ${{ needs.version.outputs.tag }}
name: ServerKit ${{ needs.version.outputs.tag }}
draft: false
prerelease: ${{ github.event.inputs.prerelease == 'true' }}
+ overwrite_files: false
files: |
release/*
body: |
diff --git a/.github/workflows/scripts-ci.yml b/.github/workflows/scripts-ci.yml
index a0c1b1db..a46a27da 100644
--- a/.github/workflows/scripts-ci.yml
+++ b/.github/workflows/scripts-ci.yml
@@ -21,6 +21,8 @@ on:
- 'install.sh'
- 'uninstall.sh'
- 'serverkit'
+ - '.github/workflows/main-promotion.yml'
+ - '.github/workflows/release.yml'
- '.github/workflows/scripts-ci.yml'
pull_request:
branches: [main]
@@ -30,6 +32,8 @@ on:
- 'install.sh'
- 'uninstall.sh'
- 'serverkit'
+ - '.github/workflows/main-promotion.yml'
+ - '.github/workflows/release.yml'
- '.github/workflows/scripts-ci.yml'
workflow_call:
@@ -77,6 +81,7 @@ jobs:
bash scripts/test/test_cli.sh
bash scripts/test/test_agent_install.sh
bash scripts/test/test_stage.sh
+ bash scripts/test/test_release_workflow.sh
- name: nginx -t smoke (shipped vhosts parse on a real nginx)
run: |
@@ -188,6 +193,7 @@ jobs:
bash scripts/test/test_cli.sh
bash scripts/test/test_agent_install.sh
bash scripts/test/test_stage.sh
+ bash scripts/test/test_release_workflow.sh
'
python-provisioning:
diff --git a/scripts/test/test_release_workflow.sh b/scripts/test/test_release_workflow.sh
new file mode 100644
index 00000000..f3815ea1
--- /dev/null
+++ b/scripts/test/test_release_workflow.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+# Static regression guard for the feature -> dev -> main release path.
+
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
+RELEASE="$ROOT/.github/workflows/release.yml"
+PROMOTION="$ROOT/.github/workflows/main-promotion.yml"
+failures=0
+
+expect_text() {
+ file="$1"
+ text="$2"
+ label="$3"
+ if grep -Fq -- "$text" "$file"; then
+ printf 'ok %s\n' "$label"
+ else
+ printf 'FAIL %s\n' "$label" >&2
+ failures=$((failures + 1))
+ fi
+}
+
+expect_text "$PROMOTION" 'branches: [main]' \
+ 'main promotion runs on pull requests targeting main'
+expect_text "$PROMOTION" 'HEAD_BRANCH: ${{ github.head_ref }}' \
+ 'main promotion reads the pull request head branch safely'
+expect_text "$PROMOTION" '[ "$HEAD_BRANCH" != "dev" ]' \
+ 'main promotion rejects heads other than dev'
+expect_text "$PROMOTION" '[ "$HEAD_REPOSITORY" != "$REPOSITORY" ]' \
+ 'main promotion rejects a fork branch named dev'
+
+expect_text "$RELEASE" 'name: Verify dev promotion' \
+ 'release verifies the merged promotion'
+expect_text "$RELEASE" 'listPullRequestsAssociatedWithCommit' \
+ 'release resolves the pull request associated with the main commit'
+expect_text "$RELEASE" "pull.head.ref === 'dev'" \
+ 'release only accepts a merged dev head'
+expect_text "$RELEASE" 'name: Require an unused release version' \
+ 'release checks version immutability before tagging'
+expect_text "$RELEASE" 'Refusing to overwrite existing tag' \
+ 'release fails instead of reusing an existing tag'
+expect_text "$RELEASE" 'Refusing to overwrite existing release' \
+ 'release fails instead of reusing an existing release'
+expect_text "$RELEASE" 'overwrite_files: false' \
+ 'release assets cannot be overwritten'
+
+if [ "$failures" -ne 0 ]; then
+ printf '\n%d release workflow guard assertion(s) failed\n' "$failures" >&2
+ exit 1
+fi
+
+printf '\nrelease workflow guards are intact\n'