From 2e17ba20858d1a869d14c9d42b6a52b9db5f52e5 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Sun, 9 Jul 2023 23:05:17 +0200 Subject: [PATCH] ci: add beta release channel --- .woodpecker/publish.yaml | 25 +++++++++++++++++++++---- tools/bump-version.js | 14 ++++++++++++-- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.woodpecker/publish.yaml b/.woodpecker/publish.yaml index b03127a5..d1fc2705 100644 --- a/.woodpecker/publish.yaml +++ b/.woodpecker/publish.yaml @@ -12,7 +12,7 @@ variables: when: event: tag - evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$" + evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+(-[0-9]+)?$" depends_on: - checks @@ -44,6 +44,20 @@ steps: commands: - <<: *enable_pnpm - pnpm changelog + choose-latest-channel: + group: prepare-release + image: alpine:latest + commands: + - echo latest > .RELEASE_CHANNEL + when: + evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$" + choose-beta-channel: + group: prepare-release + image: alpine:latest + commands: + - echo beta > .RELEASE_CHANNEL + when: + evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+-[0-9]+$" release: image: woodpeckerci/plugin-gitea-release settings: @@ -55,14 +69,15 @@ steps: - ${CI_REPO_NAME}/system.json api_key: from_secret: forge_token - publish-latest-manifest: + publish-manifest: group: publish image: alpine:latest commands: - apk update - apk add curl - - 'curl --header "Authorization: token $${FORGE_TOKEN}" -X "DELETE" "${CI_FORGE_URL}/api/packages/${CI_REPO_OWNER}/generic/${CI_REPO_NAME}/latest/system.json"' - - 'curl --fail --header "Authorization: token $${FORGE_TOKEN}" --upload-file ${CI_REPO_NAME}/system.json "${CI_FORGE_URL}/api/packages/${CI_REPO_OWNER}/generic/${CI_REPO_NAME}/latest/system.json"' + - export RELEASE_CHANNEL=$(cat .RELEASE_CHANNEL) + - 'curl --header "Authorization: token $${FORGE_TOKEN}" -X "DELETE" "${CI_FORGE_URL}/api/packages/${CI_REPO_OWNER}/generic/${CI_REPO_NAME}/$${RELEASE_CHANNEL}/system.json"' + - 'curl --fail --header "Authorization: token $${FORGE_TOKEN}" --upload-file ${CI_REPO_NAME}/system.json "${CI_FORGE_URL}/api/packages/${CI_REPO_OWNER}/generic/${CI_REPO_NAME}/$${RELEASE_CHANNEL}/system.json"' secrets: - forge_token publish-to-foundry-admin: @@ -78,3 +93,5 @@ steps: - fvtt_package_id - fvtt_username - fvtt_password + when: + evaluate: CI_COMMIT_TAG matches "^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$" diff --git a/tools/bump-version.js b/tools/bump-version.js index fbac88b8..a49cfb29 100644 --- a/tools/bump-version.js +++ b/tools/bump-version.js @@ -13,7 +13,8 @@ const repositoryName = process.env.CI_REPO_NAME; const repositoryURL = process.env.CI_REPO_LINK; const forgeURL = process.env.CI_FORGE_URL; -const manifestURL = `${forgeURL}/api/packages/${repositoryOwner}/generic/${repositoryName}/latest/${packageType}.json`; +const getManifestUrl = (channel) => + `${forgeURL}/api/packages/${repositoryOwner}/generic/${repositoryName}/${channel}/${packageType}.json`; const getDownloadURL = (version) => `${repositoryURL}/releases/download/${version}/${repositoryName}.zip`; const bugsURL = `${repositoryURL}/issues`; const getChangelogURL = (version) => `${repositoryURL}/releases/tag/${version}`; @@ -46,6 +47,15 @@ function getTargetVersion(currentVersion, release) { } } +/** + * Get the channel for a given version. + * @param {string} version The version for which to get the channel + * @returns {"latest" | "beta"} The channel for the version + */ +function getChannel(version) { + return version.includes("-") ? "beta" : "latest"; +} + /** * Update version and download URL. * @param {semver.ReleaseType | string} release Either a semver release type or a valid semver version @@ -74,7 +84,7 @@ function bumpVersion(release) { fs.writeJSONSync("package.json", packageJson, { spaces: 4 }); manifest.version = targetVersion; manifest.url = repositoryURL; - manifest.manifest = manifestURL; + manifest.manifest = getManifestUrl(getChannel(targetVersion)); manifest.download = getDownloadURL(targetVersion); manifest.bugs = bugsURL; manifest.changelog = getChangelogURL(targetVersion);