Skip to content

Add path-with-slashes output #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
DEFAULT_BRANCH: main
FILTER_REGEX_EXCLUDE: dist/**/*
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPESCRIPT_DEFAULT_STYLE: prettier
VALIDATE_ALL_CODEBASE: true
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_TYPESCRIPT_STANDARD: false
VALIDATE_JSCPD: false
13 changes: 12 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ const tmpDir = fs.mkdtempSync(
// Mock the GitHub Actions core library
let errorMock: jest.SpiedFunction<typeof core.error>
let getInputMock: jest.SpiedFunction<typeof core.getInput>
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()

errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})

it('downloads 14.0.0', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'version':
return '15.0.0-beta1'
return '14.0.0'
case 'unzip-to':
return tmpDir
default:
Expand All @@ -51,5 +53,14 @@ describe('action', () => {
await main.run()
expect(runMock).toHaveReturned()
expect(errorMock).not.toHaveBeenCalled()

expect(setOutputMock).toHaveBeenCalledWith(
'path',
expect.stringContaining(tmpDir)
)
expect(setOutputMock).toHaveBeenCalledWith(
'path-with-slashes',
expect.not.stringContaining('\\')
)
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 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.

11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function downloadQtC(urls: string[]): Promise<string[]> {
try {
for (const packageName of packages) {
const fullUrl = `${url}/${packageName}`
console.log(`Downloading ${fullUrl}`)
core.info(`Downloading ${fullUrl}`)
await downloadPackage(fullUrl, `${tmpDir}/${packageName}`)
}
return packages.map(packageName => `${tmpDir}/${packageName}`)
Expand Down Expand Up @@ -101,16 +101,19 @@ export async function run(): Promise<void> {

for (const packageFile of packages) {
// Unzip the downloaded file
console.log(`Unzipping package: ${packageFile}`)
core.info(`Unzipping package: ${packageFile}`)
await extract(packageFile, destination)
}

console.log(`Qt Creator ${version} has been extracted to ${destination}`)
core.info(`Qt Creator ${version} has been extracted to ${destination}`)

// Set outputs for other workflow steps to use
core.setOutput('path', destination)
core.setOutput(
'path-with-slashes',
path.resolve(destination).split(path.sep).join('/')
)
} catch (error) {
console.log('Error:', error)
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down
Loading