From 5efcb4131070e88ba86e31e265502355187bf332 Mon Sep 17 00:00:00 2001 From: Yiran Date: Tue, 14 Jan 2025 16:20:58 +0800 Subject: [PATCH] ci: automatically bump doc version when release GreptimeDB (#5343) * ci: automatically bump doc version when release GreptimeDB * add license header --- .github/workflows/release.yml | 16 ++++++++ cyborg/bin/bump-doc-version.ts | 75 ++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 cyborg/bin/bump-doc-version.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8968d06b80..1e66626b34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -436,6 +436,22 @@ jobs: aws-region: ${{ vars.EC2_RUNNER_REGION }} github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + bump-doc-version: + name: Bump doc version + if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} + needs: [allocate-runners] + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-cyborg + - name: Bump doc version + working-directory: cyborg + run: pnpm tsx bin/bump-doc-version.ts + env: + VERSION: ${{ needs.allocate-runners.outputs.version }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCS_REPO_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }} + notification: if: ${{ github.repository == 'GreptimeTeam/greptimedb' && (github.event_name == 'push' || github.event_name == 'schedule') && always() }} name: Send notification to Greptime team diff --git a/cyborg/bin/bump-doc-version.ts b/cyborg/bin/bump-doc-version.ts new file mode 100644 index 0000000000..a85d36c22f --- /dev/null +++ b/cyborg/bin/bump-doc-version.ts @@ -0,0 +1,75 @@ +/* + * Copyright 2023 Greptime Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as core from "@actions/core"; +import {obtainClient} from "@/common"; + +async function triggerWorkflow(workflowId: string, version: string) { + const docsClient = obtainClient("DOCS_REPO_TOKEN") + try { + await docsClient.rest.actions.createWorkflowDispatch({ + owner: "GreptimeTeam", + repo: "docs", + workflow_id: workflowId, + ref: "main", + inputs: { + version, + }, + }); + console.log(`Successfully triggered ${workflowId} workflow with version ${version}`); + } catch (error) { + core.setFailed(`Failed to trigger workflow: ${error.message}`); + } +} + +function determineWorkflow(version: string): [string, string] { + // Check if it's a nightly version + if (version.includes('nightly')) { + return ['bump-nightly-version.yml', version]; + } + + const parts = version.split('.'); + + if (parts.length !== 3) { + throw new Error('Invalid version format'); + } + + // If patch version (last number) is 0, it's a major version + // Return only major.minor version + if (parts[2] === '0') { + return ['bump-version.yml', `${parts[0]}.${parts[1]}`]; + } + + // Otherwise it's a patch version, use full version + return ['bump-patch-version.yml', version]; +} + +const version = process.env.VERSION; +if (!version) { + core.setFailed("VERSION environment variable is required"); + process.exit(1); +} + +// Remove 'v' prefix if exists +const cleanVersion = version.startsWith('v') ? version.slice(1) : version; + +try { + const [workflowId, apiVersion] = determineWorkflow(cleanVersion); + triggerWorkflow(workflowId, apiVersion); +} catch (error) { + core.setFailed(`Error processing version: ${error.message}`); + process.exit(1); +}