-
Notifications
You must be signed in to change notification settings - Fork 0
168 lines (141 loc) · 6.96 KB
/
Copy pathupdate-gh-cli.yml
File metadata and controls
168 lines (141 loc) · 6.96 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Update CLI Versions
on:
schedule:
# 毎日9時 (JST) に実行
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
update-cli-versions:
name: Update CLI Versions
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Check for GitHub CLI updates
id: check-gh
env:
GH_TOKEN: ${{ github.token }}
run: |
# 最新バージョンを取得
LATEST_VERSION=$(gh release view --repo cli/cli --json tagName -q '.tagName' | sed 's/^v//')
echo "latest_version=${LATEST_VERSION}" >> $GITHUB_OUTPUT
# 現在のバージョンを取得
CURRENT_VERSION=$(jq -r '.gh_cli_version' .github/versions.json)
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
# バージョン比較
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "update_available=true" >> $GITHUB_OUTPUT
echo "::notice::New GitHub CLI version available: ${LATEST_VERSION} (current: ${CURRENT_VERSION})"
else
echo "update_available=false" >> $GITHUB_OUTPUT
echo "::notice::GitHub CLI is up to date: ${CURRENT_VERSION}"
fi
- name: Check for Copilot CLI updates
id: check-copilot
env:
GH_TOKEN: ${{ github.token }}
run: |
# 最新バージョンを取得
LATEST_VERSION=$(gh release view --repo github/copilot-cli --json tagName -q '.tagName' | sed 's/^v//')
echo "latest_version=${LATEST_VERSION}" >> $GITHUB_OUTPUT
# 現在のバージョンを取得
CURRENT_VERSION=$(jq -r '.copilot_cli_version' .github/versions.json)
echo "current_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
# バージョン比較
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
echo "update_available=true" >> $GITHUB_OUTPUT
echo "::notice::New Copilot CLI version available: ${LATEST_VERSION} (current: ${CURRENT_VERSION})"
else
echo "update_available=false" >> $GITHUB_OUTPUT
echo "::notice::Copilot CLI is up to date: ${CURRENT_VERSION}"
fi
- name: Update versions.json
id: update
if: steps.check-gh.outputs.update_available == 'true' || steps.check-copilot.outputs.update_available == 'true'
run: |
# 更新内容を構築
UPDATES=""
if [ "${{ steps.check-gh.outputs.update_available }}" == "true" ]; then
jq '.gh_cli_version = "${{ steps.check-gh.outputs.latest_version }}"' .github/versions.json > .github/versions.json.tmp
mv .github/versions.json.tmp .github/versions.json
UPDATES="gh-cli-${{ steps.check-gh.outputs.latest_version }}"
fi
if [ "${{ steps.check-copilot.outputs.update_available }}" == "true" ]; then
jq '.copilot_cli_version = "${{ steps.check-copilot.outputs.latest_version }}"' .github/versions.json > .github/versions.json.tmp
mv .github/versions.json.tmp .github/versions.json
if [ -n "$UPDATES" ]; then
UPDATES="${UPDATES}_copilot-cli-${{ steps.check-copilot.outputs.latest_version }}"
else
UPDATES="copilot-cli-${{ steps.check-copilot.outputs.latest_version }}"
fi
fi
echo "branch_suffix=${UPDATES}" >> $GITHUB_OUTPUT
- name: Create Pull Request
if: steps.check-gh.outputs.update_available == 'true' || steps.check-copilot.outputs.update_available == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
BRANCH_NAME="automated/update-cli-${{ steps.update.outputs.branch_suffix }}"
# PR タイトルと本文を構築
TITLE=""
BODY="## Summary\n\nThis PR updates CLI versions used in E2E tests.\n\n| CLI | Current | New |\n|-----|---------|-----|\n"
if [ "${{ steps.check-gh.outputs.update_available }}" == "true" ]; then
TITLE="GitHub CLI v${{ steps.check-gh.outputs.latest_version }}"
BODY="${BODY}| GitHub CLI | v${{ steps.check-gh.outputs.current_version }} | v${{ steps.check-gh.outputs.latest_version }} |\n"
fi
if [ "${{ steps.check-copilot.outputs.update_available }}" == "true" ]; then
if [ -n "$TITLE" ]; then
TITLE="${TITLE}, Copilot CLI v${{ steps.check-copilot.outputs.latest_version }}"
else
TITLE="Copilot CLI v${{ steps.check-copilot.outputs.latest_version }}"
fi
BODY="${BODY}| Copilot CLI | v${{ steps.check-copilot.outputs.current_version }} | v${{ steps.check-copilot.outputs.latest_version }} |\n"
fi
TITLE="chore(deps): update ${TITLE}"
BODY="${BODY}\n## Release Notes\n\n"
if [ "${{ steps.check-gh.outputs.update_available }}" == "true" ]; then
BODY="${BODY}- [GitHub CLI v${{ steps.check-gh.outputs.latest_version }}](https://github.com/cli/cli/releases/tag/v${{ steps.check-gh.outputs.latest_version }})\n"
fi
if [ "${{ steps.check-copilot.outputs.update_available }}" == "true" ]; then
BODY="${BODY}- [Copilot CLI v${{ steps.check-copilot.outputs.latest_version }}](https://github.com/github/copilot-cli/releases/tag/v${{ steps.check-copilot.outputs.latest_version }})\n"
fi
BODY="${BODY}\n---\n*This PR was automatically created by the [Update CLI Versions workflow](../actions/workflows/update-gh-cli.yml).*"
# 変更をコミット
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# ブランチ名を決定(既存の場合は連番を付与)
BASE_BRANCH_NAME="automated/update-cli-${{ steps.update.outputs.branch_suffix }}"
BRANCH_NAME="$BASE_BRANCH_NAME"
COUNTER=1
while git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; do
COUNTER=$((COUNTER + 1))
BRANCH_NAME="${BASE_BRANCH_NAME}-${COUNTER}"
done
if [ "$BRANCH_NAME" != "$BASE_BRANCH_NAME" ]; then
echo "::notice::Using branch name: ${BRANCH_NAME}"
fi
git checkout -b "$BRANCH_NAME"
git add .github/versions.json
git commit -m "${TITLE}"
git push origin "$BRANCH_NAME"
# PRを作成
PR_URL=$(echo -e "$BODY" | gh pr create \
--title "${TITLE}" \
--body-file - \
--base main \
--head "$BRANCH_NAME")
# PR番号とブランチ名をファイルに保存(workflow_run トリガーで使用)
PR_NUMBER=$(echo "$PR_URL" | grep -oE '[0-9]+$')
echo "Created PR #${PR_NUMBER} on branch ${BRANCH_NAME}"
mkdir -p ./pr-info
echo "$PR_NUMBER" > ./pr-info/pr_number
echo "$BRANCH_NAME" > ./pr-info/branch_name
- name: Upload PR number
if: steps.check-gh.outputs.update_available == 'true' || steps.check-copilot.outputs.update_available == 'true'
uses: actions/upload-artifact@v7
with:
name: pr-info
path: pr-info/