Skip to content
Closed

Main #1778

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
3e1fca0
Tommy/tool-specific-config-support (#1394)
tommaso-moro Nov 26, 2025
4d6d64e
Add AI issue assessment workflow with github/ai-assessment-comment-la…
Copilot Nov 28, 2025
9c73e88
Tommy/server-config-docs (#1495)
tommaso-moro Nov 28, 2025
ada4bc0
Add ai_review_label to ai-issue-assessment.yml (#1501)
Copilot Nov 28, 2025
60aef5d
Convert to `modelcontextprotocol/go-sdk` (#1428)
omgitsads Dec 1, 2025
9b34211
Check if the tool is _NOT_ read only before skipping it in read-only …
omgitsads Dec 1, 2025
fa2d802
Add resource completion for GitHub repository resources (#1493)
omgitsads Dec 1, 2025
8dac9b1
Add proxima config for oauth (#1528)
tonytrg Dec 4, 2025
f197a9f
Add Tool Handler shim to RegisterFunc (#1536)
omgitsads Dec 4, 2025
82c4930
fix: include empty properties in get_me schema for OpenAI compatibility
SamMorrowDrums Dec 8, 2025
cfd7ef9
Correct lower-case issue state (#1567)
almaleksia Dec 10, 2025
90a1255
Trim leading slash in path parameter (#1569)
almaleksia Dec 10, 2025
94ee074
Add support for safe tool renaming (#1563)
tommaso-moro Dec 11, 2025
4cbbf6f
fix: indent multi-line descriptions in generated docs
SamMorrowDrums Dec 11, 2025
5da71e3
fix: update get-me script for go-SDK MCP protocol
SamMorrowDrums Dec 8, 2025
5cd95dc
remove both default and all (#1401)
tommaso-moro Dec 12, 2025
87ea319
fix: handle architecture-specific license differences
SamMorrowDrums Dec 12, 2025
3a1844c
fix: make license script portable and deterministic
SamMorrowDrums Dec 12, 2025
e7e2925
fix: update licenses-check to use new architecture-aware format
SamMorrowDrums Dec 12, 2025
adaa6a1
fix: use LC_ALL=C for consistent sorting across systems
SamMorrowDrums Dec 12, 2025
a48e306
Improvements & refactoring of get_file_contents (#1582)
almaleksia Dec 15, 2025
5a4338c
adding review comments grouped as threads (#1554)
tonytrg Dec 15, 2025
afe34d8
Fix create_or_update SHA-related failures (#1621)
almaleksia Dec 16, 2025
df66613
docs: Add Antigravity installation guide (#1549)
ManoloZocco Dec 16, 2025
637819a
Update docs to include tool renaming guide (#1623)
tommaso-moro Dec 16, 2025
a897d70
Update pr template (#1605)
JoannaaKL Dec 17, 2025
5a42d7a
Chore: Add testify-based HTTP mocking infrastructure and pilot migrat…
Copilot Dec 17, 2025
f32af95
build(deps): bump actions/cache from 4 to 5 (#1609)
dependabot[bot] Dec 17, 2025
ce2e4f9
refactor: Introduce Inventory pattern with builder, filtering, and pe…
SamMorrowDrums Dec 17, 2025
b820435
Fix: path param should be optional (#1631)
almaleksia Dec 17, 2025
bc5d08d
fix: track HTTP status code errors in context for observability (#1630)
SamMorrowDrums Dec 17, 2025
6b3c375
feat: Add Octicon icons to MCP tools, resources, and prompts (#1603)
SamMorrowDrums Dec 17, 2025
97feb5c
update docs generation to populate correct docs, remove redundant doc…
tommaso-moro Dec 17, 2025
3c453dd
refactor: inject deps via context instead of closures
SamMorrowDrums Dec 18, 2025
12af99b
Add endpoint constants and migrate raw package tests
Copilot Dec 17, 2025
c04b287
Migrate security_advisories_test.go to testify mocks
Copilot Dec 17, 2025
b81df99
Migrate actions, dependabot, and secret_scanning tests to testify
Copilot Dec 17, 2025
3b9a0b1
Fix linting issues in helper constants
Copilot Dec 17, 2025
49e606d
Migrate context_tools_test and repository_resource_test to testify
Copilot Dec 17, 2025
1b6f0e0
Fix wildcard path matching for raw content endpoints
Copilot Dec 17, 2025
37a214d
Migrate gists_test.go to testify mocks
Copilot Dec 17, 2025
0eb2d2f
Add comprehensive migration guide for remaining files
Copilot Dec 17, 2025
ac0e79e
Add completion script and enhanced migration guide
Copilot Dec 17, 2025
ba55ecf
Migrate notifications_test.go to testify mocks
Copilot Dec 17, 2025
3c568af
Remove migration guide and completion script
Copilot Dec 17, 2025
9bf5076
Update pkg/github/helper_test.go
JoannaaKL Dec 17, 2025
511121f
add ff saupport and consolidated actions toolsets
mattdholloway Dec 16, 2025
e7f5ca4
update tests
mattdholloway Dec 18, 2025
f325b35
update consolidated actions tools for new handler pattern
mattdholloway Dec 18, 2025
27c1051
update tests
mattdholloway Dec 18, 2025
cc5f536
refine pattern matching logic to prioritise non-wildcard handlers in …
mattdholloway Dec 18, 2025
c0bd7b2
fix ring buffer panic (#1556)
mattdholloway Dec 18, 2025
a8fafad
Omit icon sizes field for backward compatibility
Copilot Dec 18, 2025
311d581
Fix: Add middleware to inject deps into context for tool handlers
Copilot Dec 18, 2025
63c7db0
Add aliases for new actions tools (#1652)
tommaso-moro Dec 19, 2025
b79d126
Add raw client error annotation and annotate GetFileContents (#1570)
omgitsads Dec 19, 2025
844137c
feat: Add DestructiveHint to delete_project_item tool annotation
web-flow Dec 21, 2025
6c0bbb8
chore: Update toolsnap for delete_project_item with destructiveHint
web-flow Dec 21, 2025
2f31c15
`get_file_contents` fetch refs improvements (#1655)
almaleksia Dec 22, 2025
b5be18c
remove experiments toolset
tommaso-moro Dec 22, 2025
f9ef72f
build(deps): bump docker/setup-buildx-action from 3.11.1 to 3.12.0
dependabot[bot] Dec 22, 2025
4f064a3
feat: auto-fix license files on PRs and improve CI reliability (#1583)
SamMorrowDrums Dec 22, 2025
2bfe467
Fix YAML syntax errors in license-check workflow
Copilot Dec 22, 2025
6a3c306
build(deps): bump github.com/google/jsonschema-go from 0.3.0 to 0.4.2
dependabot[bot] Dec 22, 2025
e51e6b1
chore: regenerate license files
github-actions[bot] Dec 22, 2025
6d1ce24
build(deps): bump github.com/modelcontextprotocol/go-sdk
dependabot[bot] Dec 22, 2025
b28d7fb
chore: regenerate license files
github-actions[bot] Dec 22, 2025
8ac1eb4
Use typed IconTheme constants from Go SDK
Copilot Dec 22, 2025
95a637e
Update PR template to include tool renaming section (#1657)
tommaso-moro Dec 23, 2025
a1bc8b6
build(deps): bump github.com/spf13/cobra from 1.10.1 to 1.10.2
dependabot[bot] Dec 22, 2025
7e32623
chore: regenerate license files
github-actions[bot] Dec 22, 2025
9426075
Fallback to default branch in get_file_contents when main doesn't exi…
almaleksia Dec 23, 2025
1f38172
fix: Skip CodeQL scanning on forked repositories
kaovilai Aug 13, 2025
d4da526
build(deps): bump docker/metadata-action from 5.9.0 to 5.10.0
dependabot[bot] Dec 23, 2025
1decd77
remove claude web
tommaso-moro Dec 24, 2025
43bea59
Change list workflow runs to allow empty resource id to list all runs…
mattdholloway Dec 29, 2025
73a8f98
build(deps): bump actions/github-script from 7 to 8
dependabot[bot] Dec 29, 2025
af5a6df
Update README.md to hyperlink Open AI Codex installation guide
s-sanjay Dec 28, 2025
587d829
docs: add Docker image name to Prerequisites section
majiayu000 Dec 30, 2025
953d26f
fix: use gh pr checkout to handle fork PRs in license-check workflow
Copilot Dec 31, 2025
2cc6911
refactor: use consistent snake_case for issue_number parameter
majiayu000 Dec 30, 2025
30712de
docs: regenerate README after parameter rename
majiayu000 Dec 31, 2025
762845a
Add API Error annotations to GitHub issue errors (#1566)
omgitsads Jan 2, 2026
92bdc28
add docs for Rovo Dev CLI installation
atinylittleshell Aug 13, 2025
116c574
fix: filterToolsByName returns all matching tools for feature flag fi…
majiayu000 Jan 1, 2026
cac11f2
exclude tools requiring ff from docs
mattdholloway Jan 2, 2026
6f7bf27
refactor docs toolset gen
mattdholloway Jan 2, 2026
67f3427
Update cmd/github-mcp-server/generate_docs.go
mattdholloway Jan 2, 2026
905a08f
Update cmd/github-mcp-server/generate_docs.go
mattdholloway Jan 2, 2026
2b352ab
Improvements to push_files tool (#1676)
almaleksia Jan 5, 2026
eb6db0f
Add scopes package and update ServerTool struct with scope fields
Copilot Dec 23, 2025
1e5931a
Update most tools with OAuth scope information
Copilot Dec 23, 2025
db9f4e8
Complete OAuth scope implementation for all tools
Copilot Dec 23, 2025
db179be
Simplify scope implementation per feedback
Copilot Dec 23, 2025
c765101
refresh readme after rebase
SamMorrowDrums Jan 5, 2026
7796c08
Add scope hierarchy and auto-derive accepted scopes
SamMorrowDrums Jan 5, 2026
3d1ae30
refres readme after update
SamMorrowDrums Jan 5, 2026
df9fc6a
Use repo scope for star/unstar tools instead of public_repo
SamMorrowDrums Jan 5, 2026
cec5a1a
Fix conflict and regenerate docs after rebase
SamMorrowDrums Jan 5, 2026
48744ca
Sort scope slices for deterministic output
SamMorrowDrums Jan 5, 2026
46b8cb6
Add PAT scope filtering for stdio server
SamMorrowDrums Jan 5, 2026
a19a159
Enable scope filtering by default
SamMorrowDrums Jan 5, 2026
f45b94a
Make scope filtering always enabled (remove flag)
SamMorrowDrums Jan 5, 2026
8afb4fb
Only check scopes for classic PATs (ghp_ prefix)
SamMorrowDrums Jan 5, 2026
39fed35
Remove manual scope-to-tools table from docs
SamMorrowDrums Jan 5, 2026
c2450ce
Update pkg/scopes/filter.go
SamMorrowDrums Jan 5, 2026
acd7929
Document that GitHub App and server-to-server tokens are not filtered
SamMorrowDrums Jan 5, 2026
f14f507
Add tip about editing PAT scopes in GitHub UI
SamMorrowDrums Jan 5, 2026
4deaa83
Remove empty filter.go and document OAuth scope challenges
SamMorrowDrums Jan 5, 2026
9aef435
Fix server-configuration.md scope filtering description
SamMorrowDrums Jan 5, 2026
c809766
Mention OAuth scope challenges in server-configuration.md
SamMorrowDrums Jan 5, 2026
c428f72
Don't filter read-only repo tools (work on public repos without scope)
SamMorrowDrums Jan 5, 2026
7d4a4a6
Document public repo access quirk for read-only tools
SamMorrowDrums Jan 5, 2026
80b0306
Replace go-github-mock with stretchr/testify for actions/issues/proje…
Copilot Jan 6, 2026
66a0164
initial projects consolidation
mattdholloway Dec 31, 2025
3cd0be2
update tool aliases
mattdholloway Dec 31, 2025
304f074
hold-bac feature flag
mattdholloway Jan 5, 2026
7b30c93
update docs
mattdholloway Jan 5, 2026
099f995
revert "hold-bac feature flag"
mattdholloway Jan 5, 2026
be5a449
fix project tools to add scope to newtool init
mattdholloway Jan 5, 2026
a57b472
add http resp code checking for getProjectItem
mattdholloway Jan 6, 2026
71862a9
update tests to use new mock pattern
mattdholloway Jan 6, 2026
ab23070
Update command instructions for terminal usage
floriangrousset Oct 25, 2025
cc9e864
Fix nil pointer dereference in completion handler
SamMorrowDrums Jan 7, 2026
f2ff9d2
updated (#1756)
tommaso-moro Jan 8, 2026
ee8f4e6
Add list-scopes command using inventory architecture
Copilot Jan 6, 2026
d2df189
Add list_scopes.go implementation file
Copilot Jan 6, 2026
cd75b9b
Refactor formatToolsetName to shared helper function
Copilot Jan 6, 2026
33014a6
Add helpers.go with shared formatToolsetName function
Copilot Jan 6, 2026
ff0e67e
Add formatScopeDisplay helper and improve empty scope handling
Copilot Jan 6, 2026
e335503
Update Claude Code installation command to use add-json format for v2…
Copilot Jan 8, 2026
c061804
Use default scope in examples and clarify --scope flag is optional
Copilot Jan 8, 2026
b1ab893
bug fix (#1775)
tommaso-moro Jan 9, 2026
44d9e13
Bringing back local mcp server registry config (#1767)
almaleksia Jan 9, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is the **GitHub MCP Server**, a Model Context Protocol (MCP) server that co
- **Type:** MCP server application with CLI interface
- **Primary Package:** github-mcp-server (stdio MCP server - **this is the main focus**)
- **Secondary Package:** mcpcurl (testing utility - don't break it, but not the priority)
- **Framework:** Uses mark3labs/mcp-go for MCP protocol, google/go-github for GitHub API
- **Framework:** Uses modelcontextprotocol/go-sdk for MCP protocol, google/go-github for GitHub API
- **Size:** ~60MB repository, 70 Go files
- **Library Usage:** This repository is also used as a library by the remote server. Functions that could be called by other repositories should be exported (capitalized), even if not required internally. Preserve existing export patterns.

Expand Down
32 changes: 32 additions & 0 deletions .github/prompts/bug-report-review.prompt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
messages:
- role: system
content: |
You are a triage assistant for the GitHub MCP Server repository. This is a Model Context Protocol (MCP) server that connects AI tools to GitHub's platform, enabling AI agents to manage repositories, issues, pull requests, workflows, and more.

Your job is to analyze bug reports and assess their completeness.

Analyze the issue for these key elements:
1. Clear description of the problem
2. Affected version (from running `docker run -i --rm ghcr.io/github/github-mcp-server ./github-mcp-server --version`)
3. Steps to reproduce the behavior
4. Expected vs actual behavior
5. Relevant logs (if applicable)

Provide ONE of these assessments:

### AI Assessment: Ready for Review
Use when the bug report has most required information and can be triaged by a maintainer.

### AI Assessment: Missing Details
Use when critical information is missing (no reproduction steps, no version info, unclear problem description).

### AI Assessment: Unsure
Use when you cannot determine the completeness of the report.

After your assessment header, provide a brief explanation of your rating.
If details are missing, note which specific sections need more information.
- role: user
content: "{{input}}"
model: openai/gpt-4o-mini
modelParameters:
max_tokens: 500
31 changes: 31 additions & 0 deletions .github/prompts/default-issue-review.prompt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
messages:
- role: system
content: |
You are a triage assistant for the GitHub MCP Server repository. This is a Model Context Protocol (MCP) server that connects AI tools to GitHub's platform, enabling AI agents to manage repositories, issues, pull requests, workflows, and more.

Your job is to analyze new issues and help categorize them.

Analyze the issue to determine:
1. Is this a bug report, feature request, question, or something else?
2. Is the issue clear and well-described?
3. Does it contain enough information for maintainers to act on?

Provide ONE of these assessments:

### AI Assessment: Ready for Review
Use when the issue is clear, well-described, and contains enough context for maintainers to understand and act on it.

### AI Assessment: Missing Details
Use when the issue is unclear, lacks context, or needs more information to be actionable.

### AI Assessment: Unsure
Use when you cannot determine the nature or completeness of the issue.

After your assessment header, provide a brief explanation including:
- What type of issue this appears to be (bug, feature request, question, etc.)
- What additional information might be helpful if any
- role: user
content: "{{input}}"
model: openai/gpt-4o-mini
modelParameters:
max_tokens: 500
56 changes: 48 additions & 8 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,51 @@
<!--
Thank you for contributing to GitHub MCP Server!
Please reference an existing issue: `Closes #NUMBER`

Screenshots or videos of changed behavior is incredibly helpful and always appreciated.
Consider addressing the following:
- Tradeoffs: List tradeoffs you made to take on or pay down tech debt.
- Alternatives: Describe alternative approaches you considered and why you discarded them.
Copilot: Fill all sections. Prefer short, concrete answers.
If a checkbox is selected, add a brief explanation.
-->

Closes:
## Summary
<!-- In 1–2 sentences: what does this PR do? -->

## Why
<!-- Why is this change needed? Link issues or discussions. -->
Fixes #

## What changed
<!-- Bullet list of concrete changes. -->
-
-

## MCP impact
<!-- Select one or more. If selected, add 1–2 sentences. -->
- [ ] No tool or API changes
- [ ] Tool schema or behavior changed
- [ ] New tool added

## Prompts tested (tool changes only)
<!-- If you changed or added tools, list example prompts you tested. -->
<!-- Include prompts that trigger the tool and describe the use case. -->
<!-- Example: "List all open issues in the repo assigned to me" -->
-

## Security / limits
<!-- Select if relevant. Add a short note if checked. -->
- [ ] No security or limits impact
- [ ] Auth / permissions considered
- [ ] Data exposure, filtering, or token/size limits considered

## Tool renaming
- [ ] I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
- [ ] I have added the new tool aliases in `deprecated_tool_aliases.go`
- [ ] I am not renaming tools as part of this PR

Note: if you're renaming tools, you *must* add the tool aliases. For more information on how to do so, please refer to the [official docs](https://github.com/github/github-mcp-server/blob/main/docs/tool-renaming.md).

## Lint & tests
<!-- Check what you ran. If not run, explain briefly. -->
- [ ] Linted locally with `./script/lint`
- [ ] Tested locally with `./script/test`

## Docs

- [ ] Not needed
- [ ] Updated (README / docs / examples)
30 changes: 30 additions & 0 deletions .github/workflows/ai-issue-assessment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: AI Issue Assessment

on:
issues:
types: [opened, labeled]

jobs:
ai-issue-assessment:
if: >
(github.event.action == 'opened' && github.event.issue.labels[0] == null) ||
(github.event.action == 'labeled' && github.event.label.name == 'bug')
runs-on: ubuntu-latest
permissions:
issues: write
models: read
contents: read

steps:
- name: Checkout
uses: actions/checkout@v6

- name: Run AI assessment
uses: github/ai-assessment-comment-labeler@e3bedc38cfffa9179fe4cee8f7ecc93bffb3fee7 # v1.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ai_review_label: 'bug, enhancement'
issue_number: ${{ github.event.issue.number }}
issue_body: ${{ github.event.issue.body }}
prompts_directory: '.github/prompts'
labels_to_prompts_mapping: 'bug,bug-report-review.prompt.yml|default,default-issue-review.prompt.yml'
5 changes: 5 additions & 0 deletions .github/workflows/code-scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Only run on the main repository, not on forks
if: github.repository == 'github/github-mcp-server'
runs-on: ${{ fromJSON(matrix.runner) }}
permissions:
actions: read
Expand Down Expand Up @@ -46,6 +48,9 @@ jobs:
queries: "" # Default query suite
packs: github/ccr-${{ matrix.language }}-queries
config: |
paths-ignore:
- third-party
- third-party-licenses.*.md
default-setup:
org:
model-packs: [ ${{ github.event.inputs.code_scanning_codeql_packs }} ]
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Conformance Test

on:
pull_request:

permissions:
contents: read

jobs:
conformance:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v6
with:
# Fetch full history to access merge-base
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"

- name: Download dependencies
run: go mod download

- name: Run conformance test
id: conformance
run: |
# Run conformance test, capture stdout for summary
script/conformance-test > conformance-summary.txt 2>&1 || true

# Output the summary
cat conformance-summary.txt

# Check result
if grep -q "RESULT: ALL TESTS PASSED" conformance-summary.txt; then
echo "status=passed" >> $GITHUB_OUTPUT
else
echo "status=differences" >> $GITHUB_OUTPUT
fi

- name: Generate Job Summary
run: |
# Add the full markdown report to the job summary
echo "# MCP Server Conformance Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Comparing PR branch against merge-base with \`origin/main\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

# Extract and append the report content (skip the header since we added our own)
tail -n +5 conformance-report/CONFORMANCE_REPORT.md >> $GITHUB_STEP_SUMMARY

echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

# Add interpretation note
if [ "${{ steps.conformance.outputs.status }}" = "passed" ]; then
echo "✅ **All conformance tests passed** - No behavioral differences detected." >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ **Differences detected** - Review the diffs above to ensure changes are intentional." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Common expected differences:" >> $GITHUB_STEP_SUMMARY
echo "- New tools/toolsets added" >> $GITHUB_STEP_SUMMARY
echo "- Tool descriptions updated" >> $GITHUB_STEP_SUMMARY
echo "- Capability changes (intentional improvements)" >> $GITHUB_STEP_SUMMARY
fi
6 changes: 3 additions & 3 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
Expand All @@ -70,7 +70,7 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
Expand All @@ -87,7 +87,7 @@ jobs:
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-') }}

- name: Go Build Cache for Docker
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: go-build-cache
key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }}
Expand Down
102 changes: 97 additions & 5 deletions .github/workflows/license-check.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# Create a github action that runs the license check script and fails if it exits with a non-zero status
# Automatically fix license files on PRs that need updates
# Tries to auto-commit the fix, or comments with instructions if push fails

name: License Check
on: [push, pull_request]
on:
pull_request:
branches:
- main # Only run when PR targets main
paths:
- "**.go"
- go.mod
- go.sum
- ".github/licenses.tmpl"
- "script/licenses*"
- "third-party-licenses.*.md"
- "third-party/**"
permissions:
contents: read
contents: write
pull-requests: write

jobs:
license-check:
Expand All @@ -13,9 +26,88 @@ jobs:
- name: Check out code
uses: actions/checkout@v6

# Check out the actual PR branch so we can push changes back if needed
- name: Check out PR branch
env:
GH_TOKEN: ${{ github.token }}
run: gh pr checkout ${{ github.event.pull_request.number }}

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: check licenses
run: ./script/licenses-check

# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
# which causes go-licenses to raise "Package ... does not have module info" errors.
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
- name: Regenerate licenses
env:
CI: "true"
run: |
export GOROOT=$(go env GOROOT)
export PATH=${GOROOT}/bin:$PATH
./script/licenses

- name: Check for changes
id: changes
continue-on-error: true
run: script/licenses-check

- name: Commit and push fixes
if: steps.changes.outcome == 'failure'
continue-on-error: true
id: push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add third-party-licenses.*.md third-party/
git commit -m "chore: regenerate license files" -m "Auto-generated by license-check workflow"
git push

- name: Check if already commented
if: steps.changes.outcome == 'failure' && steps.push.outcome == 'failure'
id: check_comment
uses: actions/github-script@v8
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});

const alreadyCommented = comments.some(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('## ⚠️ License files need updating')
);

core.setOutput('already_commented', alreadyCommented ? 'true' : 'false');

- name: Comment with instructions if cannot push
if: steps.changes.outcome == 'failure' && steps.push.outcome == 'failure' && steps.check_comment.outputs.already_commented == 'false'
uses: actions/github-script@v8
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## ⚠️ License files need updating

The license files are out of date. I tried to fix them automatically but don't have permission to push to this branch.

**Please run:**
\`\`\`bash
script/licenses
git add third-party-licenses.*.md third-party/
git commit -m "chore: regenerate license files"
git push
\`\`\`

Alternatively, enable "Allow edits by maintainers" in the PR settings so I can fix it automatically.`
});

- name: Fail check if changes needed
if: steps.changes.outcome == 'failure'
run: exit 1

Loading
Loading