Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions __tests__/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe('diff.ts', () => {
const configuration = 'configuration'
const tempDirs: TempDirs = {
root: '/temp',
baseRepo: '/temp/base-repo',
result: '/temp/result'
}

Expand Down Expand Up @@ -115,6 +114,8 @@ describe('diff.ts', () => {
const result = await calculateDiffResults(
jarPath,
configuration,
'old',
'new',
tempDirs
)

Expand All @@ -138,7 +139,6 @@ describe('diff.ts', () => {
const configuration = 'configuration'
const tempDirs: TempDirs = {
root: '/temp',
baseRepo: '/temp/base-repo',
result: '/temp/result'
}

Expand All @@ -150,6 +150,8 @@ describe('diff.ts', () => {
const result = await calculateDiffResults(
jarPath,
configuration,
'old',
'new',
tempDirs
)

Expand Down
56 changes: 3 additions & 53 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
calculateDiffResults,
cloneBaseRepository,
createTempDirs,
getGitUrl
} from '../src/main'
import { calculateDiffResults, createTempDirs } from '../src/main'
import { expect, jest } from '@jest/globals'
import * as exec from '@actions/exec'
import * as github from '@actions/github'
import * as utils from '../src/utils.js'
import * as io from '@actions/io'
import * as gradle from '../src/gradle.js'
Expand All @@ -32,56 +25,12 @@ describe('main.ts', () => {

expect(result).toEqual({
root: '/temp',
baseRepo: '/temp/base-repo',
result: '/temp/result'
})
expect(mkdirP).toHaveBeenCalledWith('/temp/base-repo')
expect(mkdirP).toHaveBeenCalledWith('/temp/result')
})
})

describe('getGitUrl', () => {
beforeEach(() => {
process.env.GITHUB_REPOSITORY = 'owner/repo'
})
it('personal token', () => {
const actual = getGitUrl('ghp_token')
expect(actual).toEqual('https://[email protected]/owner/repo')
})
it('not personal token', () => {
const actual = getGitUrl('token')
expect(actual).toEqual(
'https://x-access-token:[email protected]/owner/repo'
)
})
})

describe('cloneBaseRepository', () => {
const mockExec = jest.spyOn(exec, 'exec')

it('test', async () => {
const gitUrl = 'gitUrl'
const baseRepoDir = 'baseRepoDir'

mockExec.mockResolvedValue(0)
jest.replaceProperty(github, 'context', {
payload: { pull_request: { base: { ref: 'main' } } }
} as never)

await cloneBaseRepository('gitUrl', 'baseRepoDir')

expect(mockExec).toHaveBeenCalledWith('git', [
'clone',
'--depth',
'1',
'-b',
'main',
gitUrl,
baseRepoDir
])
})
})

describe('calculateDiffResults', () => {
const mockGenerateDependenciesFiles = jest.spyOn(
gradle,
Expand All @@ -92,7 +41,6 @@ describe('main.ts', () => {
it('test', async () => {
const tempDirs: TempDirs = {
root: '/temp',
baseRepo: '/temp/base-repo',
result: '/temp/result'
}

Expand Down Expand Up @@ -120,6 +68,8 @@ describe('main.ts', () => {
const result = await calculateDiffResults(
'jarPath',
['c1', 'c2'],
'old',
'new',
tempDirs
)
expect(result).toEqual([
Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ inputs:
separated by commas.'
required: false
default: 'runtimeClasspath'
old-repo-dir:
description:
'The location within the workspace holding the base version of the repo.'
required: false
default: 'old'
new-repo-dir:
description:
'The location within the workspace holding the updated version of the
repo.'
required: false
default: 'new'
post-pr-comment:
description:
'If true, posts a PR comment when there are dependency differences.'
Expand Down
2 changes: 1 addition & 1 deletion dist/diff.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 19 additions & 42 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions dist/main.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export async function downloadJar(
export async function calculateDiffResults(
jarPath: string,
configuration: string,
oldRepoDir: string,
newRepoDir: string,
tempDirs: TempDirs
): Promise<DiffResult[]> {
const results: DiffResult[] = []
Expand All @@ -35,14 +37,18 @@ export async function calculateDiffResults(
)
for (const filePath of await globber.glob()) {
const oldFilePath = path.join(
tempDirs.baseRepo,
oldRepoDir,
removePrefix(filePath, process.env.GITHUB_WORKSPACE + path.sep)
)
const newFilePath = path.join(
newRepoDir,
removePrefix(filePath, process.env.GITHUB_WORKSPACE + path.sep)
)
const result = await execDiff(
jarPath,
configuration,
filePath,
oldFilePath,
newFilePath,
tempDirs.result
)
if (result) {
Expand All @@ -57,6 +63,7 @@ export function sortDiffResults(results: DiffResult[]) {
if (a.project === b.project) {
return a.configuration.localeCompare(b.configuration)
} else {
// TODO: fix
if (a.project === 'gradle-root-project') return -1
if (b.project === 'gradle-root-project') return 1
return a.project.localeCompare(b.project)
Expand All @@ -67,19 +74,19 @@ export function sortDiffResults(results: DiffResult[]) {
async function execDiff(
jarPath: string,
configuration: string,
filePath: string,
oldFilePath: string,
newFilePath: string,
resultDir: string
): Promise<DiffResult | undefined> {
if (!fs.existsSync(oldFilePath)) {
return
}

const project = getProjectFromFile(filePath)
const project = getProjectFromFile(newFilePath)

const output = await exec.getExecOutput(
'java',
['-jar', jarPath, oldFilePath, filePath],
['-jar', jarPath, oldFilePath, newFilePath],
{ silent: true }
)
if (output.stdout) {
Expand Down
Loading