-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (138 loc) · 6.63 KB
/
check-opencode-updates.yml
File metadata and controls
168 lines (138 loc) · 6.63 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Check for OpenCode Desktop updates
on:
schedule:
# Run daily at 6:00 AM UTC
- cron: '0 6 * * *'
workflow_dispatch:
# Allow manual triggering
jobs:
check-update:
runs-on: ubuntu-latest
outputs:
update_needed: ${{ steps.check.outputs.update_needed }}
latest_version: ${{ steps.check.outputs.latest_version }}
current_version: ${{ steps.check.outputs.current_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get current version
id: current
run: |
CURRENT_VERSION=$(grep 'version = "' flake.nix | head -1 | sed 's/.*version = "\(.*\)".*/\1/')
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"
- name: Check for latest release
id: check
run: |
CURRENT_VERSION="${{ steps.current.outputs.current_version }}"
# Get latest release from GitHub API
LATEST_RELEASE=$(curl -s https://api.github.com/repos/anomalyco/opencode/releases/latest)
LATEST_VERSION=$(echo "$LATEST_RELEASE" | grep '"tag_name":' | sed 's/.*"tag_name": "v\(.*\)".*/\1/')
echo "Latest version: $LATEST_VERSION"
echo "Current version: $CURRENT_VERSION"
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "Update needed: $CURRENT_VERSION -> $LATEST_VERSION"
echo "update_needed=true" >> $GITHUB_OUTPUT
else
echo "No update needed"
echo "update_needed=false" >> $GITHUB_OUTPUT
fi
update-flake:
needs: check-update
runs-on: ubuntu-latest
if: ${{ needs.check-update.outputs.update_needed == 'true' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v12
- name: Calculate new hashes
id: hashes
run: |
VERSION="${{ needs.check-update.outputs.latest_version }}"
# Calculate hashes for all platforms (convert base32 to SRI format)
echo "Calculating hashes for version $VERSION..."
# Function to fetch and convert hash
fetch_hash() {
local url="$1"
local raw_hash
raw_hash=$(nix-prefetch-url "$url" 2>&1 | tail -1)
if [ -z "$raw_hash" ]; then
echo "ERROR: Failed to fetch hash for $url" >&2
exit 1
fi
nix hash convert --hash-algo sha256 --to sri "$raw_hash"
}
HASH_AMD64=$(fetch_hash "https://github.com/anomalyco/opencode/releases/download/v${VERSION}/opencode-desktop-linux-amd64.deb")
HASH_ARM64=$(fetch_hash "https://github.com/anomalyco/opencode/releases/download/v${VERSION}/opencode-desktop-linux-arm64.deb")
HASH_DARWIN_AARCH64=$(fetch_hash "https://github.com/anomalyco/opencode/releases/download/v${VERSION}/opencode-desktop-darwin-aarch64.app.tar.gz")
HASH_DARWIN_X64=$(fetch_hash "https://github.com/anomalyco/opencode/releases/download/v${VERSION}/opencode-desktop-darwin-x64.app.tar.gz")
echo "hash_amd64=$HASH_AMD64" >> $GITHUB_OUTPUT
echo "hash_arm64=$HASH_ARM64" >> $GITHUB_OUTPUT
echo "hash_darwin_aarch64=$HASH_DARWIN_AARCH64" >> $GITHUB_OUTPUT
echo "hash_darwin_x64=$HASH_DARWIN_X64" >> $GITHUB_OUTPUT
echo "Calculated hashes:"
echo " x86_64-linux: $HASH_AMD64"
echo " aarch64-linux: $HASH_ARM64"
echo " aarch64-darwin: $HASH_DARWIN_AARCH64"
echo " x86_64-darwin: $HASH_DARWIN_X64"
- name: Update flake.nix
run: |
VERSION="${{ needs.check-update.outputs.latest_version }}"
# Update version
sed -i "s/version = \".*\";/version = \"${VERSION}\";/" flake.nix
# Update hashes using Python for proper multi-line handling
python3 << 'EOF'
import re
with open('flake.nix', 'r') as f:
content = f.read()
# Hash mapping by platform
hashes = {
'x86_64-linux': '${{ steps.hashes.outputs.hash_amd64 }}',
'aarch64-linux': '${{ steps.hashes.outputs.hash_arm64 }}',
'aarch64-darwin': '${{ steps.hashes.outputs.hash_darwin_aarch64 }}',
'x86_64-darwin': '${{ steps.hashes.outputs.hash_darwin_x64 }}'
}
# Update each platform's hash
for platform, hash_val in hashes.items():
pattern = rf'({platform} = \{{[^}}]+hash = )"sha256-[^"]+"'
replacement = rf'\1"{hash_val}"'
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
with open('flake.nix', 'w') as f:
f.write(content)
print("Updated hashes:")
for platform, hash_val in hashes.items():
print(f" {platform}: {hash_val}")
EOF
# Show changes
git diff flake.nix
- name: Verify flake builds
run: |
# Verify the flake evaluates correctly
echo "Checking flake evaluation..."
nix flake check --no-build
# Try to build for x86_64-linux to verify hashes are correct
echo "Building package to verify hashes..."
nix build .#default --system x86_64-linux --no-link
echo "Flake verification passed!"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: bump opencode-desktop to ${{ needs.check-update.outputs.latest_version }}"
title: "chore: bump opencode-desktop to ${{ needs.check-update.outputs.latest_version }}"
body: |
Automated update of OpenCode Desktop.
**Changes:**
- Version: ${{ needs.check-update.outputs.current_version }} → ${{ needs.check-update.outputs.latest_version }}
- Updated hashes for all platforms:
- x86_64-linux
- aarch64-linux
- aarch64-darwin
- x86_64-darwin
This PR was generated automatically by the update-check workflow.
Please review the changes before merging.
branch: update/opencode-desktop-${{ needs.check-update.outputs.latest_version }}
delete-branch: true