added initial commits
This commit is contained in:
parent
d1f33fc390
commit
ef9e218224
|
@ -1,4 +1,3 @@
|
|||
# Repository CODEOWNERS
|
||||
|
||||
* @actions/actions-runtime
|
||||
* @ncalteen
|
||||
* @cjlapao
|
|
@ -94,3 +94,133 @@ describe('action', () => {
|
|||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getLatestVersion', () => {
|
||||
beforeEach(() => {
|
||||
process.env['RUNNER_OS'] = 'macos'
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
const getLatestVersionMock = jest.spyOn(main, 'getLatestVersion')
|
||||
|
||||
it('wrong os', async () => {
|
||||
process.env['RUNNER_OS'] = 'test'
|
||||
await main.getLatestVersion('dev', 'x64', '3.16.3')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setFailedMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'Failed to get the latest version'
|
||||
)
|
||||
})
|
||||
|
||||
it('convert darwin to macos', async () => {
|
||||
process.env['RUNNER_OS'] = 'darwin'
|
||||
await main.getLatestVersion('stable')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets the latest stable version', async () => {
|
||||
await main.getLatestVersion('stable')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets the latest beta version', async () => {
|
||||
await main.getLatestVersion('beta')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets the latest dev version', async () => {
|
||||
await main.getLatestVersion('dev')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets a specific version', async () => {
|
||||
await main.getLatestVersion('stable', '', '3.16.3')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets a specific arch', async () => {
|
||||
await main.getLatestVersion('stable', 'arm64', '')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets a specific arch and version', async () => {
|
||||
await main.getLatestVersion('stable', 'arm64', '3.16.3')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('gets the x64 as amd64 version', async () => {
|
||||
await main.getLatestVersion('stable', 'amd64', '')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setOutputMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'version',
|
||||
expect.any(String)
|
||||
)
|
||||
})
|
||||
|
||||
it('no version found', async () => {
|
||||
await main.getLatestVersion('mock')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'Channel mock not found')
|
||||
})
|
||||
|
||||
it('no version found for version', async () => {
|
||||
await main.getLatestVersion('dev', '', '3.16.3')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setFailedMock).toHaveBeenNthCalledWith(1, 'Version 3.16.3 not found')
|
||||
})
|
||||
|
||||
it('no version found for arch', async () => {
|
||||
await main.getLatestVersion('dev', 'x641', '')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setFailedMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'Architecture x641 not found'
|
||||
)
|
||||
})
|
||||
|
||||
it('no version found for version and arch', async () => {
|
||||
await main.getLatestVersion('dev', 'x64', '3.16.3')
|
||||
expect(getLatestVersionMock).toHaveReturned()
|
||||
expect(setFailedMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'Version 3.16.3 with architecture x64 not found'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: 'The name of your action here'
|
||||
description: 'Provide a description here'
|
||||
author: 'Your name or organization here'
|
||||
name: 'Setup Flutter'
|
||||
description: 'Setup Flutter SDK on GitHub Actions'
|
||||
author: 'Carlos Lapao'
|
||||
|
||||
# Define your inputs here.
|
||||
inputs:
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -35,6 +35,28 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@fastify/busboy
|
||||
MIT
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
|
||||
tunnel
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
@ -60,6 +82,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|||
THE SOFTWARE.
|
||||
|
||||
|
||||
undici
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) Matteo Collina and Undici contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
uuid
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "javascript-action",
|
||||
"description": "GitHub Actions JavaScript Template",
|
||||
"version": "0.0.0",
|
||||
"name": "setup-flutter",
|
||||
"description": "Setup your GitHub Actions workflow with Flutter SDK",
|
||||
"version": "0.0.1",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"homepage": "https://github.com/actions/javascript-action#readme",
|
||||
|
@ -63,7 +63,8 @@
|
|||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1"
|
||||
"@actions/core": "^1.10.1",
|
||||
"axios": "^1.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.23.5",
|
||||
|
|
90
src/main.js
90
src/main.js
|
@ -1,4 +1,5 @@
|
|||
const core = require('@actions/core')
|
||||
const axios = require('axios')
|
||||
const { wait } = require('./wait')
|
||||
|
||||
/**
|
||||
|
@ -25,6 +26,91 @@ async function run() {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run
|
||||
async function getLatestVersion(channel, arch, version) {
|
||||
let osName = process.env['RUNNER_OS']
|
||||
if (osName === 'darwin') {
|
||||
osName = 'macos'
|
||||
}
|
||||
|
||||
// sometimes the x64 architecture is reported as amd64
|
||||
if (arch !== undefined && arch !== '') {
|
||||
if (arch === 'amd64') {
|
||||
arch = 'x64'
|
||||
}
|
||||
}
|
||||
|
||||
const manifestBaseUrl =
|
||||
'https://storage.googleapis.com/flutter_infra_release/releases'
|
||||
const json_path = `releases_${osName}.json`
|
||||
const manifestUrl = `${manifestBaseUrl}/${json_path}`
|
||||
|
||||
try {
|
||||
core.info('Getting latest version...')
|
||||
const response = await axios.get(manifestUrl)
|
||||
const channelHash = response.data.current_release[channel]
|
||||
if (!channelHash) {
|
||||
core.setFailed(`Channel ${channel} not found`)
|
||||
return
|
||||
}
|
||||
|
||||
const channelEntries = []
|
||||
for (const [key, value] of Object.entries(response.data.releases)) {
|
||||
if (value.hash === channelHash) {
|
||||
channelEntries.push(value)
|
||||
}
|
||||
}
|
||||
|
||||
if ((!arch || arch === '') && (!version || version === '')) {
|
||||
core.setOutput('version', channelEntries[0].version)
|
||||
core.info(`Latest version: ${channelEntries[0].version}`)
|
||||
return channelEntries[0].version
|
||||
}
|
||||
|
||||
let filteredEntry = {}
|
||||
|
||||
for (const entry of channelEntries) {
|
||||
if (version && version !== '' && arch && arch !== '') {
|
||||
if (entry.version === version && entry.dart_sdk_arch === arch) {
|
||||
filteredEntry = entry
|
||||
break
|
||||
}
|
||||
} else if (version && version !== '') {
|
||||
if (entry.version === version) {
|
||||
filteredEntry = entry
|
||||
break
|
||||
}
|
||||
} else if (arch && arch !== '') {
|
||||
if (entry.dart_sdk_arch === arch) {
|
||||
filteredEntry = entry
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!filteredEntry.version) {
|
||||
if (version && version !== '' && arch && arch !== '') {
|
||||
core.setFailed(`Version ${version} with architecture ${arch} not found`)
|
||||
return
|
||||
}
|
||||
if (version && version !== '') {
|
||||
core.setFailed(`Version ${version} not found`)
|
||||
return
|
||||
}
|
||||
if (arch && arch !== '') {
|
||||
core.setFailed(`Architecture ${arch} not found`)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
core.setOutput('version', filteredEntry.version)
|
||||
core.info(`Latest version: ${filteredEntry.version}`)
|
||||
return filteredEntry.version
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed('Failed to get the latest version')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run,
|
||||
getLatestVersion
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue