Skip to content

Commit c0f357c

Browse files
committed
fix: update Canton release process to fetch top 5 versions, enhancing version management and preventing duplicate tags
🤖 Generated with GitHub Actions
1 parent 95bae9b commit c0f357c

File tree

3 files changed

+164
-120
lines changed

3 files changed

+164
-120
lines changed

.github/workflows/update-canton.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ name: Check and Release Canton Updates
33
on:
44
schedule:
55
# Run every 12 hours
6-
- cron: '0 */12 * * *'
6+
- cron: "0 */12 * * *"
77
workflow_dispatch: # Allow manual triggering
88

99
jobs:
1010
check-and-release:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: write
14-
14+
1515
steps:
16-
- name: Checkout repository
17-
uses: actions/checkout@v4
18-
with:
19-
token: ${{ secrets.GITHUB_TOKEN }}
20-
21-
- name: Run Canton update script
22-
run: ./update.sh
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
fetch-depth: 0 # Fetch full history including tags
21+
fetch-tags: true
22+
23+
- name: Run Canton update script
24+
run: ./update.sh
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Formula/canton.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ class Canton < Formula
33
homepage "https://www.canton.network/"
44
license "Apache-2.0"
55

6-
url "https://github.com/digital-asset/daml/releases/download/v3.4.0-snapshot.20250723.0/canton-open-source-3.4.0-snapshot.20250715.16432.0.vcd4fe703.tar.gz"
7-
sha256 "04f33ccadd9651b4be8fbbbd0c33039795a8ee86e3e07d2d9955200bce4ce74a"
8-
version "3.4.0-snapshot.20250715.16432.0.vcd4fe703"
6+
url "https://github.com/digital-asset/daml/releases/download/v3.4.0-snapshot.20250709.0/canton-open-source-3.4.0-snapshot.20250624.16258.0.v3144db49.tar.gz"
7+
sha256 "8fd4026e3e80d8edffb1855dc20c1545bb718e6a20393c1f3b09b747578b7c29"
8+
version "3.4.0-snapshot.20250624.16258.0.v3144db49"
99

1010
# Java 11+ is required (recommend 17 for best compatibility)
1111
depends_on "openjdk@17" => :recommended
@@ -40,7 +40,7 @@ def caveats
4040

