Skip to content

Commit b1e54fc

Browse files
ci: add upstream release checker workflow
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent e2bca04 commit b1e54fc

2 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Check for Upstream Releases
2+
3+
on:
4+
schedule:
5+
# Check for new releases once a day at midnight UTC
6+
- cron: '0 0 * * *'
7+
workflow_dispatch:
8+
inputs:
9+
force_build:
10+
description: 'Force build regardless of version check'
11+
required: false
12+
default: 'false'
13+
14+
jobs:
15+
check-release:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
should_build: ${{ steps.check.outputs.should_build }}
19+
new_version: ${{ steps.check.outputs.new_version }}
20+
old_version: ${{ steps.check.outputs.old_version }}
21+
steps:
22+
- name: Get latest release info from upstream
23+
id: upstream
24+
run: |
25+
# Fetch latest release from anomalyco/opencode
26+
RELEASE_JSON=$(curl -s -H "Accept: application/vnd.github+json" \
27+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
28+
-H "X-GitHub-Api-Version: 2022-11-28" \
29+
https://api.github.com/repos/anomalyco/opencode/releases/latest)
30+
31+
VERSION=$(echo "$RELEASE_JSON" | jq -r '.tag_name')
32+
echo "Latest upstream version: $VERSION"
33+
echo "version=$VERSION" >> $GITHUB_OUTPUT
34+
35+
- name: Check if we need to build
36+
id: check
37+
run: |
38+
CURRENT_VERSION=""
39+
40+
# Try to get the last built version from git tags
41+
if git rev-parse last-built-version >/dev/null 2>&1; then
42+
CURRENT_VERSION=$(git rev-parse last-built-version)
43+
fi
44+
45+
# Also check if there's a recent Docker image tag
46+
if [ -z "$CURRENT_VERSION" ]; then
47+
# Try GitHub API to get existing image tags
48+
TAGS_JSON=$(curl -s -H "Accept: application/vnd.github+json" \
49+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
50+
-H "X-GitHub-Api-Version: 2022-11-28" \
51+
https://api.github.com/repos/${{ github.repository }}/git/refs/tags)
52+
53+
# Get the most recent tag that matches anomalyco version pattern
54+
CURRENT_VERSION=$(echo "$TAGS_JSON" | jq -r '.[] | select(.ref | startswith("refs/tags/anomalyco-")) | .ref' 2>/dev/null | head -1 | sed 's/refs\/tags\/anomalyco-//')
55+
fi
56+
57+
# For manual dispatch or if no previous version, always build
58+
if [ "${{ github.event.inputs.force_build }}" == "true" ] || [ -z "$CURRENT_VERSION" ]; then
59+
echo "should_build=true" >> $GITHUB_OUTPUT
60+
echo "new_version=${{ steps.upstream.outputs.version }}" >> $GITHUB_OUTPUT
61+
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
62+
echo "No previous version found or force build enabled. Will build."
63+
exit 0
64+
fi
65+
66+
# Compare versions
67+
if [ "$CURRENT_VERSION" != "${{ steps.upstream.outputs.version }}" ]; then
68+
echo "should_build=true" >> $GITHUB_OUTPUT
69+
echo "new_version=${{ steps.upstream.outputs.version }}" >> $GITHUB_OUTPUT
70+
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
71+
echo "New version detected: ${{ steps.upstream.outputs.version }} (was: $CURRENT_VERSION)"
72+
else
73+
echo "should_build=false" >> $GITHUB_OUTPUT
74+
echo "new_version=${{ steps.upstream.outputs.version }}" >> $GITHUB_OUTPUT
75+
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
76+
echo "No new version. Already at: $CURRENT_VERSION"
77+
fi
78+
79+
trigger-build:
80+
needs: check-release
81+
if: needs.check-release.outputs.should_build == 'true'
82+
runs-on: ubuntu-latest
83+
steps:
84+
- name: Trigger Docker build workflow
85+
uses: actions/github-script@v7
86+
with:
87+
script: |
88+
const workflowId = 'docker-build.yml';
89+
90+
// Get the workflow run URL
91+
const response = await github.rest.actions.createWorkflowDispatch({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
workflow_id: workflowId,
95+
ref: 'main',
96+
inputs: {
97+
triggered_by: 'upstream-release',
98+
upstream_version: '${{ needs.check-release.outputs.new_version }}',
99+
previous_version: '${{ needs.check-release.outputs.old_version }}'
100+
}
101+
});
102+
103+
console.log('Triggered Docker build for version: ${{ needs.check-release.outputs.new_version }}');

.github/workflows/docker-build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ on:
66
tags: ["v*"]
77
pull_request:
88
branches: ["main"]
9+
workflow_dispatch:
10+
inputs:
11+
triggered_by:
12+
description: 'What triggered this build'
13+
required: false
14+
default: 'manual'
15+
upstream_version:
16+
description: 'Upstream version from anomalyco/opencode'
17+
required: false
18+
default: ''
19+
previous_version:
20+
description: 'Previous upstream version'
21+
required: false
22+
default: ''
923

1024
env:
1125
REGISTRY: ghcr.io
@@ -37,6 +51,15 @@ jobs:
3751
uses: docker/metadata-action@v5
3852
with:
3953
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54+
tags: |
55+
type=ref,event=branch
56+
type=ref,event=pr
57+
type=semver,pattern={{version}}
58+
type=semver,pattern={{major}}.{{minor}}
59+
type=semver,pattern={{major}}
60+
type=raw,value=${{ github.sha }},enable=${{ github.event_name == 'pull_request' }}
61+
type=raw,value=upstream-${{ github.event.inputs.upstream_version }},enable=${{ github.event.inputs.upstream_version != '' }}
62+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
4063
4164
- name: Build and push Docker image
4265
uses: docker/build-push-action@v5

0 commit comments

Comments
 (0)