Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #422 from achieve-3000/dist
Browse files Browse the repository at this point in the history
Update deps
  • Loading branch information
Fabio Silva authored May 10, 2023
2 parents 53fa7ed + 52a6174 commit a4e10fd
Show file tree
Hide file tree
Showing 11 changed files with 8,315 additions and 12,144 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ on:
jobs:
check:
name: Check
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
-
name: Checkout code
uses: actions/checkout@v3
-
name: Set Node.js 14.x
name: Set Node.js 19.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 19.x
-
name: Cache dependencies
uses: actions/cache@v3
Expand All @@ -37,16 +37,16 @@ jobs:

dist:
name: Dist
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
-
name: Checkout code
uses: actions/checkout@v3
-
name: Set Node.js 14.x
name: Set Node.js 19.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 19.x
-
name: Cache dependencies
uses: actions/cache@v3
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
# Run action
diff:
name: Diff
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
outputs:
modules: ${{ steps.run.outputs.modules }}
changed: ${{ steps.run.outputs.changed }}
Expand Down Expand Up @@ -40,7 +40,7 @@ jobs:
print-all:
needs: [diff]
name: Print all
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: ${{ fromJson(needs.diff.outputs.changed) }}
strategy:
fail-fast: false
Expand All @@ -61,7 +61,7 @@ jobs:
print-changes:
needs: [diff]
name: Print changes
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: ${{ fromJson(needs.diff.outputs.changed) }}
strategy:
fail-fast: false
Expand All @@ -81,7 +81,7 @@ jobs:
print-ts:
needs: [diff]
name: Print ts
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: ${{ fromJson(needs.diff.outputs.tags).ts.changed }}
strategy:
fail-fast: false
Expand All @@ -101,7 +101,7 @@ jobs:
print-js:
needs: [diff]
name: Print js
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
if: ${{ fromJson(needs.diff.outputs.tags).js.changed }}
strategy:
fail-fast: false
Expand Down
201 changes: 102 additions & 99 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import {expect, test} from '@jest/globals'
import {expect, test, jest} from '@jest/globals'

import {randomUUID} from 'crypto'
import {Params} from '../src/models'
import {GithubAdapter} from '../src/github'
import nock from 'nock'

import {components} from '@octokit/openapi-types/types'

/* eslint-disable import/named */
import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
/* eslint-enable import/named */

type CompareCommitsWithBaseheadResponse = RestEndpointMethodTypes['repos']['compareCommitsWithBasehead']['response']
type CompareCommitsWithBaseheadDataDiff = CompareCommitsWithBaseheadResponse['data']['files']

function createParams(): Params {
return {
Expand Down Expand Up @@ -48,51 +57,53 @@ function createParams(): Params {
}
}

function mockCompareResponse(params: Params, body: object) {
const host = 'https://api.github.com'
const path = `/repos/${params.repo_owner}/${params.repo_name}/compare/${params.base_ref}...${params.head_ref}`
function createMockResponse(files: object[]): Promise<CompareCommitsWithBaseheadDataDiff> {
return Promise.resolve(files.map(o => o as components['schemas']['diff-entry']))
}

function createGithubAdapter(params: Params, files: object[]) {
const adapter = new GithubAdapter(params)
const result = createMockResponse(files)

jest.spyOn(adapter, 'compareCommits').mockImplementation(() => result)

nock(host).persist().get(path).reply(200, body)
return adapter
}

test('compare commits', async () => {
const params = createParams()
const response = {
files: [
{
filename: 'infra/terraform/added.txt',
status: 'added'
},
{
filename: 'infra/terraform/modified.txt',
status: 'modified'
},
{
filename: 'infra/terraform/renamed.txt',
status: 'renamed'
},
{
filename: 'infra/terraform/removed.txt',
status: 'removed'
},
{
filename: 'module1/added.txt',
status: 'added'
},
{
filename: 'module1/modified.txt',
status: 'modified'
},
{
filename: 'module2/modified.txt',
status: 'added'
}
]
}

mockCompareResponse(params, response)
const response = [
{
filename: 'infra/terraform/added.txt',
status: 'added'
},
{
filename: 'infra/terraform/modified.txt',
status: 'modified'
},
{
filename: 'infra/terraform/renamed.txt',
status: 'renamed'
},
{
filename: 'infra/terraform/removed.txt',
status: 'removed'
},
{
filename: 'module1/added.txt',
status: 'added'
},
{
filename: 'module1/modified.txt',
status: 'modified'
},
{
filename: 'module2/modified.txt',
status: 'added'
}
]

const adapter = new GithubAdapter(params)
const adapter = createGithubAdapter(params, response)
const result = await adapter.compare()

expect(Array.from(result.modules.keys())).toEqual(
Expand Down Expand Up @@ -151,46 +162,42 @@ test('compare commits', async () => {

test('map diff tags', async () => {
const params = createParams()
const response = {
files: [
{
filename: 'infra/terraform/added.txt',
status: 'added'
},
{
filename: 'infra/terraform/modified.txt',
status: 'modified'
},
{
filename: 'infra/terraform/renamed.txt',
status: 'renamed'
},
{
filename: 'infra/terraform/removed.txt',
status: 'removed'
},
{
filename: 'infra/kubernetes/added.txt',
status: 'added'
},
{
filename: 'module1/added.txt',
status: 'added'
},
{
filename: 'module1/modified.txt',
status: 'modified'
},
{
filename: 'module2/modified.txt',
status: 'added'
}
]
}

mockCompareResponse(params, response)
const response = [
{
filename: 'infra/terraform/added.txt',
status: 'added'
},
{
filename: 'infra/terraform/modified.txt',
status: 'modified'
},
{
filename: 'infra/terraform/renamed.txt',
status: 'renamed'
},
{
filename: 'infra/terraform/removed.txt',
status: 'removed'
},
{
filename: 'infra/kubernetes/added.txt',
status: 'added'
},
{
filename: 'module1/added.txt',
status: 'added'
},
{
filename: 'module1/modified.txt',
status: 'modified'
},
{
filename: 'module2/modified.txt',
status: 'added'
}
]

const adapter = new GithubAdapter(params)
const adapter = createGithubAdapter(params, response)
const result = await adapter.compare()

expect(Array.from(result.modules.keys())).toEqual(
Expand All @@ -215,26 +222,22 @@ test('map diff tags', async () => {

test('compare commits on subpath', async () => {
const params = createParams()
const response = {
files: [
{
filename: 'infra/terraform/config/dev/config.yaml',
status: 'modified'
},
{
filename: 'infra/terraform/config/qa/config.yaml',
status: 'modified'
},
{
filename: 'module1/src/main/resources/log4j.properties',
status: 'modified'
}
]
}

mockCompareResponse(params, response)
const response = [
{
filename: 'infra/terraform/config/dev/config.yaml',
status: 'modified'
},
{
filename: 'infra/terraform/config/qa/config.yaml',
status: 'modified'
},
{
filename: 'module1/src/main/resources/log4j.properties',
status: 'modified'
}
]

const adapter = new GithubAdapter(params)
const adapter = createGithubAdapter(params, response)
const result = await adapter.compare()

expect(result.changed).toBeTruthy()
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ inputs:
required: false
description: 'YAML file containing modules to track'
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
Loading

0 comments on commit a4e10fd

Please sign in to comment.