Check for OpenCode Desktop updates #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |