@@ -2,7 +2,6 @@ name: Check for Upstream Releases
22
33on :
44 schedule :
5- # Check for new releases once a day at midnight UTC
65 - cron : ' 0 0 * * *'
76 workflow_dispatch :
87 inputs :
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 }}
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
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
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,
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 }}');
0 commit comments