4141
# Test that Java is available (required for Canton to run)
4242
java_version = shell_output("java -version 2>&1")
43-
assert_match(/version "3.4.0-snapshot.20250715.16432.0.vcd4fe703"[1-9][0-9]"/, java_version)
43+
assert_match(/version "[1-9][0-9]"/, java_version)
4444

4545
# Test that Canton can show help (basic functionality test)
4646
output = shell_output("#{bin}/canton --help 2>&1", 0)

update.sh

Lines changed: 147 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -17,113 +17,121 @@ else
1717
echo "Current version: $CURRENT_VERSION"
1818
fi
1919

20-
# Get latest snapshot release from Digital Asset
21-
echo "Fetching latest Canton snapshot release from Digital Asset..."
22-
LATEST_RELEASE=$(curl -s "https://api.github.com/repos/digital-asset/daml/releases" | \
23-
jq -r '[.[] | select(.prerelease == true) | select(.assets[] | select(.name | contains("canton-open-source") and endswith(".tar.gz")))][0]')
20+
# Get top 5 releases from Digital Asset that contain Canton
21+
echo "Fetching top 5 Canton releases from Digital Asset..."
22+
ALL_RELEASES=$(curl -s "https://api.github.com/repos/digital-asset/daml/releases" | \
23+
jq -r '[.[] | select(.assets[] | select(.name | contains("canton-open-source") and endswith(".tar.gz")))] | .[0:5]')
2424

25-
if [ "$LATEST_RELEASE" = "null" ]; then
26-
echo "No Canton snapshot release found"
25+
if [ "$ALL_RELEASES" = "null" ] || [ "$ALL_RELEASES" = "[]" ]; then
26+
echo "No Canton releases found"
2727
exit 0
2828
fi
2929

30-
LATEST_VERSION=$(echo "$LATEST_RELEASE" | jq -r '.assets[] | select(.name | contains("canton-open-source") and endswith(".tar.gz")) | .name' | sed 's/canton-open-source-\(.*\)\.tar\.gz/\1/')
31-
LATEST_URL=$(echo "$LATEST_RELEASE" | jq -r '.html_url')
32-
DOWNLOAD_URL=$(echo "$LATEST_RELEASE" | jq -r '.assets[] | select(.name | contains("canton-open-source") and endswith(".tar.gz")) | .browser_download_url')
33-
34-
echo "Latest version: $LATEST_VERSION"
35-
36-
# Check if we need to update
37-
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
38-
echo "Already up to date"
39-
exit 0
40-
fi
41-
42-
echo "New version available: $LATEST_VERSION"
43-
44-
# Download and calculate SHA256
45-
echo "Downloading $DOWNLOAD_URL to calculate SHA256..."
46-
if command -v wget >/dev/null 2>&1; then
47-
wget -q "$DOWNLOAD_URL" -O canton-release.tar.gz
48-
else
49-
curl -s -L "$DOWNLOAD_URL" -o canton-release.tar.gz
50-
fi
51-
52-
# Calculate SHA256 (different command on macOS vs Linux)
53-
if [[ "$OSTYPE" == "darwin"* ]]; then
54-
SHA256=$(shasum -a 256 canton-release.tar.gz | cut -d' ' -f1)
55-
else
56-
SHA256=$(sha256sum canton-release.tar.gz | cut -d' ' -f1)
57-
fi
58-
echo "SHA256: $SHA256"
59-
60-
# Cleanup
61-
rm -f canton-release.tar.gz
62-
63-
# Update formula
64-
echo "Updating Formula/canton.rb..."
65-
# Use different sed syntax for macOS vs Linux
66-
if [[ "$OSTYPE" == "darwin"* ]]; then
67-
# macOS
68-
sed -i '' "s|url \"https://github\.com/digital-asset/daml/releases/download/[^\"]*\"|url \"$DOWNLOAD_URL\"|" Formula/canton.rb
69-
sed -i '' "s|sha256 \"[a-f0-9]\{64\}\"|sha256 \"$SHA256\"|" Formula/canton.rb
70-
sed -i '' "s|version \"[^\"]*\"|version \"$LATEST_VERSION\"|" Formula/canton.rb
71-
else
72-
# Linux
73-
sed -i "s|url \"https://github\.com/digital-asset/daml/releases/download/[^\"]*\"|url \"$DOWNLOAD_URL\"|" Formula/canton.rb
74-
sed -i "s|sha256 \"[a-f0-9]\{64\}\"|sha256 \"$SHA256\"|" Formula/canton.rb
75-
sed -i "s|version \"[^\"]*\"|version \"$LATEST_VERSION\"|" Formula/canton.rb
76-
fi
77-
78-
# Only commit and create release if running in CI (GITHUB_TOKEN is set)
79-
if [ -n "$GITHUB_TOKEN" ]; then
80-
echo "Running in CI, checking for changes and creating release..."
81-
82-
# Configure git
83-
git config --local user.email "action@github.com"
84-
git config --local user.name "GitHub Action"
85-
86-
# Add formula changes
87-
git add Formula/canton.rb
88-
89-
# Check if there are any changes to commit
90-
if git diff --cached --quiet; then
91-
echo "No changes detected in Formula/canton.rb, skipping commit"
30+
# Get existing tags to avoid duplicates
31+
echo "Checking existing tags..."
32+
EXISTING_TAGS=$(git tag -l | sed 's/^canton-//' || echo "")
33+
34+
# Process each of the top 5 releases
35+
printf "Processing top 5 Canton releases...\n"
36+
PROCESSED_COUNT=0
37+
PROCESSED_VERSIONS=""
38+
39+
# Use process substitution to avoid subshell issues
40+
while IFS= read -r release; do
41+
VERSION=$(echo "$release" | jq -r '.assets[] | select(.name | contains("canton-open-source") and endswith(".tar.gz")) | .name' | sed 's/canton-open-source-\(.*\)\.tar\.gz/\1/')
42+
RELEASE_URL=$(echo "$release" | jq -r '.html_url')
43+
DOWNLOAD_URL=$(echo "$release" | jq -r '.assets[] | select(.name | contains("canton-open-source") and endswith(".tar.gz")) | .browser_download_url')
44+
45+
printf "\n=== Processing Canton version: %s ===\n" "$VERSION"
46+
47+
# Check if this version already exists as a tag or was already processed
48+
if echo "$EXISTING_TAGS" | grep -q "^$VERSION$"; then
49+
echo "Tag canton-$VERSION already exists, skipping..."
50+
continue
51+
fi
52+
53+
# Check if we already processed this version in this run
54+
if echo "$PROCESSED_VERSIONS" | grep -q "$VERSION"; then
55+
echo "Version $VERSION already processed in this run, skipping..."
56+
continue
57+
fi
58+
59+
PROCESSED_VERSIONS="$PROCESSED_VERSIONS $VERSION"
60+
61+
echo "New version found: $VERSION"
62+
63+
# Download and calculate SHA256
64+
echo "Downloading $DOWNLOAD_URL to calculate SHA256..."
65+
TEMP_FILE="canton-release-$VERSION.tar.gz"
66+
if command -v wget >/dev/null 2>&1; then
67+
wget -q "$DOWNLOAD_URL" -O "$TEMP_FILE"
9268
else
93-
echo "Changes detected, committing and pushing..."
94-
# Commit formula changes
95-
if ! git commit -m "feat: update Canton to $LATEST_VERSION
96-
97-
Release URL: $LATEST_URL
98-
99-
🤖 Generated with GitHub Actions"; then
100-
echo "Failed to commit changes"
101-
exit 1
69+
curl -s -L "$DOWNLOAD_URL" -o "$TEMP_FILE"
70+
fi
71+
72+
# Calculate SHA256 (different command on macOS vs Linux)
73+
if [[ "$OSTYPE" == "darwin"* ]]; then
74+
SHA256=$(shasum -a 256 "$TEMP_FILE" | cut -d' ' -f1)
75+
else
76+
SHA256=$(sha256sum "$TEMP_FILE" | cut -d' ' -f1)
77+
fi
78+
echo "SHA256: $SHA256"
79+
80+
# Cleanup temp file
81+
rm -f "$TEMP_FILE"
82+
83+
# Update formula with this version (only for the first/latest version)
84+
if [ $PROCESSED_COUNT -eq 0 ]; then
85+
echo "Updating Formula/canton.rb with latest version..."
86+
# Use different sed syntax for macOS vs Linux
87+
if [[ "$OSTYPE" == "darwin"* ]]; then
88+
# macOS
89+
sed -i '' "s|url \"https://github\.com/digital-asset/daml/releases/download/[^\"]*\"|url \"$DOWNLOAD_URL\"|" Formula/canton.rb
90+
sed -i '' "s|sha256 \"[a-f0-9]\{64\}\"|sha256 \"$SHA256\"|" Formula/canton.rb
91+
sed -i '' "s|version \"[^\"]*\"|version \"$VERSION\"|" Formula/canton.rb
92+
else
93+
# Linux
94+
sed -i "s|url \"https://github\.com/digital-asset/daml/releases/download/[^\"]*\"|url \"$DOWNLOAD_URL\"|" Formula/canton.rb
95+
sed -i "s|sha256 \"[a-f0-9]\{64\}\"|sha256 \"$SHA256\"|" Formula/canton.rb
96+
sed -i "s|version \"[^\"]*\"|version \"$VERSION\"|" Formula/canton.rb
10297
fi
98+
fi
10399

104-
if ! git push; then
105-
echo "Failed to push changes"
106-
exit 1
100+
# Only commit and create release if running in CI (GITHUB_TOKEN is set)
101+
if [ -n "$GITHUB_TOKEN" ]; then
102+
echo "Running in CI, creating release for $VERSION..."
103+
104+
# Configure git (only once)
105+
if [ $PROCESSED_COUNT -eq 0 ]; then
106+
git config --local user.email "action@github.com"
107+
git config --local user.name "GitHub Action"
107108
fi
108-
109-
# Create GitHub release and tag
110-
if ! git tag "canton-$LATEST_VERSION"; then
111-
echo "Failed to create tag"
112-
exit 1
109+
110+
# Create GitHub release and tag for this version
111+
if ! git tag "canton-$VERSION"; then
112+
echo "Failed to create tag for $VERSION"
113+
continue
113114
fi
114-
115-
if ! git push origin "canton-$LATEST_VERSION"; then
116-
echo "Failed to push tag"
117-
exit 1
115+
116+
if ! git push origin "canton-$VERSION"; then
117+
echo "Failed to push tag for $VERSION"
118+
continue
118119
fi
120+
121+
# Determine if this should be marked as latest (first processed version)
122+
LATEST_FLAG=""
123+
if [ $PROCESSED_COUNT -eq 0 ]; then
124+
LATEST_FLAG="--latest"
125+
fi
126+
127+
if ! gh release create "canton-$VERSION" \
128+
--title "Canton $VERSION" \
129+
--notes "Homebrew formula for Canton version $VERSION.
119130
120-
if ! gh release create "canton-$LATEST_VERSION" \
121-
--title "Canton $LATEST_VERSION" \
122-
--notes "Homebrew formula updated to Canton version $LATEST_VERSION.
123-
124-
This release tracks the Canton snapshot release from Digital Asset:
125-
- Original Release: $LATEST_URL
126-
- Canton Version: $LATEST_VERSION
131+
This release tracks the Canton release from Digital Asset:
132+
- Original Release: $RELEASE_URL
133+
- Canton Version: $VERSION
134+
- SHA256: $SHA256
127135
128136
Install with:
129137
\`\`\`bash
@@ -137,18 +145,52 @@ brew install 0xsend/homebrew-canton/canton
137145
\`\`\`
138146
139147
🤖 Auto-generated by GitHub Actions" \
140-
--latest; then
141-
echo "Failed to create GitHub release"
142-
exit 1
148+
$LATEST_FLAG; then
149+
echo "Failed to create GitHub release for $VERSION"
150+
continue
143151
fi
152+
153+
echo "Successfully created release for Canton $VERSION"
154+
else
155+
echo "Running locally, found version $VERSION"
156+
echo "- URL: $DOWNLOAD_URL"
157+
echo "- SHA256: $SHA256"
158+
fi
159+
160+
PROCESSED_COUNT=$((PROCESSED_COUNT + 1))
161+
done < <(echo "$ALL_RELEASES" | jq -c '.[]')
144162

145-
echo "Successfully created release for Canton $LATEST_VERSION"
163+
# Commit formula changes if running in CI and we processed any versions
164+
if [ -n "$GITHUB_TOKEN" ] && [ "$PROCESSED_COUNT" -gt 0 ]; then
165+
printf "\nCommitting formula changes...\n"
166+
git add Formula/canton.rb
167+
168+
# Check if there are any changes to commit
169+
if ! git diff --cached --quiet; then
170+
if ! git commit -m "feat: update Canton formula to latest versions
171+
172+
Processed $PROCESSED_COUNT Canton releases
173+
174+
🤖 Generated with GitHub Actions"; then
175+
echo "Failed to commit formula changes"
176+
exit 1
177+
fi
178+
179+
if ! git push; then
180+
echo "Failed to push formula changes"
181+
exit 1
182+
fi
183+
184+
echo "Successfully committed formula changes"
185+
else
186+
echo "No formula changes to commit"
146187
fi
188+
fi
189+
190+
if [ "$PROCESSED_COUNT" -eq 0 ]; then
191+
printf "\nNo new Canton versions to process\n"
147192
else
148-
echo "Running locally, formula updated but not committing"
149-
echo "Updated formula to Canton $LATEST_VERSION"
150-
echo "- URL: $DOWNLOAD_URL"
151-
echo "- SHA256: $SHA256"
193+
printf "\nProcessed %d new Canton versions\n" "$PROCESSED_COUNT"
152194
fi
153195

154-
echo "=== Update complete ==="
196+
echo "=== Canton release scan complete ==="

0 commit comments

Comments
 (0)