Skip to content

Commit 6a0139f

Browse files
ci: use GHCR users API to list container versions
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 313ed92 commit 6a0139f

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

.github/workflows/check-upstream-release.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: Check for Upstream Releases
22

33
on:
44
schedule:
5-
# Check for new releases once a day at midnight UTC
65
- cron: '0 0 * * *'
76
workflow_dispatch:
87
inputs:
@@ -16,6 +15,7 @@ jobs:
1615
runs-on: ubuntu-latest
1716
permissions:
1817
contents: read
18+
packages: read
1919
actions: write
2020
outputs:
2121
should_build: ${{ steps.check.outputs.should_build }}
@@ -25,7 +25,6 @@ jobs:
2525
- name: Get latest release info from upstream
2626
id: upstream
2727
run: |
28-
# Fetch latest release from anomalyco/opencode
2928
RELEASE_JSON=$(curl -s -H "Accept: application/vnd.github+json" \
3029
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
3130
-H "X-GitHub-Api-Version: 2022-11-28" \
@@ -38,22 +37,21 @@ jobs:
3837
- name: Check if we need to build
3938
id: check
4039
run: |
41-
# Fetch latest upstream version
4240
UPSTREAM_VERSION="${{ steps.upstream.outputs.version }}"
4341
44-
# Query workflow runs to find the last successful build with upstream version
45-
RUNS_RESPONSE=$(curl -s -H "Accept: application/vnd.github+json" \
42+
OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
43+
PACKAGE_NAME=$(echo "${{ github.repository }}" | sed 's/.*\///' | tr '[:upper:]' '[:lower:]')
44+
45+
TAGS_RESPONSE=$(curl -s -H "Accept: application/vnd.github+json" \
4646
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
4747
-H "X-GitHub-Api-Version: 2022-11-28" \
48-
"https://api.github.com/repos/${{ github.repository }}/actions/runs?status=success&per_page=5")
48+
"https://api.github.com/users/$OWNER_LOWER/packages/container/$PACKAGE_NAME/versions?per_page=100")
4949
50-
# Find the most recent run that was triggered by upstream-release and has upstream_version
51-
CURRENT_VERSION=$(echo "$RUNS_RESPONSE" | jq -r '.workflow_runs[] | select(.display_title? | contains("upstream")) | .inputs.upstream_version // empty' 2>/dev/null | head -1)
50+
CURRENT_VERSION=$(echo "$TAGS_RESPONSE" | jq -r '.[].metadata.container.tags[]' 2>/dev/null | grep '^upstream-' | head -1 | sed 's/upstream-//')
5251
5352
echo "Current built version: $CURRENT_VERSION"
5453
echo "Latest upstream version: $UPSTREAM_VERSION"
5554
56-
# For manual dispatch or if no previous version, always build
5755
if [ "${{ github.event.inputs.force_build }}" == "true" ] || [ -z "$CURRENT_VERSION" ]; then
5856
echo "should_build=true" >> $GITHUB_OUTPUT
5957
echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
@@ -62,7 +60,6 @@ jobs:
6260
exit 0
6361
fi
6462
65-
# Compare versions
6663
if [ "$CURRENT_VERSION" != "$UPSTREAM_VERSION" ]; then
6764
echo "should_build=true" >> $GITHUB_OUTPUT
6865
echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
@@ -88,8 +85,6 @@ jobs:
8885
with:
8986
script: |
9087
const workflowId = 'docker-build.yml';
91-
92-
// Get the workflow run URL
9388
const response = await github.rest.actions.createWorkflowDispatch({
9489
owner: context.repo.owner,
9590
repo: context.repo.repo,
@@ -101,5 +96,4 @@ jobs:
10196
previous_version: '${{ needs.check-release.outputs.old_version }}'
10297
}
10398
});
104-
10599
console.log('Triggered Docker build for version: ${{ needs.check-release.outputs.new_version }}');

.sisyphus/plans/fix-ghcr-api.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Fix: GHCR API for listing container versions
2+
3+
## Context
4+
User wants to check Docker image tags in their own GHCR repo. Previous attempts used wrong API endpoints.
5+
6+
## Plan
7+
8+
### Task 1: Fix GHCR API call
9+
10+
**What to do**: Use correct GHCR API endpoint for user-owned packages
11+
- Endpoint: `GET /users/{owner}/packages/container/{package_name}/versions`
12+
- Add `packages: read` permission back
13+
14+
**Files**: `.github/workflows/check-upstream-release.yml`
15+
16+
**QA Scenarios**:
17+
- Verify API returns container version tags
18+
- Verify upstream-* tag is detected correctly

0 commit comments

Comments
 (0)