Compare commits
6 Commits
v1.0.38-2-
...
v1.0.44
| Author | SHA1 | Date | |
|---|---|---|---|
| bd54e85727 | |||
| b042b2d508 | |||
| af1733dc9a | |||
| 389fff2b44 | |||
| f331ba2b61 | |||
| f4b8fc5382 |
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
description: Build the RelSpec binary
|
|
||||||
---
|
|
||||||
|
|
||||||
Build the RelSpec project by running `make build`. Report the build status and any errors encountered.
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
description: Generate test coverage report
|
|
||||||
---
|
|
||||||
|
|
||||||
Generate and display test coverage for RelSpec:
|
|
||||||
1. Run `go test -cover ./...` to get coverage percentage
|
|
||||||
2. If detailed coverage is needed, run `go test -coverprofile=coverage.out ./...` and then `go tool cover -html=coverage.out` to generate HTML report
|
|
||||||
|
|
||||||
Show coverage statistics and identify areas needing more tests.
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
---
|
|
||||||
description: Run Go linters on the codebase
|
|
||||||
---
|
|
||||||
|
|
||||||
Run linting tools on the RelSpec codebase:
|
|
||||||
1. First run `gofmt -l .` to check formatting
|
|
||||||
2. If golangci-lint is available, run `golangci-lint run ./...`
|
|
||||||
3. Run `go vet ./...` to check for suspicious constructs
|
|
||||||
|
|
||||||
Report any issues found and suggest fixes if needed.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
description: Run all tests for the RelSpec project
|
|
||||||
---
|
|
||||||
|
|
||||||
Run `go test ./...` to execute all unit tests in the project. Show a summary of the results and highlight any failures.
|
|
||||||
327
.gitea/workflows/release.yml
Normal file
327
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
tag:
|
||||||
|
description: 'Tag to release (e.g. v1.2.3)'
|
||||||
|
required: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Build release binaries
|
||||||
|
run: |
|
||||||
|
VERSION="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
for target in "linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64" "windows/amd64"; do
|
||||||
|
GOOS="${target%/*}"
|
||||||
|
GOARCH="${target#*/}"
|
||||||
|
EXT=""
|
||||||
|
[ "$GOOS" = "windows" ] && EXT=".exe"
|
||||||
|
NAME="relspec-${GOOS}-${GOARCH}${EXT}"
|
||||||
|
GOOS="$GOOS" GOARCH="$GOARCH" go build \
|
||||||
|
-trimpath \
|
||||||
|
-ldflags "-X git.warky.dev/wdevs/relspecgo/cmd/relspec.version=${VERSION}" \
|
||||||
|
-o "$NAME" ./cmd/relspec
|
||||||
|
echo "Built $NAME"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Create release and upload assets
|
||||||
|
run: |
|
||||||
|
TAG="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
API="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases"
|
||||||
|
|
||||||
|
# Collect commits since the previous tag (or last 20 if no prior tag)
|
||||||
|
PREV_TAG=$(git tag --sort=-version:refname | grep -v "^${TAG}$" | head -1)
|
||||||
|
if [ -n "$PREV_TAG" ]; then
|
||||||
|
RANGE="${PREV_TAG}..${TAG}"
|
||||||
|
else
|
||||||
|
RANGE="HEAD~20..HEAD"
|
||||||
|
fi
|
||||||
|
NOTES=$(git log "$RANGE" --pretty=format:"- %s" --no-merges)
|
||||||
|
BODY="## What's changed"$'\n'"${NOTES}"
|
||||||
|
|
||||||
|
# Escape for JSON
|
||||||
|
BODY_JSON=$(printf '%s' "$BODY" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))')
|
||||||
|
|
||||||
|
RELEASE=$(curl -s -X POST "$API" \
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{\"tag_name\":\"${TAG}\",\"name\":\"${TAG}\",\"body\":${BODY_JSON}}")
|
||||||
|
|
||||||
|
UPLOAD_URL=$(echo "$RELEASE" | grep -o '"upload_url":"[^"]*"' | cut -d'"' -f4 | sed 's/{[^}]*}//')
|
||||||
|
if [ -z "$UPLOAD_URL" ]; then
|
||||||
|
echo "Failed to create release: $RELEASE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for f in relspec-*; do
|
||||||
|
echo "Uploading $f..."
|
||||||
|
curl -s -X POST "${UPLOAD_URL}?name=${f}" \
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary "@${f}" > /dev/null
|
||||||
|
done
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
pkg-aur:
|
||||||
|
needs: release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Publish to AUR
|
||||||
|
env:
|
||||||
|
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
VERSION="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
PKGVER="${VERSION#v}"
|
||||||
|
AUR_KEY_PATH="$HOME/.ssh/aur"
|
||||||
|
AUR_KNOWN_HOSTS="$HOME/.ssh/known_hosts"
|
||||||
|
|
||||||
|
# Setup SSH for AUR
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
chmod 700 ~/.ssh
|
||||||
|
|
||||||
|
if [ -z "${AUR_SSH_KEY:-}" ]; then
|
||||||
|
echo "AUR_SSH_KEY is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Support raw multiline keys, escaped \\n secrets, or base64-encoded keys.
|
||||||
|
CLEAN_AUR_SSH_KEY="$(printf '%s' "$AUR_SSH_KEY" | tr -d '\r')"
|
||||||
|
if printf '%s' "$CLEAN_AUR_SSH_KEY" | grep -q "^-----BEGIN .*PRIVATE KEY-----$"; then
|
||||||
|
printf '%s\n' "$CLEAN_AUR_SSH_KEY" > "$AUR_KEY_PATH"
|
||||||
|
elif printf '%s' "$CLEAN_AUR_SSH_KEY" | grep -q '\\n'; then
|
||||||
|
printf '%b\n' "$CLEAN_AUR_SSH_KEY" > "$AUR_KEY_PATH"
|
||||||
|
else
|
||||||
|
if printf '%s' "$CLEAN_AUR_SSH_KEY" | tr -d '[:space:]' | base64 --decode > "$AUR_KEY_PATH" 2>/dev/null; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
printf '%s\n' "$CLEAN_AUR_SSH_KEY" > "$AUR_KEY_PATH"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
chmod 600 "$AUR_KEY_PATH"
|
||||||
|
|
||||||
|
if ! ssh-keygen -y -f "$AUR_KEY_PATH" >/dev/null 2>&1; then
|
||||||
|
echo "AUR_SSH_KEY is not a valid private key."
|
||||||
|
echo "Store it as a raw private key, an escaped private key with \\n, or a base64-encoded private key."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ssh-keyscan -t rsa,ed25519 aur.archlinux.org >> "$AUR_KNOWN_HOSTS"
|
||||||
|
chmod 644 "$AUR_KNOWN_HOSTS"
|
||||||
|
|
||||||
|
# Clone AUR repo
|
||||||
|
GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$AUR_KNOWN_HOSTS -i $AUR_KEY_PATH" \
|
||||||
|
git clone ssh://aur@aur.archlinux.org/relspec.git aur-repo
|
||||||
|
|
||||||
|
CURRENT_PKGVER=$(awk -F= '/^pkgver=/ {print $2; exit}' aur-repo/PKGBUILD | tr -d "[:space:]")
|
||||||
|
CURRENT_PKGREL=$(awk -F= '/^pkgrel=/ {print $2; exit}' aur-repo/PKGBUILD | tr -d "[:space:]")
|
||||||
|
|
||||||
|
if [ "$CURRENT_PKGVER" = "$PKGVER" ]; then
|
||||||
|
case "$CURRENT_PKGREL" in
|
||||||
|
''|*[!0-9]*)
|
||||||
|
echo "Unsupported pkgrel in AUR repo: ${CURRENT_PKGREL}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
PKGREL=$((CURRENT_PKGREL + 1))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
PKGREL=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Publishing AUR package version ${PKGVER}-${PKGREL}"
|
||||||
|
|
||||||
|
# Compute SHA256 of the source archive from the same URL the PKGBUILD will download.
|
||||||
|
SHA=$(curl -fsSL "https://git.warky.dev/wdevs/relspecgo/archive/v${PKGVER}.zip" | sha256sum | cut -d' ' -f1)
|
||||||
|
|
||||||
|
# Update PKGBUILD — keep remote source URL, bump version/checksum, and increment pkgrel for same-version rebuilds.
|
||||||
|
sed -e "s/^pkgver=.*/pkgver=${PKGVER}/" \
|
||||||
|
-e "s/^pkgrel=.*/pkgrel=${PKGREL}/" \
|
||||||
|
-e "s/^sha256sums=.*/sha256sums=('${SHA}')/" \
|
||||||
|
linux/arch/PKGBUILD > aur-repo/PKGBUILD
|
||||||
|
|
||||||
|
# Generate .SRCINFO inside an Arch container (docker cp avoids DinD volume mount issues)
|
||||||
|
CID=$(docker run -d archlinux:latest sleep infinity)
|
||||||
|
docker cp aur-repo/PKGBUILD $CID:/build/PKGBUILD || (docker exec $CID mkdir -p /build && docker cp aur-repo/PKGBUILD $CID:/build/PKGBUILD)
|
||||||
|
docker exec $CID bash -c "
|
||||||
|
pacman -Sy --noconfirm base-devel &&
|
||||||
|
useradd -m builder &&
|
||||||
|
chown -R builder:builder /build &&
|
||||||
|
runuser -u builder -- bash -c 'cd /build && makepkg --printsrcinfo > .SRCINFO'
|
||||||
|
"
|
||||||
|
docker cp $CID:/build/.SRCINFO aur-repo/.SRCINFO
|
||||||
|
docker rm -f $CID
|
||||||
|
|
||||||
|
# Commit and push to AUR master
|
||||||
|
cd aur-repo
|
||||||
|
git config user.email "hein@warky.dev"
|
||||||
|
git config user.name "Hein"
|
||||||
|
git add PKGBUILD .SRCINFO
|
||||||
|
git commit -m "Update to v${PKGVER}-${PKGREL}"
|
||||||
|
GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$AUR_KNOWN_HOSTS -i $AUR_KEY_PATH" \
|
||||||
|
git push origin HEAD:master
|
||||||
|
|
||||||
|
pkg-deb:
|
||||||
|
needs: release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
|
||||||
|
- name: Build Debian packages
|
||||||
|
run: |
|
||||||
|
VERSION="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
PKGVER="${VERSION#v}"
|
||||||
|
|
||||||
|
for GOARCH in amd64 arm64; do
|
||||||
|
GOOS=linux GOARCH=$GOARCH go build \
|
||||||
|
-trimpath \
|
||||||
|
-ldflags "-X git.warky.dev/wdevs/relspecgo/cmd/relspec.version=${PKGVER}" \
|
||||||
|
-o relspec ./cmd/relspec
|
||||||
|
|
||||||
|
PKGDIR="relspec_${PKGVER}_${GOARCH}"
|
||||||
|
mkdir -p "${PKGDIR}/DEBIAN"
|
||||||
|
mkdir -p "${PKGDIR}/usr/bin"
|
||||||
|
|
||||||
|
install -m755 relspec "${PKGDIR}/usr/bin/relspec"
|
||||||
|
|
||||||
|
sed -e "s/VERSION/${PKGVER}/" \
|
||||||
|
-e "s/ARCH/${GOARCH}/" \
|
||||||
|
linux/debian/control > "${PKGDIR}/DEBIAN/control"
|
||||||
|
|
||||||
|
dpkg-deb --build --root-owner-group "${PKGDIR}"
|
||||||
|
echo "Built ${PKGDIR}.deb"
|
||||||
|
done
|
||||||
|
|
||||||
|
- name: Upload to release
|
||||||
|
run: |
|
||||||
|
TAG="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
RELEASE=$(curl -s "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" \
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN}")
|
||||||
|
UPLOAD_URL=$(echo "$RELEASE" | grep -o '"upload_url":"[^"]*"' | cut -d'"' -f4 | sed 's/{[^}]*}//')
|
||||||
|
for f in *.deb; do
|
||||||
|
FNAME=$(basename "$f")
|
||||||
|
echo "Uploading $FNAME..."
|
||||||
|
curl -s -X POST "${UPLOAD_URL}?name=${FNAME}" \
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary "@${f}" > /dev/null
|
||||||
|
done
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
pkg-rpm:
|
||||||
|
needs: release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Build RPM
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
VERSION="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
PKGVER="${VERSION#v}"
|
||||||
|
GO_VER="$(awk '/^go / { print $2; exit }' go.mod)"
|
||||||
|
|
||||||
|
if [ -z "${GO_VER}" ]; then
|
||||||
|
echo "Failed to determine Go version from go.mod"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Source tarball — prefix=relspec-VERSION/ matches RPM %autosetup convention
|
||||||
|
git archive --format=tar.gz --prefix=relspec-${PKGVER}/ HEAD \
|
||||||
|
> relspec-${PKGVER}.tar.gz
|
||||||
|
|
||||||
|
# Patch spec version
|
||||||
|
sed -i "s/^Version:.*/Version: ${PKGVER}/" linux/centos/relspec.spec
|
||||||
|
|
||||||
|
mkdir -p linux/centos/out
|
||||||
|
CID=$(docker create \
|
||||||
|
-e GO_VER="${GO_VER}" \
|
||||||
|
-e PKGVER="${PKGVER}" \
|
||||||
|
-w /build \
|
||||||
|
rockylinux:9 \
|
||||||
|
bash -lc "
|
||||||
|
set -euo pipefail
|
||||||
|
dnf install -y rpm-build git &&
|
||||||
|
curl -fsSL https://go.dev/dl/go\${GO_VER}.linux-amd64.tar.gz | tar -C /usr/local -xz &&
|
||||||
|
export PATH=\$PATH:/usr/local/go/bin &&
|
||||||
|
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} &&
|
||||||
|
cp relspec-${PKGVER}.tar.gz ~/rpmbuild/SOURCES/ &&
|
||||||
|
cp linux/centos/relspec.spec ~/rpmbuild/SPECS/ &&
|
||||||
|
rpmbuild --nodeps -ba ~/rpmbuild/SPECS/relspec.spec
|
||||||
|
")
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
docker rm -f "$CID" >/dev/null 2>&1 || true
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
docker cp relspec-${PKGVER}.tar.gz "$CID:/build/relspec-${PKGVER}.tar.gz"
|
||||||
|
docker cp linux "$CID:/build/linux"
|
||||||
|
|
||||||
|
docker start -a "$CID"
|
||||||
|
docker cp "$CID:/root/rpmbuild/RPMS/." linux/centos/out/
|
||||||
|
|
||||||
|
trap - EXIT
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
- name: Upload to release
|
||||||
|
run: |
|
||||||
|
TAG="${{ github.event.inputs.tag || github.ref_name }}"
|
||||||
|
RELEASE=$(curl -s "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" \
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN}")
|
||||||
|
UPLOAD_URL=$(echo "$RELEASE" | grep -o '"upload_url":"[^"]*"' | cut -d'"' -f4 | sed 's/{[^}]*}//')
|
||||||
|
while IFS= read -r f; do
|
||||||
|
FNAME=$(basename "$f")
|
||||||
|
echo "Uploading $FNAME..."
|
||||||
|
curl -s -X POST "${UPLOAD_URL}?name=${FNAME}" \
|
||||||
|
-H "Authorization: token ${GITHUB_TOKEN}" \
|
||||||
|
-H "Content-Type: application/octet-stream" \
|
||||||
|
--data-binary "@${f}" > /dev/null
|
||||||
|
done < <(find linux/centos/out -name "*.rpm")
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
117
.github/workflows/release.yml
vendored
117
.github/workflows/release.yml
vendored
@@ -1,117 +0,0 @@
|
|||||||
name: Release
|
|
||||||
run-name: "Making Release"
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- 'v*.*.*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-release:
|
|
||||||
name: Build and Release
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Set up Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
|
|
||||||
- name: Get version from tag
|
|
||||||
id: get_version
|
|
||||||
run: |
|
|
||||||
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
|
||||||
echo "BUILD_DATE=$(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT
|
|
||||||
echo "Version: ${GITHUB_REF#refs/tags/}"
|
|
||||||
|
|
||||||
- name: Build binaries for multiple platforms
|
|
||||||
run: |
|
|
||||||
mkdir -p dist
|
|
||||||
|
|
||||||
# Linux AMD64
|
|
||||||
GOOS=linux GOARCH=amd64 go build -o dist/relspec-linux-amd64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
|
||||||
|
|
||||||
# Linux ARM64
|
|
||||||
GOOS=linux GOARCH=arm64 go build -o dist/relspec-linux-arm64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
|
||||||
|
|
||||||
# macOS AMD64
|
|
||||||
GOOS=darwin GOARCH=amd64 go build -o dist/relspec-darwin-amd64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
|
||||||
|
|
||||||
# macOS ARM64 (Apple Silicon)
|
|
||||||
GOOS=darwin GOARCH=arm64 go build -o dist/relspec-darwin-arm64 -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
|
||||||
|
|
||||||
# Windows AMD64
|
|
||||||
GOOS=windows GOARCH=amd64 go build -o dist/relspec-windows-amd64.exe -ldflags "-X 'main.version=${{ steps.get_version.outputs.VERSION }}' -X 'main.buildDate=${{ steps.get_version.outputs.BUILD_DATE }}'" ./cmd/relspec
|
|
||||||
|
|
||||||
# Create checksums
|
|
||||||
cd dist
|
|
||||||
sha256sum * > checksums.txt
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
- name: Generate release notes
|
|
||||||
id: release_notes
|
|
||||||
run: |
|
|
||||||
# Get the previous tag
|
|
||||||
previous_tag=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
|
||||||
|
|
||||||
if [ -z "$previous_tag" ]; then
|
|
||||||
# No previous tag, get all commits
|
|
||||||
commits=$(git log --pretty=format:"- %s (%h)" --no-merges)
|
|
||||||
else
|
|
||||||
# Get commits since the previous tag
|
|
||||||
commits=$(git log "${previous_tag}..HEAD" --pretty=format:"- %s (%h)" --no-merges)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create release notes
|
|
||||||
cat > release_notes.md << EOF
|
|
||||||
# Release ${{ steps.get_version.outputs.VERSION }}
|
|
||||||
|
|
||||||
## Changes
|
|
||||||
|
|
||||||
${commits}
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
Download the appropriate binary for your platform:
|
|
||||||
|
|
||||||
- **Linux (AMD64)**: \`relspec-linux-amd64\`
|
|
||||||
- **Linux (ARM64)**: \`relspec-linux-arm64\`
|
|
||||||
- **macOS (Intel)**: \`relspec-darwin-amd64\`
|
|
||||||
- **macOS (Apple Silicon)**: \`relspec-darwin-arm64\`
|
|
||||||
- **Windows (AMD64)**: \`relspec-windows-amd64.exe\`
|
|
||||||
|
|
||||||
Make the binary executable (Linux/macOS):
|
|
||||||
\`\`\`bash
|
|
||||||
chmod +x relspec-*
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
Verify the download with the provided checksums.
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: Create Release
|
|
||||||
uses: softprops/action-gh-release@v1
|
|
||||||
with:
|
|
||||||
body_path: release_notes.md
|
|
||||||
files: |
|
|
||||||
dist/relspec-linux-amd64
|
|
||||||
dist/relspec-linux-arm64
|
|
||||||
dist/relspec-darwin-amd64
|
|
||||||
dist/relspec-darwin-arm64
|
|
||||||
dist/relspec-windows-amd64.exe
|
|
||||||
dist/checksums.txt
|
|
||||||
draft: false
|
|
||||||
prerelease: false
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Summary
|
|
||||||
run: |
|
|
||||||
echo "Release ${{ steps.get_version.outputs.VERSION }} created successfully!"
|
|
||||||
echo "Binaries built for:"
|
|
||||||
echo " - Linux (amd64, arm64)"
|
|
||||||
echo " - macOS (amd64, arm64)"
|
|
||||||
echo " - Windows (amd64)"
|
|
||||||
39
Makefile
39
Makefile
@@ -204,30 +204,21 @@ release: ## Create and push a new release tag (auto-increments patch version)
|
|||||||
git push origin "$$version"; \
|
git push origin "$$version"; \
|
||||||
echo "Tag $$version created and pushed to remote repository."
|
echo "Tag $$version created and pushed to remote repository."
|
||||||
|
|
||||||
release-version: ## Create and push a release with specific version (use: make release-version VERSION=v1.2.3)
|
release-version: ## Auto-increment patch version, update package files, commit, tag, and push
|
||||||
@if [ -z "$(VERSION)" ]; then \
|
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
|
||||||
echo "Error: VERSION is required. Usage: make release-version VERSION=v1.2.3"; \
|
MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \
|
||||||
exit 1; \
|
MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \
|
||||||
fi
|
PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \
|
||||||
@version="$(VERSION)"; \
|
NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
|
||||||
if ! echo "$$version" | grep -q "^v"; then \
|
PKGVER="$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
|
||||||
version="v$$version"; \
|
echo "Current: $$CURRENT → Next: $$NEXT"; \
|
||||||
fi; \
|
sed -i "s/^pkgver=.*/pkgver=$$PKGVER/" linux/arch/PKGBUILD; \
|
||||||
echo "Creating release: $$version"; \
|
sed -i "s/^Version:.*/Version: $$PKGVER/" linux/centos/relspec.spec; \
|
||||||
latest_tag=$$(git describe --tags --abbrev=0 2>/dev/null || echo ""); \
|
git add linux/arch/PKGBUILD linux/centos/relspec.spec; \
|
||||||
if [ -z "$$latest_tag" ]; then \
|
git commit -m "chore(release): update package version to $$PKGVER"; \
|
||||||
commit_logs=$$(git log --pretty=format:"- %s" --no-merges); \
|
git tag -a "$$NEXT" -m "Release $$NEXT"; \
|
||||||
else \
|
git push origin HEAD "$$NEXT"; \
|
||||||
commit_logs=$$(git log "$${latest_tag}..HEAD" --pretty=format:"- %s" --no-merges); \
|
echo "Pushed $$NEXT — release workflow triggered"
|
||||||
fi; \
|
|
||||||
if [ -z "$$commit_logs" ]; then \
|
|
||||||
tag_message="Release $$version"; \
|
|
||||||
else \
|
|
||||||
tag_message="Release $$version\n\n$$commit_logs"; \
|
|
||||||
fi; \
|
|
||||||
git tag -a "$$version" -m "$$tag_message"; \
|
|
||||||
git push origin "$$version"; \
|
|
||||||
echo "Tag $$version created and pushed to remote repository."
|
|
||||||
|
|
||||||
help: ## Display this help screen
|
help: ## Display this help screen
|
||||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||||
|
|||||||
320
README.md
320
README.md
@@ -6,264 +6,160 @@
|
|||||||
[](https://go.dev/dl/)
|
[](https://go.dev/dl/)
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
|
|
||||||
> Database Relations Specification Tool for Go
|
> Bidirectional database schema conversion, validation, and templating tool.
|
||||||
|
|
||||||
RelSpec is a comprehensive database relations management tool that reads, transforms, and writes database table specifications across multiple formats and ORMs.
|

|
||||||
|
|
||||||
## Overview
|
## Install
|
||||||
|
|
||||||
RelSpec provides bidirectional conversion, comparison, and validation of database specification formats, allowing you to:
|
|
||||||
- Inspect live databases and extract their structure
|
|
||||||
- Validate schemas against configurable rules and naming conventions
|
|
||||||
- Convert between different ORM models (GORM, Bun, etc.)
|
|
||||||
- Transform legacy schema definitions (Clarion DCTX, XML, JSON, etc.)
|
|
||||||
- Generate standardized specification files (JSON, YAML, etc.)
|
|
||||||
- Compare database schemas and track changes
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
### Readers (Input Formats)
|
|
||||||
|
|
||||||
RelSpec can read database schemas from multiple sources:
|
|
||||||
|
|
||||||
#### ORM Models
|
|
||||||
- [GORM](pkg/readers/gorm/README.md) - Go GORM model definitions
|
|
||||||
- [Bun](pkg/readers/bun/README.md) - Go Bun model definitions
|
|
||||||
- [Drizzle](pkg/readers/drizzle/README.md) - TypeScript Drizzle ORM schemas
|
|
||||||
- [Prisma](pkg/readers/prisma/README.md) - Prisma schema language
|
|
||||||
- [TypeORM](pkg/readers/typeorm/README.md) - TypeScript TypeORM entities
|
|
||||||
|
|
||||||
#### Database Inspection
|
|
||||||
- [PostgreSQL](pkg/readers/pgsql/README.md) - Direct PostgreSQL database introspection
|
|
||||||
- [SQLite](pkg/readers/sqlite/README.md) - Direct SQLite database introspection
|
|
||||||
|
|
||||||
#### Schema Formats
|
|
||||||
- [DBML](pkg/readers/dbml/README.md) - Database Markup Language (dbdiagram.io)
|
|
||||||
- [DCTX](pkg/readers/dctx/README.md) - Clarion database dictionary format
|
|
||||||
- [DrawDB](pkg/readers/drawdb/README.md) - DrawDB JSON format
|
|
||||||
- [GraphQL](pkg/readers/graphql/README.md) - GraphQL Schema Definition Language (SDL)
|
|
||||||
- [JSON](pkg/readers/json/README.md) - RelSpec canonical JSON format
|
|
||||||
- [YAML](pkg/readers/yaml/README.md) - RelSpec canonical YAML format
|
|
||||||
|
|
||||||
### Writers (Output Formats)
|
|
||||||
|
|
||||||
RelSpec can write database schemas to multiple formats:
|
|
||||||
|
|
||||||
#### ORM Models
|
|
||||||
- [GORM](pkg/writers/gorm/README.md) - Generate GORM-compatible Go structs
|
|
||||||
- [Bun](pkg/writers/bun/README.md) - Generate Bun-compatible Go structs
|
|
||||||
- [Drizzle](pkg/writers/drizzle/README.md) - Generate Drizzle ORM TypeScript schemas
|
|
||||||
- [Prisma](pkg/writers/prisma/README.md) - Generate Prisma schema files
|
|
||||||
- [TypeORM](pkg/writers/typeorm/README.md) - Generate TypeORM TypeScript entities
|
|
||||||
|
|
||||||
#### Database DDL
|
|
||||||
- [PostgreSQL](pkg/writers/pgsql/README.md) - PostgreSQL DDL (CREATE TABLE, etc.)
|
|
||||||
- [SQLite](pkg/writers/sqlite/README.md) - SQLite DDL with automatic schema flattening
|
|
||||||
|
|
||||||
#### Schema Formats
|
|
||||||
- [DBML](pkg/writers/dbml/README.md) - Database Markup Language
|
|
||||||
- [DCTX](pkg/writers/dctx/README.md) - Clarion database dictionary format
|
|
||||||
- [DrawDB](pkg/writers/drawdb/README.md) - DrawDB JSON format
|
|
||||||
- [GraphQL](pkg/writers/graphql/README.md) - GraphQL Schema Definition Language (SDL)
|
|
||||||
- [JSON](pkg/writers/json/README.md) - RelSpec canonical JSON format
|
|
||||||
- [YAML](pkg/writers/yaml/README.md) - RelSpec canonical YAML format
|
|
||||||
|
|
||||||
### Inspector (Schema Validation)
|
|
||||||
|
|
||||||
RelSpec includes a powerful schema validation and linting tool:
|
|
||||||
|
|
||||||
- [Inspector](pkg/inspector/README.md) - Validate database schemas against configurable rules
|
|
||||||
- Enforce naming conventions (snake_case, camelCase, custom patterns)
|
|
||||||
- Check primary key and foreign key standards
|
|
||||||
- Detect missing indexes on foreign keys
|
|
||||||
- Prevent use of SQL reserved keywords
|
|
||||||
- Ensure schema integrity (missing PKs, orphaned FKs, circular dependencies)
|
|
||||||
- Support for custom validation rules
|
|
||||||
- Multiple output formats (Markdown with colors, JSON)
|
|
||||||
- CI/CD integration ready
|
|
||||||
|
|
||||||
## Use of AI
|
|
||||||
[Rules and use of AI](./AI_USE.md)
|
|
||||||
|
|
||||||
## User Interface
|
|
||||||
|
|
||||||
RelSpec provides an interactive terminal-based user interface for managing and editing database schemas. The UI allows you to:
|
|
||||||
|
|
||||||
- **Browse Databases** - Navigate through your database structure with an intuitive menu system
|
|
||||||
- **Edit Schemas** - Create, modify, and organize database schemas
|
|
||||||
- **Manage Tables** - Add, update, or delete tables with full control over structure
|
|
||||||
- **Configure Columns** - Define column properties, data types, constraints, and relationships
|
|
||||||
- **Interactive Editing** - Real-time validation and feedback as you make changes
|
|
||||||
|
|
||||||
The interface supports multiple input formats, making it easy to load, edit, and save your database definitions in various formats.
|
|
||||||
|
|
||||||
<p align="center" width="100%">
|
|
||||||
<img src="./assets/image/screenshots/main_screen.jpg">
|
|
||||||
</p>
|
|
||||||
<p align="center" width="100%">
|
|
||||||
<img src="./assets/image/screenshots/table_view.jpg">
|
|
||||||
</p>
|
|
||||||
<p align="center" width="100%">
|
|
||||||
<img src="./assets/image/screenshots/edit_column.jpg">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/wdevs/relspecgo
|
|
||||||
|
|
||||||
go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest
|
go install -v git.warky.dev/wdevs/relspecgo/cmd/relspec@latest
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Supported Formats
|
||||||
|
|
||||||
### Interactive Schema Editor
|
| Direction | Formats |
|
||||||
|
|-----------|---------|
|
||||||
|
| **Readers** | `bun` `dbml` `dctx` `drawdb` `drizzle` `gorm` `graphql` `json` `mssql` `pgsql` `prisma` `sqldir` `sqlite` `typeorm` `yaml` |
|
||||||
|
| **Writers** | `bun` `dbml` `dctx` `drawdb` `drizzle` `gorm` `graphql` `json` `mssql` `pgsql` `prisma` `sqlexec` `sqlite` `template` `typeorm` `yaml` |
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
### `convert` — Schema conversion
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Launch interactive editor with a DBML schema
|
# PostgreSQL → GORM models
|
||||||
relspec edit --from dbml --from-path schema.dbml --to dbml --to-path schema.dbml
|
relspec convert --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
||||||
|
--to gorm --to-path models/ --package models
|
||||||
|
|
||||||
# Edit PostgreSQL database in place
|
# DBML → PostgreSQL DDL
|
||||||
relspec edit --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
relspec convert --from dbml --from-path schema.dbml --to pgsql --to-path schema.sql
|
||||||
--to pgsql --to-conn "postgres://user:pass@localhost/mydb"
|
|
||||||
|
|
||||||
# Edit JSON schema and save as GORM models
|
# PostgreSQL → SQLite (auto flattens schemas)
|
||||||
relspec edit --from json --from-path db.json --to gorm --to-path models/
|
relspec convert --from pgsql --from-conn "postgres://..." --to sqlite --to-path schema.sql
|
||||||
|
|
||||||
|
# Multiple input files merged
|
||||||
|
relspec convert --from json --from-list "a.json,b.json" --to yaml --to-path merged.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
The `edit` command launches an interactive terminal user interface where you can:
|
### `merge` — Additive schema merge (never modifies existing items)
|
||||||
- Browse and navigate your database structure
|
|
||||||
- Create, modify, and delete schemas, tables, and columns
|
|
||||||
- Configure column properties, constraints, and relationships
|
|
||||||
- Save changes to various formats
|
|
||||||
- Import and merge schemas from other databases
|
|
||||||
|
|
||||||
### Schema Merging
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Merge two JSON schemas (additive merge - adds missing items only)
|
# Merge two JSON schemas
|
||||||
relspec merge --target json --target-path base.json \
|
relspec merge --target json --target-path base.json \
|
||||||
--source json --source-path additions.json \
|
--source json --source-path additions.json \
|
||||||
--output json --output-path merged.json
|
--output json --output-path merged.json
|
||||||
|
|
||||||
# Merge PostgreSQL database into JSON, skipping specific tables
|
# Merge PostgreSQL into JSON, skipping tables
|
||||||
relspec merge --target json --target-path current.json \
|
relspec merge --target json --target-path current.json \
|
||||||
--source pgsql --source-conn "postgres://user:pass@localhost/source_db" \
|
--source pgsql --source-conn "postgres://user:pass@localhost/db" \
|
||||||
--output json --output-path updated.json \
|
--output json --output-path updated.json \
|
||||||
--skip-tables "audit_log,temp_tables"
|
--skip-tables "audit_log,temp_tables"
|
||||||
|
|
||||||
# Cross-format merge (DBML + YAML → JSON)
|
|
||||||
relspec merge --target dbml --target-path base.dbml \
|
|
||||||
--source yaml --source-path additions.yaml \
|
|
||||||
--output json --output-path result.json \
|
|
||||||
--skip-relations --skip-views
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The `merge` command combines two database schemas additively:
|
Skip flags: `--skip-relations` `--skip-views` `--skip-domains` `--skip-enums` `--skip-sequences`
|
||||||
- Adds missing schemas, tables, columns, and other objects
|
|
||||||
- Never modifies or deletes existing items (safe operation)
|
|
||||||
- Supports selective merging with skip options (domains, relations, enums, views, sequences, specific tables)
|
|
||||||
- Works across any combination of supported formats
|
|
||||||
- Perfect for integrating multiple schema definitions or applying patches
|
|
||||||
|
|
||||||
### Schema Conversion
|
### `inspect` — Schema validation / linting
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Convert PostgreSQL database to GORM models
|
# Validate PostgreSQL database
|
||||||
relspec convert --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
|
||||||
--to gorm --to-path models/ --package models
|
|
||||||
|
|
||||||
# Convert GORM models to Bun
|
|
||||||
relspec convert --from gorm --from-path models.go \
|
|
||||||
--to bun --to-path bun_models.go --package models
|
|
||||||
|
|
||||||
# Export database schema to JSON
|
|
||||||
relspec convert --from pgsql --from-conn "postgres://..." \
|
|
||||||
--to json --to-path schema.json
|
|
||||||
|
|
||||||
# Convert DBML to PostgreSQL SQL
|
|
||||||
relspec convert --from dbml --from-path schema.dbml \
|
|
||||||
--to pgsql --to-path schema.sql
|
|
||||||
|
|
||||||
# Convert PostgreSQL database to SQLite (with automatic schema flattening)
|
|
||||||
relspec convert --from pgsql --from-conn "postgres://..." \
|
|
||||||
--to sqlite --to-path sqlite_schema.sql
|
|
||||||
```
|
|
||||||
|
|
||||||
### Schema Validation
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Validate a PostgreSQL database with default rules
|
|
||||||
relspec inspect --from pgsql --from-conn "postgres://user:pass@localhost/mydb"
|
relspec inspect --from pgsql --from-conn "postgres://user:pass@localhost/mydb"
|
||||||
|
|
||||||
# Validate DBML file with custom rules
|
# Validate DBML with custom rules
|
||||||
relspec inspect --from dbml --from-path schema.dbml --rules .relspec-rules.yaml
|
relspec inspect --from dbml --from-path schema.dbml --rules .relspec-rules.yaml
|
||||||
|
|
||||||
# Generate JSON validation report
|
# JSON report output
|
||||||
relspec inspect --from json --from-path db.json \
|
relspec inspect --from json --from-path db.json --output-format json --output report.json
|
||||||
--output-format json --output report.json
|
|
||||||
|
|
||||||
# Validate specific schema only
|
# Filter to specific schema
|
||||||
relspec inspect --from pgsql --from-conn "..." --schema public
|
relspec inspect --from pgsql --from-conn "..." --schema public
|
||||||
```
|
```
|
||||||
|
|
||||||
### Schema Comparison
|
Rules: naming conventions, PK/FK standards, missing indexes, reserved keywords, circular dependencies.
|
||||||
|
|
||||||
|
### `diff` — Schema comparison
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Compare two database schemas
|
|
||||||
relspec diff --from pgsql --from-conn "postgres://localhost/db1" \
|
relspec diff --from pgsql --from-conn "postgres://localhost/db1" \
|
||||||
--to pgsql --to-conn "postgres://localhost/db2"
|
--to pgsql --to-conn "postgres://localhost/db2"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `templ` — Custom template rendering
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Render database schema to Markdown docs
|
||||||
|
relspec templ --from pgsql --from-conn "postgres://user:pass@localhost/db" \
|
||||||
|
--template docs.tmpl --output schema-docs.md
|
||||||
|
|
||||||
|
# One TypeScript file per table
|
||||||
|
relspec templ --from dbml --from-path schema.dbml \
|
||||||
|
--template ts-model.tmpl --mode table \
|
||||||
|
--output ./models/ --filename-pattern "{{.Name | toCamelCase}}.ts"
|
||||||
|
```
|
||||||
|
|
||||||
|
Modes: `database` (default) · `schema` · `table` · `script`
|
||||||
|
|
||||||
|
Template functions: string utils (`toCamelCase`, `toSnakeCase`, `pluralize`, …), type converters (`sqlToGo`, `sqlToTypeScript`, …), filters, loop helpers, safe access.
|
||||||
|
|
||||||
|
### `edit` — Interactive TUI editor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Edit DBML schema interactively
|
||||||
|
relspec edit --from dbml --from-path schema.dbml --to dbml --to-path schema.dbml
|
||||||
|
|
||||||
|
# Edit live PostgreSQL database
|
||||||
|
relspec edit --from pgsql --from-conn "postgres://user:pass@localhost/mydb" \
|
||||||
|
--to pgsql --to-conn "postgres://user:pass@localhost/mydb"
|
||||||
|
```
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="./assets/image/screenshots/main_screen.jpg">
|
||||||
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
<img src="./assets/image/screenshots/table_view.jpg">
|
||||||
|
</p>
|
||||||
|
<p align="center">
|
||||||
|
<img src="./assets/image/screenshots/edit_column.jpg">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
**Prerequisites:** Go 1.24.0+
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make build # → build/relspec
|
||||||
|
make test # race detection + coverage
|
||||||
|
make lint # requires golangci-lint
|
||||||
|
make coverage # → coverage.html
|
||||||
|
make install # → $GOPATH/bin
|
||||||
|
```
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
```
|
```
|
||||||
relspecgo/
|
cmd/relspec/ CLI commands
|
||||||
├── cmd/
|
pkg/readers/ Input format readers
|
||||||
│ └── relspec/ # CLI application (convert, inspect, diff, scripts)
|
pkg/writers/ Output format writers
|
||||||
├── pkg/
|
pkg/inspector/ Schema validation
|
||||||
│ ├── readers/ # Input format readers (DBML, GORM, PostgreSQL, etc.)
|
pkg/diff/ Schema comparison
|
||||||
│ ├── writers/ # Output format writers (GORM, Bun, SQL, etc.)
|
pkg/merge/ Schema merging
|
||||||
│ ├── inspector/ # Schema validation and linting
|
pkg/models/ Internal data models
|
||||||
│ ├── diff/ # Schema comparison
|
pkg/transform/ Transformation logic
|
||||||
│ ├── models/ # Internal data models
|
pkg/pgsql/ PostgreSQL utilities
|
||||||
│ ├── transform/ # Transformation logic
|
|
||||||
│ └── pgsql/ # PostgreSQL utilities (keywords, data types)
|
|
||||||
├── examples/ # Usage examples
|
|
||||||
└── tests/ # Test files
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Todo
|
|
||||||
|
|
||||||
[Todo List of Features](./TODO.md)
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
### Prerequisites
|
|
||||||
- Go 1.21 or higher
|
|
||||||
- Access to test databases (optional)
|
|
||||||
|
|
||||||
### Building
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go build -o relspec ./cmd/relspec
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go test ./...
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Apache License 2.0 - See [LICENSE](LICENSE) for details.
|
|
||||||
|
|
||||||
Copyright 2025 Warky Devs
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Contributions welcome. Please open an issue or submit a pull request.
|
1. Register or sign in with GitHub at [git.warky.dev](https://git.warky.dev)
|
||||||
|
2. Clone the repository: `git clone https://git.warky.dev/wdevs/relspecgo.git`
|
||||||
|
3. Create a feature branch: `git checkout -b feature/your-feature-name`
|
||||||
|
4. Commit your changes and push the branch
|
||||||
|
5. Open a pull request with a description of the new feature or fix
|
||||||
|
|
||||||
|
For questions or discussion, join the Discord: [discord.gg/74rcTujp25](https://discord.gg/74rcTujp25) — `warkyhein`
|
||||||
|
|
||||||
|
## Links
|
||||||
|
|
||||||
|
- [Todo](./TODO.md)
|
||||||
|
- [AI Use Policy](./AI_USE.md)
|
||||||
|
- [License](LICENSE) — Apache 2.0 · Copyright 2025 Warky Devs
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 200 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 200 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 80 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 192 KiB |
35
linux/arch/PKGBUILD
Normal file
35
linux/arch/PKGBUILD
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Maintainer: Hein (Warky Devs) <hein@warky.dev>
|
||||||
|
pkgname=relspec
|
||||||
|
pkgver=1.0.44
|
||||||
|
pkgrel=1
|
||||||
|
pkgdesc="RelSpec is a comprehensive database relations management tool that reads, transforms, and writes database table specifications across multiple formats and ORMs."
|
||||||
|
arch=('x86_64' 'aarch64')
|
||||||
|
url="https://git.warky.dev/wdevs/relspecgo"
|
||||||
|
license=('MIT')
|
||||||
|
makedepends=('go')
|
||||||
|
source=("$pkgname-$pkgver.zip::$url/archive/v$pkgver.zip")
|
||||||
|
sha256sums=('SKIP')
|
||||||
|
|
||||||
|
build() {
|
||||||
|
cd "relspecgo"
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
go build \
|
||||||
|
-trimpath \
|
||||||
|
-ldflags "-X git.warky.dev/wdevs/relspecgo/cmd/relspec.version=$pkgver" \
|
||||||
|
-o "$pkgname" ./cmd/relspec
|
||||||
|
}
|
||||||
|
|
||||||
|
check() {
|
||||||
|
cd "relspecgo"
|
||||||
|
go test ./...
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
cd "relspecgo"
|
||||||
|
|
||||||
|
# Binary
|
||||||
|
install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"
|
||||||
|
|
||||||
|
# Default config dir
|
||||||
|
install -dm755 "$pkgdir/etc/relspec"
|
||||||
|
}
|
||||||
43
linux/centos/relspec.spec
Normal file
43
linux/centos/relspec.spec
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
Name: relspec
|
||||||
|
Version: 1.0.44
|
||||||
|
Release: 1%{?dist}
|
||||||
|
Summary: RelSpec is a comprehensive database relations management tool that reads, transforms, and writes database table specifications across multiple formats and ORMs.
|
||||||
|
|
||||||
|
License: MIT
|
||||||
|
URL: https://git.warky.dev/wdevs/relspecgo
|
||||||
|
Source0: %{name}-%{version}.tar.gz
|
||||||
|
|
||||||
|
BuildRequires: golang >= 1.24
|
||||||
|
|
||||||
|
%global debug_package %{nil}
|
||||||
|
%define _debugsource_packages 0
|
||||||
|
%define _debuginfo_subpackages 0
|
||||||
|
|
||||||
|
%description
|
||||||
|
RelSpec provides bidirectional conversion between various database schema
|
||||||
|
formats including PostgreSQL, MySQL, SQLite, Prisma, TypeORM, GORM, Drizzle,
|
||||||
|
DBML, GraphQL, and more.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%autosetup
|
||||||
|
|
||||||
|
%build
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
go build \
|
||||||
|
-trimpath \
|
||||||
|
-ldflags "-X git.warky.dev/wdevs/relspecgo/cmd/relspec.version=%{version}" \
|
||||||
|
-o %{name} ./cmd/relspec
|
||||||
|
|
||||||
|
%install
|
||||||
|
install -Dm755 %{name} %{buildroot}%{_bindir}/%{name}
|
||||||
|
install -Dm644 LICENSE %{buildroot}%{_licensedir}/%{name}/LICENSE
|
||||||
|
install -dm755 %{buildroot}%{_sysconfdir}/relspec
|
||||||
|
|
||||||
|
%files
|
||||||
|
%license LICENSE
|
||||||
|
%{_bindir}/%{name}
|
||||||
|
%dir %{_sysconfdir}/relspec
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Wed Apr 08 2026 Hein (Warky Devs) <hein@warky.dev> - 1.0.42-1
|
||||||
|
- Initial package
|
||||||
11
linux/debian/control
Normal file
11
linux/debian/control
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
Package: relspec
|
||||||
|
Version: VERSION
|
||||||
|
Architecture: ARCH
|
||||||
|
Maintainer: Hein (Warky Devs) <hein@warky.dev>
|
||||||
|
Section: database
|
||||||
|
Priority: optional
|
||||||
|
Homepage: https://git.warky.dev/wdevs/relspecgo
|
||||||
|
Description: Database schema conversion and analysis tool
|
||||||
|
RelSpec provides bidirectional conversion between various database schema
|
||||||
|
formats including PostgreSQL, MySQL, SQLite, Prisma, TypeORM, GORM, Drizzle,
|
||||||
|
DBML, GraphQL, and more.
|
||||||
@@ -832,7 +832,11 @@ func (r *Reader) parseRef(refStr string) *models.Constraint {
|
|||||||
for _, action := range actionList {
|
for _, action := range actionList {
|
||||||
action = strings.TrimSpace(action)
|
action = strings.TrimSpace(action)
|
||||||
|
|
||||||
if strings.HasPrefix(action, "ondelete:") {
|
if strings.HasPrefix(action, "delete:") {
|
||||||
|
constraint.OnDelete = strings.TrimSpace(strings.TrimPrefix(action, "delete:"))
|
||||||
|
} else if strings.HasPrefix(action, "update:") {
|
||||||
|
constraint.OnUpdate = strings.TrimSpace(strings.TrimPrefix(action, "update:"))
|
||||||
|
} else if strings.HasPrefix(action, "ondelete:") {
|
||||||
constraint.OnDelete = strings.TrimSpace(strings.TrimPrefix(action, "ondelete:"))
|
constraint.OnDelete = strings.TrimSpace(strings.TrimPrefix(action, "ondelete:"))
|
||||||
} else if strings.HasPrefix(action, "onupdate:") {
|
} else if strings.HasPrefix(action, "onupdate:") {
|
||||||
constraint.OnUpdate = strings.TrimSpace(strings.TrimPrefix(action, "onupdate:"))
|
constraint.OnUpdate = strings.TrimSpace(strings.TrimPrefix(action, "onupdate:"))
|
||||||
|
|||||||
@@ -216,6 +216,21 @@ func resolveFieldNameCollision(fieldName string) string {
|
|||||||
return fieldName
|
return fieldName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sortConstraints sorts constraints by sequence, then by name
|
||||||
|
func sortConstraints(constraints map[string]*models.Constraint) []*models.Constraint {
|
||||||
|
result := make([]*models.Constraint, 0, len(constraints))
|
||||||
|
for _, c := range constraints {
|
||||||
|
result = append(result, c)
|
||||||
|
}
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
if result[i].Sequence > 0 && result[j].Sequence > 0 {
|
||||||
|
return result[i].Sequence < result[j].Sequence
|
||||||
|
}
|
||||||
|
return result[i].Name < result[j].Name
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// sortColumns sorts columns by sequence, then by name
|
// sortColumns sorts columns by sequence, then by name
|
||||||
func sortColumns(columns map[string]*models.Column) []*models.Column {
|
func sortColumns(columns map[string]*models.Column) []*models.Column {
|
||||||
result := make([]*models.Column, 0, len(columns))
|
result := make([]*models.Column, 0, len(columns))
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ func (w *Writer) addRelationshipFields(modelData *ModelData, table *models.Table
|
|||||||
usedFieldNames := make(map[string]int)
|
usedFieldNames := make(map[string]int)
|
||||||
|
|
||||||
// For each foreign key in this table, add a belongs-to/has-one relationship
|
// For each foreign key in this table, add a belongs-to/has-one relationship
|
||||||
for _, constraint := range table.Constraints {
|
for _, constraint := range sortConstraints(table.Constraints) {
|
||||||
if constraint.Type != models.ForeignKeyConstraint {
|
if constraint.Type != models.ForeignKeyConstraint {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ func (w *Writer) addRelationshipFields(modelData *ModelData, table *models.Table
|
|||||||
continue // Skip self
|
continue // Skip self
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, constraint := range otherTable.Constraints {
|
for _, constraint := range sortConstraints(otherTable.Constraints) {
|
||||||
if constraint.Type != models.ForeignKeyConstraint {
|
if constraint.Type != models.ForeignKeyConstraint {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,6 +213,21 @@ func resolveFieldNameCollision(fieldName string) string {
|
|||||||
return fieldName
|
return fieldName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sortConstraints sorts constraints by sequence, then by name
|
||||||
|
func sortConstraints(constraints map[string]*models.Constraint) []*models.Constraint {
|
||||||
|
result := make([]*models.Constraint, 0, len(constraints))
|
||||||
|
for _, c := range constraints {
|
||||||
|
result = append(result, c)
|
||||||
|
}
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
if result[i].Sequence > 0 && result[j].Sequence > 0 {
|
||||||
|
return result[i].Sequence < result[j].Sequence
|
||||||
|
}
|
||||||
|
return result[i].Name < result[j].Name
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// sortColumns sorts columns by sequence, then by name
|
// sortColumns sorts columns by sequence, then by name
|
||||||
func sortColumns(columns map[string]*models.Column) []*models.Column {
|
func sortColumns(columns map[string]*models.Column) []*models.Column {
|
||||||
result := make([]*models.Column, 0, len(columns))
|
result := make([]*models.Column, 0, len(columns))
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ func (w *Writer) addRelationshipFields(modelData *ModelData, table *models.Table
|
|||||||
usedFieldNames := make(map[string]int)
|
usedFieldNames := make(map[string]int)
|
||||||
|
|
||||||
// For each foreign key in this table, add a belongs-to relationship
|
// For each foreign key in this table, add a belongs-to relationship
|
||||||
for _, constraint := range table.Constraints {
|
for _, constraint := range sortConstraints(table.Constraints) {
|
||||||
if constraint.Type != models.ForeignKeyConstraint {
|
if constraint.Type != models.ForeignKeyConstraint {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -269,7 +269,7 @@ func (w *Writer) addRelationshipFields(modelData *ModelData, table *models.Table
|
|||||||
continue // Skip self
|
continue // Skip self
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, constraint := range otherTable.Constraints {
|
for _, constraint := range sortConstraints(otherTable.Constraints) {
|
||||||
if constraint.Type != models.ForeignKeyConstraint {
|
if constraint.Type != models.ForeignKeyConstraint {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ Table admin.audit_logs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Relationships
|
// Relationships
|
||||||
Ref: public.posts.user_id > public.users.id [ondelete: CASCADE, onupdate: CASCADE]
|
Ref: public.posts.user_id > public.users.id [delete: CASCADE, update: CASCADE]
|
||||||
Ref: public.comments.post_id > public.posts.id [ondelete: CASCADE]
|
Ref: public.comments.post_id > public.posts.id [delete: CASCADE]
|
||||||
Ref: public.comments.user_id > public.users.id [ondelete: SET NULL]
|
Ref: public.comments.user_id > public.users.id [delete: SET NULL]
|
||||||
Ref: admin.audit_logs.user_id > public.users.id [ondelete: SET NULL]
|
Ref: admin.audit_logs.user_id > public.users.id [delete: SET NULL]
|
||||||
|
|||||||
Reference in New Issue
Block a user