Skip to content

Commit 4ebea31

Browse files
ci: query GHCR for existing image tags to detect version
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent b4f645f commit 4ebea31

1 file changed

Lines changed: 19 additions & 21 deletions

File tree

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
permissions:
1818
contents: read
1919
actions: write
20+
packages: read
2021
outputs:
2122
should_build: ${{ steps.check.outputs.should_build }}
2223
new_version: ${{ steps.check.outputs.new_version }}
@@ -38,43 +39,40 @@ jobs:
3839
- name: Check if we need to build
3940
id: check
4041
run: |
41-
CURRENT_VERSION=""
42+
# Fetch latest upstream version
43+
UPSTREAM_VERSION="${{ steps.upstream.outputs.version }}"
4244
43-
# Try to get the last built version from git tags
44-
if git rev-parse last-built-version >/dev/null 2>&1; then
45-
CURRENT_VERSION=$(git rev-parse last-built-version)
46-
fi
45+
# Query GHCR for existing image tags
46+
# Need package:read permission for this
47+
TAGS_RESPONSE=$(curl -s -H "Accept: application/vnd.github+json" \
48+
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
49+
-H "X-GitHub-Api-Version: 2022-11-28" \
50+
"https://api.github.com/orgs/${{ github.repository_owner }}/packages/container/${{ github.repository }}/versions")
4751
48-
# Also check if there's a recent Docker image tag
49-
if [ -z "$CURRENT_VERSION" ]; then
50-
# Try GitHub API to get existing image tags
51-
TAGS_JSON=$(curl -s -H "Accept: application/vnd.github+json" \
52-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
53-
-H "X-GitHub-Api-Version: 2022-11-28" \
54-
https://api.github.com/repos/${{ github.repository }}/git/refs/tags)
55-
56-
# Get the most recent tag that matches anomalyco version pattern
57-
CURRENT_VERSION=$(echo "$TAGS_JSON" | jq -r '.[] | select(.ref | startswith("refs/tags/anomalyco-")) | .ref' 2>/dev/null | head -1 | sed 's/refs\/tags\/anomalyco-//')
58-
fi
52+
# Find the latest upstream-* tag
53+
CURRENT_VERSION=$(echo "$TAGS_RESPONSE" | jq -r '.[] | select(.metadata.container.tags[]? | startswith("upstream-")) | .metadata.container.tags[]' 2>/dev/null | head -1 | sed 's/upstream-//')
54+
55+
echo "Current built version: $CURRENT_VERSION"
56+
echo "Latest upstream version: $UPSTREAM_VERSION"
5957
6058
# For manual dispatch or if no previous version, always build
6159
if [ "${{ github.event.inputs.force_build }}" == "true" ] || [ -z "$CURRENT_VERSION" ]; then
6260
echo "should_build=true" >> $GITHUB_OUTPUT
63-
echo "new_version=${{ steps.upstream.outputs.version }}" >> $GITHUB_OUTPUT
61+
echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
6462
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
6563
echo "No previous version found or force build enabled. Will build."
6664
exit 0
6765
fi
6866
6967
# Compare versions
70-
if [ "$CURRENT_VERSION" != "${{ steps.upstream.outputs.version }}" ]; then
68+
if [ "$CURRENT_VERSION" != "$UPSTREAM_VERSION" ]; then
7169
echo "should_build=true" >> $GITHUB_OUTPUT
72-
echo "new_version=${{ steps.upstream.outputs.version }}" >> $GITHUB_OUTPUT
70+
echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
7371
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
74-
echo "New version detected: ${{ steps.upstream.outputs.version }} (was: $CURRENT_VERSION)"
72+
echo "New version detected: $UPSTREAM_VERSION (was: $CURRENT_VERSION)"
7573
else
7674
echo "should_build=false" >> $GITHUB_OUTPUT
77-
echo "new_version=${{ steps.upstream.outputs.version }}" >> $GITHUB_OUTPUT
75+
echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
7876
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
7977
echo "No new version. Already at: $CURRENT_VERSION"
8078
fi

0 commit comments

Comments
 (0)