|
| 1 | +name: "Update @github/copilot Dependency" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Target version of @github/copilot (e.g. 1.0.24)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + update: |
| 17 | + name: "Update @github/copilot to ${{ inputs.version }}" |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Validate version input |
| 21 | + env: |
| 22 | + VERSION: ${{ inputs.version }} |
| 23 | + run: | |
| 24 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$ ]]; then |
| 25 | + echo "::error::Invalid version format '$VERSION'. Expected semver (e.g. 1.0.24)." |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +
|
| 29 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 30 | + |
| 31 | + - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 |
| 32 | + with: |
| 33 | + node-version: 22 |
| 34 | + |
| 35 | + - name: Update @github/copilot in scripts/codegen |
| 36 | + env: |
| 37 | + VERSION: ${{ inputs.version }} |
| 38 | + working-directory: ./scripts/codegen |
| 39 | + run: npm install "@github/copilot@$VERSION" |
| 40 | + |
| 41 | + - name: Install codegen dependencies |
| 42 | + working-directory: ./scripts/codegen |
| 43 | + run: npm ci |
| 44 | + |
| 45 | + - name: Run codegen |
| 46 | + working-directory: ./scripts/codegen |
| 47 | + run: npm run generate |
| 48 | + |
| 49 | + - name: Create pull request |
| 50 | + env: |
| 51 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + VERSION: ${{ inputs.version }} |
| 53 | + run: | |
| 54 | + BRANCH="update-copilot-$VERSION" |
| 55 | + git config user.name "github-actions[bot]" |
| 56 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 57 | +
|
| 58 | + if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then |
| 59 | + git checkout "$BRANCH" |
| 60 | + git reset --hard HEAD |
| 61 | + else |
| 62 | + git checkout -b "$BRANCH" |
| 63 | + fi |
| 64 | +
|
| 65 | + git add -A |
| 66 | +
|
| 67 | + if git diff --cached --quiet; then |
| 68 | + echo "No changes detected; skipping commit and PR creation." |
| 69 | + exit 0 |
| 70 | + fi |
| 71 | +
|
| 72 | + git commit -m "Update @github/copilot to $VERSION |
| 73 | +
|
| 74 | + - Updated @github/copilot in scripts/codegen |
| 75 | + - Re-ran Java code generator" |
| 76 | + git push origin "$BRANCH" --force-with-lease |
| 77 | +
|
| 78 | + if gh pr view "$BRANCH" >/dev/null 2>&1; then |
| 79 | + echo "Pull request for branch '$BRANCH' already exists; updated branch only." |
| 80 | + else |
| 81 | + gh pr create \ |
| 82 | + --title "Update @github/copilot to $VERSION" \ |
| 83 | + --body "Automated update of \`@github/copilot\` to version \`$VERSION\`. |
| 84 | +
|
| 85 | + ### Changes |
| 86 | + - Updated \`@github/copilot\` in \`scripts/codegen/package.json\` |
| 87 | + - Re-ran Java code generator (\`scripts/codegen\`) |
| 88 | +
|
| 89 | + > Created by the **Update @github/copilot Dependency** workflow." \ |
| 90 | + --base main \ |
| 91 | + --head "$BRANCH" |
| 92 | + fi |
0 commit comments