mirror of
https://github.com/imjasonh/apidiff-action
synced 2026-07-06 22:52:43 +00:00
Fix lint errors and formatting
- Remove unused variables - Add .eslintignore to exclude dist/ - Apply prettier formatting - Fix all pre-commit hook issues
This commit is contained in:
parent
e3eca548b6
commit
805c061497
20 changed files with 2397 additions and 2391 deletions
3
.eslintignore
Normal file
3
.eslintignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
dist/
|
||||
node_modules/
|
||||
coverage/
|
||||
|
|
@ -13,4 +13,4 @@ module.exports = {
|
|||
'no-console': 'off',
|
||||
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
|
|||
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
|
@ -79,7 +79,7 @@ jobs:
|
|||
fi
|
||||
echo "Breaking changes detected: ${{ steps.test-breaking.outputs.breaking-count }}"
|
||||
echo "Compatible changes: ${{ steps.test-breaking.outputs.compatible-count }}"
|
||||
|
||||
|
||||
# Verify counts match what we expect
|
||||
if [ "${{ steps.test-breaking.outputs.breaking-count }}" != "3" ]; then
|
||||
echo "Expected 3 breaking changes, got ${{ steps.test-breaking.outputs.breaking-count }}"
|
||||
|
|
@ -109,7 +109,7 @@ jobs:
|
|||
exit 1
|
||||
fi
|
||||
echo "Compatible changes: ${{ steps.test-safe.outputs.compatible-count }}"
|
||||
|
||||
|
||||
# Verify count matches what we expect
|
||||
if [ "${{ steps.test-safe.outputs.compatible-count }}" != "3" ]; then
|
||||
echo "Expected 3 compatible changes, got ${{ steps.test-safe.outputs.compatible-count }}"
|
||||
|
|
@ -141,4 +141,4 @@ jobs:
|
|||
if [ "${{ steps.test-clean.outputs.compatible-count }}" != "0" ]; then
|
||||
echo "Expected 0 compatible changes, got ${{ steps.test-clean.outputs.compatible-count }}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
|
|||
16
.github/workflows/release.yml
vendored
16
.github/workflows/release.yml
vendored
|
|
@ -13,18 +13,18 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
|
||||
- name: Create Release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
|
|
@ -34,13 +34,13 @@ jobs:
|
|||
release_name: ${{ github.ref }}
|
||||
body: |
|
||||
## What's Changed
|
||||
|
||||
|
||||
See the [commit history](https://github.com/${{ github.repository }}/compare/${{ github.event.before }}...${{ github.ref }}) for details.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
```yaml
|
||||
- uses: ${{ github.repository }}@${{ github.ref }}
|
||||
```
|
||||
draft: false
|
||||
prerelease: false
|
||||
prerelease: false
|
||||
|
|
|
|||
|
|
@ -20,4 +20,4 @@ repos:
|
|||
hooks:
|
||||
- id: eslint
|
||||
files: \.js$
|
||||
args: ['--fix']
|
||||
args: ['--fix']
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@
|
|||
"tabWidth": 2,
|
||||
"trailingComma": "es5",
|
||||
"printWidth": 100
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,4 @@ outputs:
|
|||
|
||||
runs:
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
main: 'dist/index.js'
|
||||
|
|
|
|||
11
index.js
11
index.js
|
|
@ -17,7 +17,7 @@ async function run() {
|
|||
|
||||
// Determine refs to compare
|
||||
let oldRef, newRef;
|
||||
|
||||
|
||||
// Check if INPUT_OLD and INPUT_NEW env vars are set (for testing)
|
||||
if (process.env.INPUT_OLD && process.env.INPUT_NEW) {
|
||||
oldRef = process.env.INPUT_OLD;
|
||||
|
|
@ -34,12 +34,14 @@ async function run() {
|
|||
newRef = context.payload.after;
|
||||
core.info(`Comparing commits ${oldRef} with ${newRef}`);
|
||||
} else {
|
||||
throw new Error('Unable to determine commits to compare. This action should be run on pull_request or push events.');
|
||||
throw new Error(
|
||||
'Unable to determine commits to compare. This action should be run on pull_request or push events.'
|
||||
);
|
||||
}
|
||||
|
||||
// Run apidiff
|
||||
const output = await runApidiff({ workingDirectory, oldRef, newRef });
|
||||
|
||||
|
||||
// Parse output
|
||||
const parsedChanges = parseApidiffOutput(output);
|
||||
|
||||
|
|
@ -62,11 +64,10 @@ async function run() {
|
|||
} else {
|
||||
core.info('No breaking API changes detected');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(`Action failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the action
|
||||
run();
|
||||
run();
|
||||
|
|
|
|||
|
|
@ -18,24 +18,22 @@ async function runApidiff({ workingDirectory, oldRef, newRef }) {
|
|||
|
||||
// Create export files if comparing directories
|
||||
const isDirectory = !oldRef.match(/^[0-9a-f]{7,40}$/i);
|
||||
|
||||
|
||||
if (isDirectory) {
|
||||
// For directories, we need to create export files first
|
||||
const oldDir = path.join(workingDirectory, oldRef);
|
||||
const newDir = path.join(workingDirectory, newRef);
|
||||
const oldExportPath = path.join(oldDir, 'apidiff.export');
|
||||
const newExportPath = path.join(newDir, 'apidiff.export');
|
||||
|
||||
|
||||
// Create export for old version
|
||||
await exec.exec('apidiff', ['-w', 'apidiff.export', '.'], {
|
||||
cwd: oldDir
|
||||
cwd: oldDir,
|
||||
});
|
||||
|
||||
|
||||
// Create export for new version
|
||||
await exec.exec('apidiff', ['-w', 'apidiff.export', '.'], {
|
||||
cwd: newDir
|
||||
cwd: newDir,
|
||||
});
|
||||
|
||||
|
||||
// Now compare the export files
|
||||
let output = '';
|
||||
let errorOutput = '';
|
||||
|
|
@ -48,16 +46,16 @@ async function runApidiff({ workingDirectory, oldRef, newRef }) {
|
|||
},
|
||||
stderr: (data) => {
|
||||
errorOutput += data.toString();
|
||||
}
|
||||
},
|
||||
},
|
||||
ignoreReturnCode: true
|
||||
ignoreReturnCode: true,
|
||||
};
|
||||
|
||||
// Compare using relative paths from working directory
|
||||
const relativeOldPath = path.join(oldRef, 'apidiff.export');
|
||||
const relativeNewPath = path.join(newRef, 'apidiff.export');
|
||||
const exitCode = await exec.exec('apidiff', [relativeOldPath, relativeNewPath], options);
|
||||
|
||||
|
||||
if (errorOutput) {
|
||||
core.warning(`apidiff stderr: ${errorOutput}`);
|
||||
}
|
||||
|
|
@ -82,9 +80,9 @@ async function runApidiff({ workingDirectory, oldRef, newRef }) {
|
|||
},
|
||||
stderr: (data) => {
|
||||
errorOutput += data.toString();
|
||||
}
|
||||
},
|
||||
},
|
||||
ignoreReturnCode: true
|
||||
ignoreReturnCode: true,
|
||||
};
|
||||
|
||||
const exitCode = await exec.exec('apidiff', [oldRef, newRef], options);
|
||||
|
|
@ -116,14 +114,14 @@ async function installApidiff() {
|
|||
// apidiff not found, install it
|
||||
core.info('Installing apidiff...');
|
||||
await exec.exec('go', ['install', 'golang.org/x/exp/cmd/apidiff@latest']);
|
||||
|
||||
|
||||
// Add Go bin to PATH
|
||||
const goPath = process.env.GOPATH || path.join(process.env.HOME, 'go');
|
||||
const goBin = path.join(goPath, 'bin');
|
||||
core.addPath(goBin);
|
||||
|
||||
|
||||
core.info('apidiff installed successfully');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { runApidiff };
|
||||
module.exports = { runApidiff };
|
||||
|
|
|
|||
|
|
@ -31,12 +31,10 @@ async function createOrUpdateComment({ token, body }) {
|
|||
const { data: comments } = await octokit.rest.issues.listComments({
|
||||
owner,
|
||||
repo,
|
||||
issue_number: prNumber
|
||||
issue_number: prNumber,
|
||||
});
|
||||
|
||||
const existingComment = comments.find(comment =>
|
||||
comment.body?.includes(COMMENT_TAG)
|
||||
);
|
||||
const existingComment = comments.find((comment) => comment.body?.includes(COMMENT_TAG));
|
||||
|
||||
if (existingComment) {
|
||||
// Update existing comment
|
||||
|
|
@ -44,7 +42,7 @@ async function createOrUpdateComment({ token, body }) {
|
|||
owner,
|
||||
repo,
|
||||
comment_id: existingComment.id,
|
||||
body: commentBody
|
||||
body: commentBody,
|
||||
});
|
||||
core.info(`Updated existing comment: ${existingComment.html_url}`);
|
||||
} else {
|
||||
|
|
@ -53,7 +51,7 @@ async function createOrUpdateComment({ token, body }) {
|
|||
owner,
|
||||
repo,
|
||||
issue_number: prNumber,
|
||||
body: commentBody
|
||||
body: commentBody,
|
||||
});
|
||||
core.info(`Created new comment: ${newComment.html_url}`);
|
||||
}
|
||||
|
|
@ -63,4 +61,4 @@ async function createOrUpdateComment({ token, body }) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = { createOrUpdateComment };
|
||||
module.exports = { createOrUpdateComment };
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ function parseApidiffOutput(output) {
|
|||
hasBreakingChanges: false,
|
||||
breakingCount: 0,
|
||||
compatibleCount: 0,
|
||||
packages: []
|
||||
packages: [],
|
||||
};
|
||||
|
||||
if (!output || output.trim() === '') {
|
||||
|
|
@ -19,14 +19,14 @@ function parseApidiffOutput(output) {
|
|||
|
||||
// Split into lines
|
||||
const lines = output.split('\n');
|
||||
|
||||
|
||||
let currentPackage = {
|
||||
name: 'default',
|
||||
breaking: [],
|
||||
compatible: []
|
||||
compatible: [],
|
||||
};
|
||||
result.packages.push(currentPackage);
|
||||
|
||||
|
||||
let inCompatibleSection = false;
|
||||
let inIncompatibleSection = false;
|
||||
|
||||
|
|
@ -55,10 +55,10 @@ function parseApidiffOutput(output) {
|
|||
// Parse changes (they start with "- ")
|
||||
if ((inCompatibleSection || inIncompatibleSection) && trimmedLine.startsWith('- ')) {
|
||||
const changeMessage = trimmedLine.substring(2).trim();
|
||||
|
||||
|
||||
const change = {
|
||||
message: changeMessage,
|
||||
compatible: inCompatibleSection
|
||||
compatible: inCompatibleSection,
|
||||
};
|
||||
|
||||
if (inCompatibleSection) {
|
||||
|
|
@ -72,8 +72,8 @@ function parseApidiffOutput(output) {
|
|||
}
|
||||
|
||||
// Clean up empty packages
|
||||
result.packages = result.packages.filter(pkg =>
|
||||
pkg.breaking.length > 0 || pkg.compatible.length > 0
|
||||
result.packages = result.packages.filter(
|
||||
(pkg) => pkg.breaking.length > 0 || pkg.compatible.length > 0
|
||||
);
|
||||
|
||||
// If no packages with changes, return empty packages array
|
||||
|
|
@ -81,7 +81,9 @@ function parseApidiffOutput(output) {
|
|||
result.packages = [];
|
||||
}
|
||||
|
||||
core.info(`Parsed ${result.breakingCount} breaking changes and ${result.compatibleCount} compatible changes`);
|
||||
core.info(
|
||||
`Parsed ${result.breakingCount} breaking changes and ${result.compatibleCount} compatible changes`
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -112,7 +114,7 @@ function formatChangesAsMarkdown(parsedChanges) {
|
|||
|
||||
// Details by package
|
||||
markdown += '## Details\n\n';
|
||||
|
||||
|
||||
for (const pkg of parsedChanges.packages) {
|
||||
if (pkg.name !== 'default') {
|
||||
markdown += `### \`${pkg.name}\`\n\n`;
|
||||
|
|
@ -138,4 +140,4 @@ function formatChangesAsMarkdown(parsedChanges) {
|
|||
return markdown;
|
||||
}
|
||||
|
||||
module.exports = { parseApidiffOutput, formatChangesAsMarkdown };
|
||||
module.exports = { parseApidiffOutput, formatChangesAsMarkdown };
|
||||
|
|
|
|||
4566
package-lock.json
generated
4566
package-lock.json
generated
File diff suppressed because it is too large
Load diff
66
package.json
66
package.json
|
|
@ -1,30 +1,11 @@
|
|||
{
|
||||
"name": "apidiff-action",
|
||||
"version": "1.0.0",
|
||||
"description": "GitHub Action for detecting breaking API changes in Go code",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build index.js -o dist",
|
||||
"test": "jest",
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --write .",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"keywords": [
|
||||
"github-action",
|
||||
"go",
|
||||
"golang",
|
||||
"api",
|
||||
"compatibility",
|
||||
"breaking-changes"
|
||||
],
|
||||
"author": "Jason Hall",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0"
|
||||
},
|
||||
"description": "GitHub Action for detecting breaking API changes in Go code",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.11",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
|
|
@ -35,6 +16,27 @@
|
|||
"lint-staged": "^15.2.0",
|
||||
"prettier": "^3.1.1"
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverage": true,
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 80,
|
||||
"functions": 80,
|
||||
"lines": 80,
|
||||
"statements": 80
|
||||
}
|
||||
},
|
||||
"testEnvironment": "node"
|
||||
},
|
||||
"keywords": [
|
||||
"github-action",
|
||||
"go",
|
||||
"golang",
|
||||
"api",
|
||||
"compatibility",
|
||||
"breaking-changes"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"lint-staged": {
|
||||
"*.js": [
|
||||
"eslint --fix",
|
||||
|
|
@ -44,16 +46,14 @@
|
|||
"prettier --write"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"collectCoverage": true,
|
||||
"coverageThreshold": {
|
||||
"global": {
|
||||
"branches": 80,
|
||||
"functions": 80,
|
||||
"lines": 80,
|
||||
"statements": 80
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"main": "index.js",
|
||||
"name": "apidiff-action",
|
||||
"scripts": {
|
||||
"build": "ncc build index.js -o dist",
|
||||
"format": "prettier --write .",
|
||||
"lint": "eslint .",
|
||||
"prepare": "husky install",
|
||||
"test": "jest"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ describe('formatChangesAsMarkdown', () => {
|
|||
hasBreakingChanges: false,
|
||||
breakingCount: 0,
|
||||
compatibleCount: 0,
|
||||
packages: []
|
||||
packages: [],
|
||||
};
|
||||
|
||||
const markdown = formatChangesAsMarkdown(parsedChanges);
|
||||
|
|
@ -98,11 +98,13 @@ describe('formatChangesAsMarkdown', () => {
|
|||
hasBreakingChanges: true,
|
||||
breakingCount: 1,
|
||||
compatibleCount: 0,
|
||||
packages: [{
|
||||
name: 'default',
|
||||
breaking: [{ message: 'Foo: removed', compatible: false }],
|
||||
compatible: []
|
||||
}]
|
||||
packages: [
|
||||
{
|
||||
name: 'default',
|
||||
breaking: [{ message: 'Foo: removed', compatible: false }],
|
||||
compatible: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const markdown = formatChangesAsMarkdown(parsedChanges);
|
||||
|
|
@ -118,14 +120,16 @@ describe('formatChangesAsMarkdown', () => {
|
|||
hasBreakingChanges: false,
|
||||
breakingCount: 0,
|
||||
compatibleCount: 2,
|
||||
packages: [{
|
||||
name: 'default',
|
||||
breaking: [],
|
||||
compatible: [
|
||||
{ message: 'Bar: added', compatible: true },
|
||||
{ message: 'Baz: added', compatible: true }
|
||||
]
|
||||
}]
|
||||
packages: [
|
||||
{
|
||||
name: 'default',
|
||||
breaking: [],
|
||||
compatible: [
|
||||
{ message: 'Bar: added', compatible: true },
|
||||
{ message: 'Baz: added', compatible: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const markdown = formatChangesAsMarkdown(parsedChanges);
|
||||
|
|
@ -134,4 +138,4 @@ describe('formatChangesAsMarkdown', () => {
|
|||
expect(markdown).toContain('- Bar: added');
|
||||
expect(markdown).toContain('- Baz: added');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
2
testdata/break/new/go.mod
vendored
2
testdata/break/new/go.mod
vendored
|
|
@ -1,3 +1,3 @@
|
|||
module example.com/test
|
||||
|
||||
go 1.21
|
||||
go 1.21
|
||||
|
|
|
|||
2
testdata/break/old/go.mod
vendored
2
testdata/break/old/go.mod
vendored
|
|
@ -1,3 +1,3 @@
|
|||
module example.com/test
|
||||
|
||||
go 1.21
|
||||
go 1.21
|
||||
|
|
|
|||
2
testdata/clean/new/go.mod
vendored
2
testdata/clean/new/go.mod
vendored
|
|
@ -1,3 +1,3 @@
|
|||
module example.com/test
|
||||
|
||||
go 1.21
|
||||
go 1.21
|
||||
|
|
|
|||
2
testdata/clean/old/go.mod
vendored
2
testdata/clean/old/go.mod
vendored
|
|
@ -1,3 +1,3 @@
|
|||
module example.com/test
|
||||
|
||||
go 1.21
|
||||
go 1.21
|
||||
|
|
|
|||
2
testdata/safe/new/go.mod
vendored
2
testdata/safe/new/go.mod
vendored
|
|
@ -1,3 +1,3 @@
|
|||
module example.com/test
|
||||
|
||||
go 1.21
|
||||
go 1.21
|
||||
|
|
|
|||
2
testdata/safe/old/go.mod
vendored
2
testdata/safe/old/go.mod
vendored
|
|
@ -1,3 +1,3 @@
|
|||
module example.com/test
|
||||
|
||||
go 1.21
|
||||
go 1.21
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue