Skip to content

Commit

Permalink
Fix version check partially (#2871)
Browse files Browse the repository at this point in the history
ref #2748 

- fix link to releases
- fix jq syntax
- support rc versions (separate json field)

---------

Co-authored-by: Anbraten <anton@ju60.de>
  • Loading branch information
qwerty287 and anbraten authored Nov 26, 2023
1 parent 981384b commit ffb3bd8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .woodpecker/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ steps:
- git config --global user.name "woodpecker-bot"
- git clone --depth 1 --single-branch git@github.com:woodpecker-ci/woodpecker-ci.github.io.git /repo
# update latest and next version
- if [ "$CI_PIPELINE_EVENT" == "tag" ] ; then jq '.latest = ${CI_COMMIT_TAG}' /repo/version.json > /repo/version.json.tmp && mv /repo/version.json.tmp /repo/version.json ; fi
- if [[ "$CI_PIPELINE_EVENT" == "tag" && "${CI_COMMIT_TAG}" != *"rc"* ]] ; then jq '.latest = "${CI_COMMIT_TAG}"' /repo/version.json > /repo/version.json.tmp && mv /repo/version.json.tmp /repo/version.json ; fi
- if [[ "$CI_PIPELINE_EVENT" == "tag" ]] ; then jq '.rc = "${CI_COMMIT_TAG}"' /repo/version.json > /repo/version.json.tmp && mv /repo/version.json.tmp /repo/version.json ; fi
- if [ "$CI_PIPELINE_EVENT" == "push" ] ; then jq '.next = "next-${CI_COMMIT_SHA:0:10}"' /repo/version.json > /repo/version.json.tmp && mv /repo/version.json.tmp /repo/version.json ; fi
# copy all docs files and delete all old ones, but leave CNAME and index.yaml untouched
- rsync -r --exclude .git --exclude CNAME --exclude index.yaml --exclude README.md --exclude version.json --delete docs/build/ /repo
Expand Down
2 changes: 1 addition & 1 deletion web/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ declare module 'vue' {
IMdiGestureTap: typeof import('~icons/mdi/gesture-tap')['default']
IMdiGithub: typeof import('~icons/mdi/github')['default']
IMdiLoading: typeof import('~icons/mdi/loading')['default']
IMdiSync: typeof import('~icons/mdi/sync')['default']
IMdiSourceBranch: typeof import('~icons/mdi/source-branch')['default']
IMdisourceCommit: typeof import('~icons/mdi/source-commit')['default']
IMdiSourcePull: typeof import('~icons/mdi/source-pull')['default']
IMdiSync: typeof import('~icons/mdi/sync')['default']
IMdiTagOutline: typeof import('~icons/mdi/tag-outline')['default']
InputField: typeof import('./src/components/form/InputField.vue')['default']
IPhGitlabLogoSimpleFill: typeof import('~icons/ph/gitlab-logo-simple-fill')['default']
Expand Down
4 changes: 4 additions & 0 deletions web/src/components/admin/settings/AdminInfoTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
<Error v-if="version?.needsUpdate">
<i18n-t keypath="update_woodpecker" tag="span">
<a
v-if="!version.usesNext"
:href="`https://github.com/woodpecker-ci/woodpecker/releases/tag/${version.latest}`"
target="_blank"
rel="noopener noreferrer"
class="underline"
>{{ version.latest }}</a
>
<span v-else>
{{ version.latest }}
</span>
</i18n-t>
</Error>
</div>
Expand Down
19 changes: 13 additions & 6 deletions web/src/compositions/useVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useConfig from './useConfig';

type VersionInfo = {
latest: string;
rc: string;
next: string;
};

Expand All @@ -13,6 +14,7 @@ const version = ref<{
current: string;
currentShort: string;
needsUpdate: boolean;
usesNext: boolean;
}>();

async function fetchVersion(): Promise<VersionInfo | undefined> {
Expand All @@ -37,7 +39,7 @@ export function useVersion() {

const config = useConfig();
const current = config.version as string;
const usesNext = config.version?.startsWith('next');
const usesNext = current.startsWith('next');

const { user } = useAuthentication();
if (!user?.admin) {
Expand All @@ -46,6 +48,7 @@ export function useVersion() {
current,
currentShort: usesNext ? 'next' : current,
needsUpdate: false,
usesNext,
};
return version;
}
Expand All @@ -56,27 +59,31 @@ export function useVersion() {
current,
currentShort: current,
needsUpdate: false,
usesNext,
};
return version;
}

onMounted(async () => {
const versionInfo = await fetchVersion();

let needsUpdate = false;
let latest;
if (versionInfo) {
if (usesNext) {
needsUpdate = versionInfo.next !== current;
latest = versionInfo.next;
} else if (current.includes('rc')) {
latest = versionInfo.rc;
} else {
needsUpdate = versionInfo.latest !== current;
latest = versionInfo.latest;
}
}

version.value = {
latest: usesNext ? versionInfo?.next : versionInfo?.latest,
latest,
current,
currentShort: usesNext ? 'next' : current,
needsUpdate,
needsUpdate: latest !== undefined && latest !== current,
usesNext,
};
});

Expand Down

0 comments on commit ffb3bd8

Please sign in to comment.