Skip to content

Commit

Permalink
✨ Get Go version dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
ewen-lbh committed Apr 15, 2024
1 parent 17ea1b5 commit bf8af0a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
26 changes: 26 additions & 0 deletions db/client-libraries-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ export async function getGemVersion(localFilename = "") {
}
}
}

export async function getGoVersion(localFilename) {
const packageName = "github.com/ortfo/db"

try {
const response = await fetch(
`https://proxy.golang.org/${packageName}/@latest`
)
const data = await response.json()
if (data.Version) {
console.info(`Got Go version from proxy.golang.org: ${data.Version}`)
return data.Version
} else {
throw new Error(`Version not found for package ${packageName}`)
}
} catch (error) {
console.info(`Falling back to reading from local file ${localFilename}`)
const contents = fs.readFileSync(localFilename, "utf-8")
const match = contents.match(/const Version = "(.+)"/)
if (match) {
return match[1]
} else {
throw new Error(`Version not found in ${localFilename}`)
}
}
}
4 changes: 3 additions & 1 deletion db/client-libraries.data.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { getGemVersion, getRustVersion } from "./client-libraries-versions"
import { getGemVersion, getGoVersion, getRustVersion } from "./client-libraries-versions"

export default {
watch: [
"ortfodb/packages/ruby/lib/ortfodb/version.rb",
"ortfodb/packages/rust/Cargo.toml",
"ortfodb/meta.go"
],
async load(watchedFiles) {
return {
versions: {
gem: await getGemVersion(watchedFiles[0]),
rust: await getRustVersion(watchedFiles[1]),
go: await getGoVersion(watchedFiles[2]),
},
}
},
Expand Down
15 changes: 5 additions & 10 deletions db/client-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ outline: [2, 3]
<script setup>
import { onMounted } from 'vue'
import { data } from './client-libraries.data.js'
import { getRustVersion, getGemVersion } from './client-libraries-versions.js'
import { getRustVersion, getGemVersion, getGoVersion } from './client-libraries-versions.js'

let versions = data.versions


onMounted(async () => {
// try to get fresh data on client-side
try {
versions = {
rust: await getRustVersion(),
ruby: await getGemVersion()
}
} catch(error) {
console.error(error)
}
versions.rust = await getRustVersion().catch(() => versions.rust)
versions.ruby = await getGemVersion().catch(() => versions.ruby)
versions.go = await getGoVersion().catch(() => versions.go)
})
</script>

Expand Down Expand Up @@ -48,7 +43,7 @@ outline: [2, 3]
</a>

<a href="https://pkg.go.dev/github.com/ortfo/db">
<img src="https://img.shields.io/github/release/ortfo/db?label=Go" alt="Go" />
<img :src="`https://img.shields.io/badge/Go-${ versions.go }-blue`" alt="Go" />
</a>

</div>
Expand Down

0 comments on commit bf8af0a

Please sign in to comment.