Check for Upstream Releases #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Check for Upstream Releases | |
| on: | |
| schedule: | |
| # Check for new releases once a day at midnight UTC | |
| - cron: '0 0 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| force_build: | |
| description: 'Force build regardless of version check' | |
| required: false | |
| default: 'false' | |
| jobs: | |
| check-release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| actions: write | |
| packages: read | |
| outputs: | |
| should_build: ${{ steps.check.outputs.should_build }} | |
| new_version: ${{ steps.check.outputs.new_version }} | |
| old_version: ${{ steps.check.outputs.old_version }} | |
| steps: | |
| - name: Get latest release info from upstream | |
| id: upstream | |
| run: | | |
| # Fetch latest release from anomalyco/opencode | |
| RELEASE_JSON=$(curl -s -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/anomalyco/opencode/releases/latest) | |
| VERSION=$(echo "$RELEASE_JSON" | jq -r '.tag_name') | |
| echo "Latest upstream version: $VERSION" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Check if we need to build | |
| id: check | |
| run: | | |
| # Fetch latest upstream version | |
| UPSTREAM_VERSION="${{ steps.upstream.outputs.version }}" | |
| # Query GHCR for existing image tags - use repo-level packages API | |
| TAGS_RESPONSE=$(curl -s -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| "https://api.github.com/repos/${{ github.repository }}/packages/container/opencode-server-docker/versions") | |
| echo "GHCR response: $TAGS_RESPONSE" | |
| # Find the latest upstream-* tag | |
| CURRENT_VERSION=$(echo "$TAGS_RESPONSE" | jq -r '.[] | .metadata.container.tags[]' 2>/dev/null | grep '^upstream-' | head -1 | sed 's/upstream-//') | |
| echo "Current built version: $CURRENT_VERSION" | |
| echo "Latest upstream version: $UPSTREAM_VERSION" | |
| # For manual dispatch or if no previous version, always build | |
| if [ "${{ github.event.inputs.force_build }}" == "true" ] || [ -z "$CURRENT_VERSION" ]; then | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT | |
| echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "No previous version found or force build enabled. Will build." | |
| exit 0 | |
| fi | |
| # Compare versions | |
| if [ "$CURRENT_VERSION" != "$UPSTREAM_VERSION" ]; then | |
| echo "should_build=true" >> $GITHUB_OUTPUT | |
| echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT | |
| echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "New version detected: $UPSTREAM_VERSION (was: $CURRENT_VERSION)" | |
| else | |
| echo "should_build=false" >> $GITHUB_OUTPUT | |
| echo "new_version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT | |
| echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT | |
| echo "No new version. Already at: $CURRENT_VERSION" | |
| fi | |
| trigger-build: | |
| needs: check-release | |
| if: needs.check-release.outputs.should_build == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| actions: write | |
| steps: | |
| - name: Trigger Docker build workflow | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const workflowId = 'docker-build.yml'; | |
| // Get the workflow run URL | |
| const response = await github.rest.actions.createWorkflowDispatch({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| workflow_id: workflowId, | |
| ref: 'main', | |
| inputs: { | |
| triggered_by: 'upstream-release', | |
| upstream_version: '${{ needs.check-release.outputs.new_version }}', | |
| previous_version: '${{ needs.check-release.outputs.old_version }}' | |
| } | |
| }); | |
| console.log('Triggered Docker build for version: ${{ needs.check-release.outputs.new_version }}'); |