Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions .github/workflows/update-opencode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ on:
schedule:
# Run every 6 hours at 15 minutes past (avoids peak times)
# Times: 00:15, 06:15, 12:15, 18:15 UTC
- cron: '15 */6 * * *'
- cron: "15 */6 * * *"
workflow_dispatch:
inputs:
version:
description: 'Specific version to update to (optional)'
description: "Specific version to update to (optional)"
required: false
type: string

Expand All @@ -28,23 +28,23 @@ permissions:
jobs:
update-opencode:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

- name: Set up Nix
uses: cachix/install-nix-action@v24
with:
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
experimental-features = nix-command flakes

- name: Install nix-update
run: nix profile install nixpkgs#nix-update

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
Expand All @@ -56,12 +56,12 @@ jobs:
CURRENT_VERSION=$(grep -o 'version = "[^"]*"' package.nix | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version: $CURRENT_VERSION"

- name: Update OpenCode with nix-update
id: update-check
run: |
echo "Running nix-update for OpenCode..."

# Run nix-update using the configured updateScript
if nix-update opencode --use-update-script --build; then
# Check if any files were actually changed
Expand All @@ -85,7 +85,7 @@ jobs:
run: |
MANUAL_VERSION="${{ github.event.inputs.version }}"
CURRENT_VERSION="${{ steps.current-version.outputs.current-version }}"

if [ "$CURRENT_VERSION" = "$MANUAL_VERSION" ]; then
echo "Already at requested version: $MANUAL_VERSION"
echo "has-changes=false" >> $GITHUB_OUTPUT
Expand All @@ -107,36 +107,35 @@ jobs:
NEW_VERSION="${{ steps.update-check.outputs.new-version }}"
BRANCH_NAME="update-opencode-${NEW_VERSION}-$(date +%s)"
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT

echo "Creating branch: $BRANCH_NAME"
git checkout -b "$BRANCH_NAME"

echo "Committing changes"
git add .
git commit -m "Update OpenCode to version $NEW_VERSION
- Updated version and all platform-specific hashes
- Updated subpackage dependencies (tui, node_modules)
- Automated update via nix-update"

- Updated version and all platform-specific hashes
- Updated subpackage dependencies (tui, node_modules)
- Automated update via nix-update"

- name: Create tag on branch
if: steps.update-check.outputs.has-changes == 'true'
run: |
NEW_VERSION="${{ steps.update-check.outputs.new-version }}"
echo "Creating tag v$NEW_VERSION"
git tag -a "v$NEW_VERSION" -m "OpenCode Flake version $NEW_VERSION"

- name: Merge branch to master
if: steps.update-check.outputs.has-changes == 'true'
id: merge-branch
run: |
BRANCH_NAME="${{ steps.create-branch.outputs.branch-name }}"
echo "Switching to master and merging $BRANCH_NAME"

# Switch to master and ensure it's up to date
git checkout ${{ github.ref_name }}
git pull origin ${{ github.ref_name }}

# Attempt fast-forward merge
if git merge "$BRANCH_NAME" --ff-only; then
echo "Successfully merged $BRANCH_NAME to master"
Expand All @@ -150,22 +149,22 @@ jobs:
echo "The update branch $BRANCH_NAME contains the changes and can be manually reviewed."
exit 1
fi

- name: Handle merge failure
if: failure() && steps.merge-branch.outputs.merge-success == 'false'
run: |
echo "Merge failed - the update was successful but couldn't be automatically merged."
echo "Branch ${{ steps.create-branch.outputs.branch-name }} contains the updates."
echo "Manual intervention may be required to resolve conflicts."

- name: Push changes and tags
if: steps.update-check.outputs.has-changes == 'true'
run: |
NEW_VERSION="${{ steps.update-check.outputs.new-version }}"
echo "Pushing master and tags"
git push origin ${{ github.ref_name }}
git push origin "v$NEW_VERSION"

- name: Create GitHub Release
if: steps.update-check.outputs.has-changes == 'true'
uses: softprops/action-gh-release@v1
Expand All @@ -174,27 +173,27 @@ jobs:
name: OpenCode Flake ${{ steps.update-check.outputs.new-version }}
body: |
OpenCode Flake version ${{ steps.update-check.outputs.new-version }}

This release packages [OpenCode](https://github.com/sst/opencode) v${{ steps.update-check.outputs.new-version }} as a Nix flake.

**Automated Update**: This version was automatically updated using nix-update, ensuring all dependencies and hashes are correct.

## Installation

```bash
# Run OpenCode directly
nix run github:AodhanHayter/opencode-flake

# Or install to your profile
nix profile install github:AodhanHayter/opencode-flake
```

## Using in a flake

```nix
{
inputs.opencode-flake.url = "github:AodhanHayter/opencode-flake";

outputs = { self, nixpkgs, opencode-flake, ... }: {
# Use in your outputs
packages.x86_64-linux.opencode = opencode-flake.packages.x86_64-linux.default;
Expand All @@ -203,7 +202,7 @@ jobs:
```
draft: false
prerelease: false

- name: Cleanup update branch
if: always() && steps.create-branch.outputs.branch-name
run: |
Expand All @@ -224,4 +223,4 @@ jobs:
echo "🏷️ Created tag and GitHub release"
else
echo "ℹ️ No updates needed - already at latest version"
fi
fi