Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.

Commit f08e55b

Browse files
authored
Adds neosync setup cli action (#2)
1 parent f8547c3 commit f08e55b

File tree

14 files changed

+28903
-924
lines changed

14 files changed

+28903
-924
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ jobs:
5151
id: checkout
5252
uses: actions/checkout@v4
5353

54-
- name: Test Local Action
55-
id: test-action
54+
- name: Test Local Action with Latest version
55+
id: test-action-latest
5656
uses: ./
5757
with:
58-
milliseconds: 2000
58+
version: latest
5959

60-
- name: Print Output
61-
id: output
62-
run: echo "${{ steps.test-action.outputs.time }}"
60+
- name: Test Local Action with specific version
61+
id: test-action-specific
62+
uses: ./
63+
with:
64+
version: v0.0.18

__tests__/main.test.ts

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,76 @@
77
*/
88

99
import * as core from '@actions/core'
10+
import * as tc from '@actions/tool-cache'
11+
import os from 'os'
1012
import * as main from '../src/main'
1113

12-
// Mock the action's main function
14+
// // Mock the action's main function
1315
const runMock = jest.spyOn(main, 'run')
1416

15-
// Other utilities
16-
const timeRegex = /^\d{2}:\d{2}:\d{2}/
17+
jest.mock('os')
1718

18-
// Mock the GitHub Actions core library
19-
let debugMock: jest.SpyInstance
2019
let errorMock: jest.SpyInstance
2120
let getInputMock: jest.SpyInstance
22-
let setFailedMock: jest.SpyInstance
23-
let setOutputMock: jest.SpyInstance
21+
let addPathMock: jest.SpyInstance
22+
let downloadToolMock: jest.SpyInstance
23+
let extractTarMock: jest.SpyInstance
2424

2525
describe('action', () => {
2626
beforeEach(() => {
2727
jest.clearAllMocks()
2828

29-
debugMock = jest.spyOn(core, 'debug').mockImplementation()
30-
errorMock = jest.spyOn(core, 'error').mockImplementation()
3129
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
32-
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
33-
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
30+
addPathMock = jest.spyOn(core, 'addPath').mockImplementation()
31+
errorMock = jest.spyOn(core, 'setFailed').mockImplementation()
32+
downloadToolMock = jest.spyOn(tc, 'downloadTool').mockImplementation()
33+
extractTarMock = jest.spyOn(tc, 'extractTar').mockImplementation()
34+
35+
os.platform = jest.fn().mockReturnValue('linux')
36+
os.arch = jest.fn().mockReturnValue('amd64')
3437
})
3538

36-
it('sets the time output', async () => {
39+
it('sets the version output', async () => {
3740
// Set the action's inputs as return values from core.getInput()
3841
getInputMock.mockImplementation((name: string): string => {
3942
switch (name) {
40-
case 'milliseconds':
41-
return '500'
43+
case 'version':
44+
return 'v0.0.18'
4245
default:
4346
return ''
4447
}
4548
})
4649

47-
await main.run()
48-
expect(runMock).toHaveReturned()
49-
50-
// Verify that all of the core library functions were called correctly
51-
expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...')
52-
expect(debugMock).toHaveBeenNthCalledWith(
53-
2,
54-
expect.stringMatching(timeRegex)
55-
)
56-
expect(debugMock).toHaveBeenNthCalledWith(
57-
3,
58-
expect.stringMatching(timeRegex)
59-
)
60-
expect(setOutputMock).toHaveBeenNthCalledWith(
61-
1,
62-
'time',
63-
expect.stringMatching(timeRegex)
64-
)
65-
expect(errorMock).not.toHaveBeenCalled()
66-
})
67-
68-
it('sets a failed status', async () => {
69-
// Set the action's inputs as return values from core.getInput()
70-
getInputMock.mockImplementation((name: string): string => {
71-
switch (name) {
72-
case 'milliseconds':
73-
return 'this is not a number'
50+
downloadToolMock.mockImplementation((dlUrl: string): string => {
51+
switch (dlUrl) {
52+
case 'https://github.com/nucleuscloud/neosync/releases/download/v0.0.18/neosync_0.0.18_linux_amd64.tar.gz':
53+
return 'fake-tar-path'
54+
default:
55+
return ''
56+
}
57+
})
58+
extractTarMock.mockImplementation((tarPath: string): string => {
59+
switch (tarPath) {
60+
case 'fake-tar-path':
61+
return '/path/to/tarball'
7462
default:
7563
return ''
7664
}
7765
})
66+
addPathMock.mockImplementation((cliPath: string): void => {
67+
switch (cliPath) {
68+
case '/path/to/tarball':
69+
return
70+
default:
71+
throw new Error('test: invalid cli path')
72+
}
73+
})
7874

7975
await main.run()
8076
expect(runMock).toHaveReturned()
81-
82-
// Verify that all of the core library functions were called correctly
83-
expect(setFailedMock).toHaveBeenNthCalledWith(
84-
1,
85-
'milliseconds not a number'
86-
)
8777
expect(errorMock).not.toHaveBeenCalled()
78+
expect(downloadToolMock).toHaveBeenCalled()
79+
expect(extractTarMock).toHaveBeenCalled()
80+
expect(addPathMock).toHaveBeenCalled()
8881
})
8982
})

__tests__/util.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, test } from '@jest/globals'
2+
import { getDownloadUrl } from '../src/util'
3+
4+
import os from 'os'
5+
6+
jest.mock('os')
7+
8+
describe('util.ts', () => {
9+
test('get latest download url', async () => {
10+
os.platform = jest.fn().mockReturnValue('linux')
11+
os.arch = jest.fn().mockReturnValue('amd64')
12+
13+
await expect(getDownloadUrl('latest')).resolves.toBeTruthy()
14+
})
15+
16+
test('get specific version download url', async () => {
17+
const version = '0.0.26'
18+
const ops = 'linux'
19+
const arch = 'amd64'
20+
const filename = `neosync_${version}_${ops}_${arch}`
21+
22+
os.platform = jest.fn().mockReturnValue(ops)
23+
os.arch = jest.fn().mockReturnValue(arch)
24+
25+
const url = await getDownloadUrl(version)
26+
expect(url).toEqual(
27+
`https://github.com/nucleuscloud/neosync/releases/download/v${version}/${filename}.tar.gz`
28+
)
29+
})
30+
})

__tests__/wait.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

action.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,15 @@ name: 'Setup Neosync CLI'
22
description: 'Setup Neosync CLI on Github Action runners'
33
author: 'nucleuscloud'
44

5-
# Add your action's branding here. This will appear on the GitHub Marketplace.
65
branding:
76
icon: 'rocket'
87
color: 'purple'
98

10-
# Define your inputs here.
119
inputs:
1210
version:
1311
description: Version of Neosync CLI to install
1412
required: false
1513
default: latest
16-
api_key:
17-
description: API Key used for accessing Neosync
18-
required: false
19-
20-
# Define your outputs here.
21-
# outputs:
22-
# time:
23-
# description: 'Your output description here'
2414

2515
runs:
2616
using: node20

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)