mirror of
https://github.com/gmeligio/flutter-docker-image.git
synced 2026-05-24 12:30:34 +00:00
64 lines
1.5 KiB
JavaScript
64 lines
1.5 KiB
JavaScript
module.exports = async ({ core, fetch }) => {
|
|
const linuxReleasesUrl =
|
|
'https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json'
|
|
const stableReleasePattern = /^\d+\.\d+\.\d+$/g
|
|
const resultPath = 'config/flutter_version.json'
|
|
|
|
/**
|
|
* Downloads the flutter releases from URL
|
|
*
|
|
* @param {*} fileUrl
|
|
* @returns object|boolean
|
|
*/
|
|
async function downloadReleases(fileUrl) {
|
|
try {
|
|
const response = await fetch(fileUrl)
|
|
|
|
return response.json()
|
|
} catch (error) {
|
|
console.error(
|
|
`An error occurred while requesting the file URL: ${fileUrl}`,
|
|
error
|
|
)
|
|
|
|
return false
|
|
}
|
|
}
|
|
|
|
const linuxReleasesResponse = await downloadReleases(linuxReleasesUrl)
|
|
|
|
if (linuxReleasesResponse === false) {
|
|
core.setFailed(
|
|
`Could not download Flutter version manifest from ${fileUrl}.`
|
|
)
|
|
|
|
return false
|
|
}
|
|
|
|
const { releases } = linuxReleasesResponse
|
|
const latestRelease = releases.find((r) =>
|
|
r.version.match(stableReleasePattern)
|
|
)
|
|
|
|
const fs = require('fs')
|
|
const data = fs.readFileSync(resultPath, 'utf8')
|
|
const oldJson = JSON.parse(data)
|
|
|
|
const { version, channel, hash: commit } = latestRelease
|
|
|
|
// Update result file, i.e. version.json
|
|
const newJson = {
|
|
...oldJson,
|
|
flutter: {
|
|
channel,
|
|
commit,
|
|
version,
|
|
},
|
|
}
|
|
|
|
// Write outputs
|
|
resultJson = JSON.stringify(newJson, null, 4)
|
|
fs.writeFileSync(resultPath, `${resultJson}\n`)
|
|
core.exportVariable('FLUTTER_VERSION', version)
|
|
}
|