-
-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version and update notes (#2722)
- Loading branch information
Showing
7 changed files
with
147 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<Settings :title="$t('info')"> | ||
<div class="flex flex-col items-center gap-4"> | ||
<WoodpeckerLogo class="w-48 h-48" /> | ||
|
||
<i18n-t keypath="running_version" tag="p" class="text-xl"> | ||
<span class="font-bold">{{ version?.current }}</span> | ||
</i18n-t> | ||
|
||
<i18n-t v-if="version?.needsUpdate" keypath="update_woodpecker" tag="span" class="text-int-wp-state-error-100"> | ||
<a | ||
:href="`https://github.com/woodpecker-ci/woodpecker/releases/tag/${version.latest}`" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
class="underline" | ||
>{{ version.latest }}</a | ||
> | ||
</i18n-t> | ||
</div> | ||
</Settings> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import WoodpeckerLogo from '~/assets/logo.svg?component'; | ||
import Settings from '~/components/layout/Settings.vue'; | ||
import { useVersion } from '~/compositions/useVersion'; | ||
const version = useVersion(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { onMounted, ref } from 'vue'; | ||
|
||
import useAuthentication from './useAuthentication'; | ||
import useConfig from './useConfig'; | ||
|
||
type VersionInfo = { | ||
latest: string; | ||
next: string; | ||
}; | ||
|
||
const version = ref<{ | ||
latest: string | undefined; | ||
current: string; | ||
currentShort: string; | ||
needsUpdate: boolean; | ||
}>(); | ||
|
||
async function fetchVersion(): Promise<VersionInfo | undefined> { | ||
try { | ||
const resp = await fetch('https://woodpecker-ci.org/version.json'); | ||
const json = await resp.json(); | ||
return json; | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error('Failed to fetch version info', error); | ||
return undefined; | ||
} | ||
} | ||
|
||
const isInitialised = ref(false); | ||
|
||
export function useVersion() { | ||
if (isInitialised.value) { | ||
return version; | ||
} | ||
isInitialised.value = true; | ||
|
||
const config = useConfig(); | ||
const current = config.version as string; | ||
const usesNext = config.version?.startsWith('next'); | ||
|
||
const { user } = useAuthentication(); | ||
if (!user?.admin) { | ||
version.value = { | ||
latest: undefined, | ||
current, | ||
currentShort: usesNext ? 'next' : current, | ||
needsUpdate: false, | ||
}; | ||
return version; | ||
} | ||
|
||
if (current === 'dev') { | ||
version.value = { | ||
latest: undefined, | ||
current, | ||
currentShort: current, | ||
needsUpdate: false, | ||
}; | ||
return version; | ||
} | ||
|
||
onMounted(async () => { | ||
const versionInfo = await fetchVersion(); | ||
|
||
let needsUpdate = false; | ||
if (versionInfo) { | ||
if (usesNext) { | ||
needsUpdate = versionInfo.next !== current; | ||
} else { | ||
needsUpdate = versionInfo.latest !== current; | ||
} | ||
} | ||
|
||
version.value = { | ||
latest: usesNext ? versionInfo?.next : versionInfo?.latest, | ||
current, | ||
currentShort: usesNext ? 'next' : current, | ||
needsUpdate, | ||
}; | ||
}); | ||
|
||
return version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters