Skip to content

Commit baca2c0

Browse files
authored
chore(release): prevent for pushing to personal forks (#115)
* chore(release): prevent for pushing to personal forks * fix: quote * chore: actually validate in the release script * docs: wording and headings
1 parent 8fefce3 commit baca2c0

3 files changed

Lines changed: 48 additions & 7 deletions

File tree

.github/scripts/common.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ readonly CURRENT_DIR="$(get_script_dir)"
3939
readonly ROOT_DIR="$(dirname $(dirname "${CURRENT_DIR}"))"
4040
readonly BUILD_DIR="${ROOT_DIR}/.github/scripts/.build"
4141
readonly GITHUB_REPO="github.com/docker/go-sdk"
42+
readonly EXPECTED_ORIGIN_SSH="git@github.com:docker/go-sdk.git"
43+
readonly EXPECTED_ORIGIN_HTTPS="https://${GITHUB_REPO}.git"
4244
readonly DRY_RUN="${DRY_RUN:-true}"
4345

4446
# This function is used to trigger the Go proxy to fetch the module.
@@ -67,6 +69,34 @@ execute_or_echo() {
6769
fi
6870
}
6971

72+
# Validate that git remote origin points to the correct repository
73+
# This prevents accidentally pushing to the wrong remote
74+
validate_git_remote() {
75+
local actual_origin="$(git -C "${ROOT_DIR}" remote get-url origin 2>/dev/null || echo "")"
76+
77+
if [[ -z "$actual_origin" ]]; then
78+
echo "❌ Error: No 'origin' remote found"
79+
echo "Please configure the origin remote first:"
80+
echo " git remote add origin ${EXPECTED_ORIGIN_SSH}"
81+
exit 1
82+
fi
83+
84+
# Accept both SSH and HTTPS formats for the docker/go-sdk repository
85+
if [[ "$actual_origin" != "$EXPECTED_ORIGIN_SSH" ]] && \
86+
[[ "$actual_origin" != "$EXPECTED_ORIGIN_HTTPS" ]]; then
87+
echo "❌ Error: Git remote 'origin' points to the wrong repository"
88+
echo " Expected: ${EXPECTED_ORIGIN_SSH}"
89+
echo " (or ${EXPECTED_ORIGIN_HTTPS})"
90+
echo " Actual: ${actual_origin}"
91+
echo ""
92+
echo "To fix this, update your origin remote:"
93+
echo " git remote set-url origin ${EXPECTED_ORIGIN_SSH}"
94+
exit 1
95+
fi
96+
97+
echo "✅ Git remote validation passed: origin → ${actual_origin}"
98+
}
99+
70100
# Function to get modules from go.work
71101
get_modules() {
72102
go work edit -json | jq -r '.Use[] | "\(.DiskPath | ltrimstr("./"))"' | tr '\n' ' ' && echo

.github/scripts/release.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ set -e
4747
readonly SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4848
source "${SCRIPT_DIR}/common.sh"
4949

50+
# Validate git remote before doing anything
51+
validate_git_remote
52+
5053
MODULE="${1:-}"
5154

5255
# Collect and stage changes across modules, then create a single commit

RELEASING.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,22 @@ The `pre-release-all` or `pre-release` command must be run first:
123123
- Handles prerelease numbering with leading zeros
124124
- Writes the next version to a file in the build directory, located at `.github/scripts/.build/<module>-next-tag`
125125

126-
### 2. Pre-Release Check
127-
The `release-all` command automatically runs `check-pre-release` for all modules to verify:
128-
- The `.github/scripts/.build` directory exists
129-
- Each module has a corresponding `<module>-next-tag` file
130-
- The version in the `<module>-next-tag` file matches the version in `<module>/version.go`
126+
### 2. Release Validation Checks
127+
Before creating any commits or tags, the release script performs the following validation checks:
128+
129+
**Git Remote Validation:**
130+
- Verifies that the `origin` remote points to `git@github.com:docker/go-sdk.git` (or HTTPS equivalent)
131+
- Prevents accidentally pushing releases to forks or personal repositories
132+
- If validation fails, the script aborts immediately with instructions to fix the remote
133+
134+
**Pre-Release Verification:**
135+
- The `release-all` command automatically runs `check-pre-release` for all modules
136+
- Verifies the `.github/scripts/.build` directory exists
137+
- Checks each module has a corresponding `<module>-next-tag` file
138+
- Validates the version in `<module>-next-tag` matches the version in `<module>/version.go`
131139
- If any checks fail, the release is aborted with an error message
132-
133-
This check is implemented in `.github/scripts/check-pre-release.sh` and ensures that `pre-release-all` was completed successfully (with `DRY_RUN=false`) and that all version files are properly updated before proceeding with the release.
140+
- Implemented in `.github/scripts/check-pre-release.sh`
141+
- Ensures `pre-release-all` was completed successfully (with `DRY_RUN=false`)
134142

135143
You can manually run the check for a specific module:
136144
```bash

0 commit comments

Comments
 (0)