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