-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·136 lines (117 loc) · 4.59 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·136 lines (117 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
set -euo pipefail
VERSION="${1:-}"
TITLE="${2:-}"
if [[ -z "$VERSION" ]]; then
echo "Usage: ./release.sh <version> [title]"
echo "Example: ./release.sh 1.2.3"
echo "Example: ./release.sh 1.2.3 \"Some Catchy Name\""
exit 1
fi
# Strip leading 'v' if provided — version numbers in files are bare,
# git tag gets the v prefix
VERSION="${VERSION#v}"
TAG="v$VERSION"
TITLE="${TITLE:-$TAG}"
# Auto-detect project name from meson.build
PROJECT_NAME=$(grep -oP "^project\(\s*'\K[^']+" meson.build)
if [[ -z "$PROJECT_NAME" ]]; then
echo "ERROR: Could not detect project name from meson.build"
exit 1
fi
echo "==> Releasing $PROJECT_NAME $TAG"
# 1. Update version in meson.build and PKGBUILD
sed -i "0,/version: '[^']*'/{s/version: '[^']*'/version: '$VERSION'/}" meson.build
sed -i "s/^pkgver=.*/pkgver=$VERSION/" PKGBUILD
# 2. Generate release notes before tagging
PREV_TAG=$(git tag --sort=-version:refname | head -1)
if [[ -n "$PREV_TAG" ]]; then
RELEASE_NOTES=$(git log --pretty=format:"- %s" "$PREV_TAG..HEAD" | grep -v -E "^- (Release |first commit)")
else
RELEASE_NOTES=$(git log --pretty=format:"- %s" | grep -v -E "^- (Release |first commit)")
fi
echo "==> Release notes:"
echo "$RELEASE_NOTES"
# 3. Commit (if there are changes) and tag
git add meson.build PKGBUILD
if ! git diff --cached --quiet; then
git commit -m "Release $TAG"
else
echo "==> Version already set to $VERSION, skipping commit"
fi
git tag "$TAG"
# 4. Push commit and tag to all remotes
for remote in $(git remote); do
echo "==> Pushing to $remote"
git push "$remote" HEAD "$TAG"
done
# 4. Build Arch package
echo "==> Building Arch package"
makepkg -sf --noconfirm
ARCH_PKG=$(ls -t ./*.pkg.tar.zst 2>/dev/null | grep -v debug | head -1)
# 5. Create releases
RELEASE_ASSETS=()
[[ -n "${ARCH_PKG:-}" ]] && RELEASE_ASSETS+=("$ARCH_PKG")
# GitHub release — find the github remote by URL
GITHUB_REMOTE=""
for remote in $(git remote); do
if git remote get-url "$remote" 2>/dev/null | grep -q github.com; then
GITHUB_REMOTE="$remote"
break
fi
done
if [[ -n "$GITHUB_REMOTE" ]] && command -v gh &>/dev/null; then
echo "==> Creating GitHub release (remote: $GITHUB_REMOTE)"
GH_REPO=$(git remote get-url "$GITHUB_REMOTE" | sed 's|.*github.com[:/]||;s|\.git$||')
gh release create "$TAG" "${RELEASE_ASSETS[@]}" \
--repo "$GH_REPO" \
--title "$TITLE" \
--notes "$RELEASE_NOTES"
echo "==> GitHub release created"
fi
# Forgejo release via API
REMOTE_URL=$(git remote get-url origin 2>/dev/null || true)
# Parse hostname and repo path from both ssh:// and scp-style URLs
if [[ "$REMOTE_URL" =~ ^ssh://[^@]+@([^/]+)/(.+)$ ]]; then
FORGEJO_URL="${BASH_REMATCH[1]}"
REPO_PATH="${BASH_REMATCH[2]%.git}"
elif [[ "$REMOTE_URL" =~ ^[^@]+@([^:]+):(.+)$ ]]; then
FORGEJO_URL="${BASH_REMATCH[1]}"
REPO_PATH="${BASH_REMATCH[2]%.git}"
else
FORGEJO_URL=""
REPO_PATH=""
fi
if [[ -n "$FORGEJO_URL" && -n "${FORGEJO_TOKEN:-}" ]]; then
echo "==> Creating Forgejo release on $FORGEJO_URL ($REPO_PATH)"
# Check if release already exists for this tag
EXISTING=$(curl -s "https://$FORGEJO_URL/api/v1/repos/$REPO_PATH/releases/tags/$TAG" \
-H "Authorization: token $FORGEJO_TOKEN")
EXISTING_ID=$(echo "$EXISTING" | jq -r '.id // empty')
if [[ -n "$EXISTING_ID" ]]; then
echo "==> Release for $TAG already exists (id=$EXISTING_ID), deleting..."
curl -s -X DELETE "https://$FORGEJO_URL/api/v1/repos/$REPO_PATH/releases/$EXISTING_ID" \
-H "Authorization: token $FORGEJO_TOKEN"
fi
COMMIT_SHA=$(git rev-parse HEAD)
RELEASE_JSON=$(curl -s -X POST "https://$FORGEJO_URL/api/v1/repos/$REPO_PATH/releases" \
-H "Authorization: token $FORGEJO_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg tag "$TAG" --arg title "$TITLE" --arg body "$RELEASE_NOTES" --arg sha "$COMMIT_SHA" \
'{tag_name: $tag, name: $title, body: $body, target_commitish: $sha}')")
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r '.id')
if [[ "$RELEASE_ID" != "null" && -n "$RELEASE_ID" ]]; then
for asset in "${RELEASE_ASSETS[@]}"; do
echo "==> Uploading $asset to Forgejo"
curl -s -X POST "https://$FORGEJO_URL/api/v1/repos/$REPO_PATH/releases/$RELEASE_ID/assets" \
-H "Authorization: token $FORGEJO_TOKEN" \
-F "attachment=@$asset"
done
echo "==> Forgejo release created"
else
echo "WARNING: Failed to create Forgejo release"
echo "$RELEASE_JSON"
fi
fi
echo ""
echo "==> Done! Released $PROJECT_NAME $TAG"