-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (103 loc) · 5.05 KB
/
check-opencode-updates.yml
File metadata and controls
126 lines (103 loc) · 5.05 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
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 by line number (lines 30, 34, 38, 42)
sed -i '30s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.hash_amd64 }}"|' flake.nix
sed -i '34s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.hash_arm64 }}"|' flake.nix
sed -i '38s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.hash_darwin_aarch64 }}"|' flake.nix
sed -i '42s|hash = "sha256-[^"]*"|hash = "${{ steps.hashes.outputs.hash_darwin_x64 }}"|' flake.nix
# Show changes
git diff flake.nix
- name: Commit and push changes
run: |
VERSION="${{ needs.check-update.outputs.latest_version }}"
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Commit changes
git add flake.nix
git commit -m "chore: bump opencode-desktop to ${VERSION}"
# Push to main
git push