Update OpenCode #42
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: Update OpenCode | |
| on: | |
| schedule: | |
| - cron: '0 17 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| update-opencode: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: cachix/install-nix-action@v31 | |
| with: | |
| nix_path: nixpkgs=channel:nixos-unstable | |
| - name: Check for updates | |
| id: check | |
| run: | | |
| LATEST_VERSION=$(curl -s "https://api.github.com/repos/anomalyco/opencode/releases/latest" | \ | |
| grep -oP '"tag_name":\s*"v\K[^"]+') | |
| if [ -z "$LATEST_VERSION" ]; then | |
| echo "Could not find latest version." | |
| exit 1 | |
| fi | |
| LATEST_VERSION="${LATEST_VERSION#v}" | |
| CURRENT_VERSION=$(grep -oP '"version":\s*"\K[^"]+' version.json) | |
| echo "Latest: $LATEST_VERSION" | |
| echo "Current: $CURRENT_VERSION" | |
| if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then | |
| echo "New version available!" | |
| echo "update_needed=true" >> $GITHUB_OUTPUT | |
| echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT | |
| else | |
| echo "Already up to date." | |
| echo "update_needed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update Flake | |
| if: steps.check.outputs.update_needed == 'true' | |
| run: | | |
| chmod +x ./update-version.sh | |
| ./update-version.sh "${{ steps.check.outputs.version }}" | |
| - name: Update flake.lock | |
| if: steps.check.outputs.update_needed == 'true' | |
| run: nix flake update | |
| - name: Verify Flake | |
| if: steps.check.outputs.update_needed == 'true' | |
| run: | | |
| nix flake check --no-build | |
| nix build .#opencode --no-link | |
| - name: Commit and Push | |
| if: steps.check.outputs.update_needed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add version.json opencode.nix opencode-desktop.nix flake.lock | |
| git commit -m "chore: update opencode to ${{ steps.check.outputs.version }}" | |
| git push |