-
Notifications
You must be signed in to change notification settings - Fork 4
97 lines (80 loc) · 3.17 KB
/
update-copilot-dependency.yml
File metadata and controls
97 lines (80 loc) · 3.17 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
name: "Update @github/copilot Dependency"
on:
workflow_dispatch:
inputs:
version:
description: 'Target version of @github/copilot (e.g. 1.0.24)'
required: true
type: string
permissions:
contents: write
pull-requests: write
jobs:
update:
name: "Update @github/copilot to ${{ inputs.version }}"
runs-on: ubuntu-latest
steps:
- name: Validate version input
env:
VERSION: ${{ inputs.version }}
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$ ]]; then
echo "::error::Invalid version format '$VERSION'. Expected semver (e.g. 1.0.24)."
exit 1
fi
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6
with:
node-version: 22
- name: Update @github/copilot in scripts/codegen
env:
VERSION: ${{ inputs.version }}
working-directory: ./scripts/codegen
# npm install updates package.json and package-lock.json to the new
# version; npm ci (below) then does a clean, reproducible install from
# the updated lock file. Both steps are required: npm install alone
# leaves leftover packages, while npm ci alone cannot change the pinned
# version in the lock file.
run: npm install "@github/copilot@$VERSION"
- name: Install codegen dependencies
working-directory: ./scripts/codegen
run: npm ci
- name: Run codegen
working-directory: ./scripts/codegen
run: npm run generate
- name: Create pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ inputs.version }}
run: |
BRANCH="update-copilot-$VERSION"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
git checkout "$BRANCH"
git reset --hard HEAD
else
git checkout -b "$BRANCH"
fi
git add -A
if git diff --cached --quiet; then
echo "No changes detected; skipping commit and PR creation."
exit 0
fi
git commit -m "Update @github/copilot to $VERSION
- Updated @github/copilot in scripts/codegen
- Re-ran Java code generator"
git push origin "$BRANCH" --force-with-lease
if gh pr view "$BRANCH" >/dev/null 2>&1; then
echo "Pull request for branch '$BRANCH' already exists; updated branch only."
else
gh pr create \
--title "Update @github/copilot to $VERSION" \
--body "Automated update of \`@github/copilot\` to version \`$VERSION\`.
### Changes
- Updated \`@github/copilot\` in \`scripts/codegen/package.json\`
- Re-ran Java code generator (\`scripts/codegen\`)
> Created by the **Update @github/copilot Dependency** workflow." \
--base main \
--head "$BRANCH"
fi