Skip to content

Commit

Permalink
feat: allow skip-login (#11)
Browse files Browse the repository at this point in the history
* feat: allow skip-login

* do not return

* use skip-login-check
  • Loading branch information
markandersontrocme authored Jan 13, 2025
1 parent d284515 commit 8701602
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
41 changes: 41 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ describe('action', () => {
})

it('fails if your are not logged in', async () => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'skip-login-check':
return 'false'
default:
return ''
}
})
jest.spyOn(io, 'which').mockResolvedValue(path)
stdErrMessage = 'Unauthorized'
mockStatusCode = 1
Expand All @@ -85,6 +93,39 @@ describe('action', () => {
)
})

it('do not check login if skip-login-check', async () => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'skip-login-check':
return 'true'
default:
return ''
}
})
jest.spyOn(io, 'which').mockResolvedValue(path)
stdOutMessage = ''
mockStatusCode = 0

await run.run()
expect(runMock).toHaveReturned()

expect(mockExecFn).not.toHaveBeenNthCalledWith(
1,
path,
['org', 'list', '--format', 'json'],
expect.any(Object)
)

expect(mockExecFn).toHaveBeenNthCalledWith(
1,
path,
['project', 'build'],
undefined
)

expect(infoMock).toHaveBeenNthCalledWith(1, 'Skipping login check.')
})

it('does not push if push-project is false', async () => {
getInputMock.mockImplementation(name => {
switch (name) {
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ inputs:
description: 'Push Upbound project'
default: 'false'
project-file:
description: 'Path to project definition file. Default to upbound.yaml'
description: 'Path to project definition file. Default to upbound.yaml.'
default: ''
repository:
description:
Expand All @@ -20,7 +20,10 @@ inputs:
generated.'
default: ''
public:
description: 'Create new repositories with public visibility'
description: 'Create new repositories with public visibility.'
default: 'false'
skip-login-check:
description: 'Do not check if you are logged in.'
default: 'false'

branding:
Expand Down
14 changes: 11 additions & 3 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.

13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ async function run(): Promise<void> {
try {
const upPath = await getUpPath()

const isLoggedIn = await verifyLogin(upPath)
if (!isLoggedIn) {
core.setFailed('User is not logged in. Please log in to Upbound.')
// NOTE (markanderstrocme): allowing skipping login check if people are using their own container registry
const skipLoginCheck = core.getInput('skip-login-check', { required: true })
if (skipLoginCheck.toLowerCase() === 'true') {
core.info('Skipping login check.')
} else {
const isLoggedIn = await verifyLogin(upPath)
if (!isLoggedIn) {
core.setFailed('User is not logged in. Please log in to Upbound.')
return
}
}

const projectFile = core.getInput('project-file')
Expand Down

0 comments on commit 8701602

Please sign in to comment.