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
4 changes: 4 additions & 0 deletions get-service-versions/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inputs:
description: GitHub token for destination repository
required: true
default: ${{ github.token }}
success-if-not-found:
description: If true, the action will not fail if the namespace is not found
required: false
default: 'true'

outputs:
application-versions:
Expand Down
1 change: 1 addition & 0 deletions get-service-versions/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const main = async (): Promise<void> => {
sourceRepository: core.getInput('source-repository', { required: true }),
destinationRepository: core.getInput('destination-repository', { required: true }),
destinationRepositoryToken: core.getInput('destination-repository-token', { required: true }),
successIfNotFound: core.getBooleanInput('success-if-not-found') || true,
})
}

Expand Down
16 changes: 14 additions & 2 deletions get-service-versions/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Inputs = {
sourceRepository: string
destinationRepository: string
destinationRepositoryToken: string
successIfNotFound: boolean
}

type Outputs = ApplicationVersion[]
Expand All @@ -20,9 +21,20 @@ export const run = async (inputs: Inputs): Promise<void> => {
}
}

const getServiceVersions = async (inputs: Inputs): Promise<Outputs> => {
export const getServiceVersions = async (inputs: Inputs): Promise<Outputs> => {
core.info(`Checking out the namespace branch`)
const namespaceDirectory = await checkoutNamespaceBranch(inputs)
let namespaceDirectory: string

try {
namespaceDirectory = await checkoutNamespaceBranch(inputs)
} catch (error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git コマンドの失敗以外の例外もキャッチしてしまうので、下記の exec からステータスコードを受け取ってチェックする方がよいと思います。

await exec.exec('git', ['checkout', opts.branch], { cwd })

if (inputs.successIfNotFound) {
core.warning(`Namespace branch not found, returning empty list`)
return []
}

throw error
}
core.debug(`Namespace directory: ${namespaceDirectory}`)

const applicationFiles = await listApplicationFiles(namespaceDirectory)
Expand Down
16 changes: 16 additions & 0 deletions get-service-versions/tests/aplication.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import * as os from 'os'
import * as path from 'path'
import { promises as fs } from 'fs'
import { getServiceVersions } from '../src/run.js'
import { listApplicationFiles, readApplication } from '../src/application.js'

const createEmptyDirectory = async () => await fs.mkdtemp(path.join(os.tmpdir(), 'bootstrap-pull-request-'))

describe('getServiceVersions', () => {
it('returnes empty list if successIfNotFound', async () => {
const result = await getServiceVersions({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ユニットテストはローカルで実行するので、実行環境に依存するコマンドを実行するとテスト結果が不安定になります。
実行環境に依存するテストは E2E テストで行うのが確実ですが、今回のような単純な条件分岐では省略してもよいのではないかと思います。

overlay: 'overlay',
namespace: 'namespace',
sourceRepository: 'sourceRepository',
destinationRepository: 'destinationRepository',
destinationRepositoryToken: 'destinationRepositoryToken',
successIfNotFound: true,
})

expect(result).toStrictEqual([])
})
})

describe('listApplicationFiles', () => {
it('lists up the application files, not other files', async () => {
const namespaceDirectory = await createEmptyDirectory()
Expand Down
Loading