|
| 1 | +name: Update cagent version |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [cagent-release] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: "cagent version (e.g., v1.28.1). Leave empty to use latest release." |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + update-version: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + HAS_APP_SECRETS: ${{ secrets.CAGENT_REVIEWER_APP_ID != '' }} |
| 18 | + steps: |
| 19 | + - name: Generate GitHub App token |
| 20 | + if: env.HAS_APP_SECRETS == 'true' |
| 21 | + id: app-token |
| 22 | + continue-on-error: true |
| 23 | + uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2 |
| 24 | + with: |
| 25 | + app_id: ${{ secrets.CAGENT_REVIEWER_APP_ID }} |
| 26 | + private_key: ${{ secrets.CAGENT_REVIEWER_APP_PRIVATE_KEY }} |
| 27 | + |
| 28 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 29 | + with: |
| 30 | + token: ${{ steps.app-token.outputs.token || secrets.RELEASE_TOKEN }} |
| 31 | + |
| 32 | + - name: Determine version |
| 33 | + id: version |
| 34 | + env: |
| 35 | + DISPATCH_VERSION: ${{ github.event.client_payload.version }} |
| 36 | + INPUT_VERSION: ${{ inputs.version }} |
| 37 | + GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.RELEASE_TOKEN }} |
| 38 | + run: | |
| 39 | + if [ -n "$INPUT_VERSION" ]; then |
| 40 | + VERSION="$INPUT_VERSION" |
| 41 | + echo "Using manual input version: $VERSION" |
| 42 | + elif [ -n "$DISPATCH_VERSION" ]; then |
| 43 | + VERSION="$DISPATCH_VERSION" |
| 44 | + echo "Using dispatched version: $VERSION" |
| 45 | + else |
| 46 | + echo "No version specified, fetching latest release from docker/cagent..." |
| 47 | + VERSION=$(gh release view --repo docker/cagent --json tagName --jq '.tagName') |
| 48 | + echo "Latest release: $VERSION" |
| 49 | + fi |
| 50 | +
|
| 51 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 52 | +
|
| 53 | + - name: Validate version exists |
| 54 | + env: |
| 55 | + GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.RELEASE_TOKEN }} |
| 56 | + VERSION: ${{ steps.version.outputs.version }} |
| 57 | + run: | |
| 58 | + echo "Validating that $VERSION exists as a release on docker/cagent..." |
| 59 | + if ! gh release view "$VERSION" --repo docker/cagent > /dev/null 2>&1; then |
| 60 | + echo "❌ Release $VERSION not found on docker/cagent" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + echo "✅ Release $VERSION exists" |
| 64 | +
|
| 65 | + - name: Check current version |
| 66 | + id: check |
| 67 | + env: |
| 68 | + VERSION: ${{ steps.version.outputs.version }} |
| 69 | + run: | |
| 70 | + CURRENT=$(cat CAGENT_VERSION | tr -d '[:space:]') |
| 71 | + echo "Current version: $CURRENT" |
| 72 | + echo "Target version: $VERSION" |
| 73 | +
|
| 74 | + if [ "$CURRENT" = "$VERSION" ]; then |
| 75 | + echo "Already up to date, nothing to do." |
| 76 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 77 | + else |
| 78 | + echo "Version update needed: $CURRENT → $VERSION" |
| 79 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 80 | + echo "current=$CURRENT" >> "$GITHUB_OUTPUT" |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Update CAGENT_VERSION |
| 84 | + if: steps.check.outputs.skip != 'true' |
| 85 | + env: |
| 86 | + VERSION: ${{ steps.version.outputs.version }} |
| 87 | + run: | |
| 88 | + echo "$VERSION" > CAGENT_VERSION |
| 89 | + echo "Updated CAGENT_VERSION to $VERSION" |
| 90 | +
|
| 91 | + - name: Create or update PR |
| 92 | + if: steps.check.outputs.skip != 'true' |
| 93 | + env: |
| 94 | + GH_TOKEN: ${{ steps.app-token.outputs.token || secrets.RELEASE_TOKEN }} |
| 95 | + VERSION: ${{ steps.version.outputs.version }} |
| 96 | + CURRENT: ${{ steps.check.outputs.current }} |
| 97 | + run: | |
| 98 | + BRANCH="auto/update-cagent-version" |
| 99 | + RELEASE_URL="https://github.com/docker/cagent/releases/tag/$VERSION" |
| 100 | +
|
| 101 | + # Configure git |
| 102 | + git config user.name "github-actions[bot]" |
| 103 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 104 | +
|
| 105 | + # Create or reset branch |
| 106 | + git checkout -B "$BRANCH" |
| 107 | + git add CAGENT_VERSION |
| 108 | + git commit -m "chore: update cagent to $VERSION" |
| 109 | +
|
| 110 | + # Force-push to handle both new and existing branches. |
| 111 | + # This branch is exclusively managed by this workflow, so --force is safe. |
| 112 | + git push --force origin "$BRANCH" |
| 113 | +
|
| 114 | + # Check if a PR already exists for this branch |
| 115 | + EXISTING_PR=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number') |
| 116 | +
|
| 117 | + if [ -n "$EXISTING_PR" ]; then |
| 118 | + echo "Updating existing PR #$EXISTING_PR" |
| 119 | + gh pr edit "$EXISTING_PR" \ |
| 120 | + --title "chore: update cagent to $VERSION" \ |
| 121 | + --body "$(cat <<EOF |
| 122 | + ## Summary |
| 123 | + Updates \`CAGENT_VERSION\` from \`$CURRENT\` to \`$VERSION\`. |
| 124 | + - **Release**: [$VERSION]($RELEASE_URL) |
| 125 | + - **Triggered by**: \`${{ github.event_name }}\` |
| 126 | + > Auto-generated by the [update-cagent-version](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow. |
| 127 | + EOF |
| 128 | + )" |
| 129 | + else |
| 130 | + echo "Creating new PR" |
| 131 | + gh pr create \ |
| 132 | + --title "chore: update cagent to $VERSION" \ |
| 133 | + --body "$(cat <<EOF |
| 134 | + ## Summary |
| 135 | + Updates \`CAGENT_VERSION\` from \`$CURRENT\` to \`$VERSION\`. |
| 136 | + - **Release**: [$VERSION]($RELEASE_URL) |
| 137 | + - **Triggered by**: \`${{ github.event_name }}\` |
| 138 | + > Auto-generated by the [update-cagent-version](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) workflow. |
| 139 | + EOF |
| 140 | + )" \ |
| 141 | + --label "kind/dependencies" |
| 142 | + fi |
0 commit comments