diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1b59f97764..42828b7f01 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -441,8 +441,8 @@ jobs: aws-region: ${{ vars.EC2_RUNNER_REGION }} github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - bump-doc-version: - name: Bump doc version + bump-downstream-repo-versions: + name: Bump downstream repo versions if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} needs: [allocate-runners, publish-github-release] runs-on: ubuntu-latest @@ -456,36 +456,16 @@ jobs: fetch-depth: 0 persist-credentials: false - uses: ./.github/actions/setup-cyborg - - name: Bump doc version + - name: Bump downstream repo versions 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 }} - - bump-website-version: - name: Bump website version - if: ${{ github.ref_type == 'tag' && !contains(github.ref_name, 'nightly') && github.event_name != 'schedule' }} - needs: [allocate-runners, publish-github-release] - runs-on: ubuntu-latest - # Permission reference: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs - permissions: - issues: write # Allows the action to create issues for cyborg. - contents: write # Allows the action to create a release. - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - persist-credentials: false - - uses: ./.github/actions/setup-cyborg - - name: Bump website version - working-directory: cyborg - run: pnpm tsx bin/bump-website-version.ts + run: pnpm tsx bin/bump-versions.ts env: + TARGET_REPOS: website,docs,demo VERSION: ${{ needs.allocate-runners.outputs.version }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} WEBSITE_REPO_TOKEN: ${{ secrets.WEBSITE_REPO_TOKEN }} + DOCS_REPO_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }} + DEMO_REPO_TOKEN: ${{ secrets.DEMO_REPO_TOKEN }} bump-helm-charts-version: name: Bump helm charts version diff --git a/cyborg/bin/bump-doc-version.ts b/cyborg/bin/bump-doc-version.ts deleted file mode 100644 index a85d36c22f..0000000000 --- a/cyborg/bin/bump-doc-version.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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); -} diff --git a/cyborg/bin/bump-versions.ts b/cyborg/bin/bump-versions.ts new file mode 100644 index 0000000000..ce9d3d21a0 --- /dev/null +++ b/cyborg/bin/bump-versions.ts @@ -0,0 +1,156 @@ +/* + * 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"; + +interface RepoConfig { + tokenEnv: string; + repo: string; + workflowLogic: (version: string) => [string, string] | null; +} + +const REPO_CONFIGS: Record = { + website: { + tokenEnv: "WEBSITE_REPO_TOKEN", + repo: "website", + workflowLogic: (version: string) => { + // Skip nightly versions for website + if (version.includes('nightly')) { + console.log('Nightly version detected for website, skipping workflow trigger.'); + return null; + } + return ['bump-patch-version.yml', version]; + } + }, + demo: { + tokenEnv: "DEMO_REPO_TOKEN", + repo: "demo-scene", + workflowLogic: (version: string) => { + // Skip nightly versions for demo + if (version.includes('nightly')) { + console.log('Nightly version detected for demo, skipping workflow trigger.'); + return null; + } + return ['bump-patch-version.yml', version]; + } + }, + docs: { + tokenEnv: "DOCS_REPO_TOKEN", + repo: "docs", + workflowLogic: (version: 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]; + } + } +}; + +async function triggerWorkflow(repoConfig: RepoConfig, workflowId: string, version: string) { + const client = obtainClient(repoConfig.tokenEnv); + try { + await client.rest.actions.createWorkflowDispatch({ + owner: "GreptimeTeam", + repo: repoConfig.repo, + workflow_id: workflowId, + ref: "main", + inputs: { + version, + }, + }); + console.log(`Successfully triggered ${workflowId} workflow for ${repoConfig.repo} with version ${version}`); + } catch (error) { + core.setFailed(`Failed to trigger workflow for ${repoConfig.repo}: ${error.message}`); + throw error; + } +} + +async function processRepo(repoName: string, version: string) { + const repoConfig = REPO_CONFIGS[repoName]; + if (!repoConfig) { + throw new Error(`Unknown repository: ${repoName}`); + } + + try { + const workflowResult = repoConfig.workflowLogic(version); + if (workflowResult === null) { + // Skip this repo (e.g., nightly version for website) + return; + } + + const [workflowId, apiVersion] = workflowResult; + await triggerWorkflow(repoConfig, workflowId, apiVersion); + } catch (error) { + core.setFailed(`Error processing ${repoName} with version ${version}: ${error.message}`); + throw error; + } +} + +async function main() { + 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; + + // Get target repositories from environment variable + // Default to both if not specified + const targetRepos = process.env.TARGET_REPOS?.split(',').map(repo => repo.trim()) || ['website', 'docs']; + + console.log(`Processing version ${cleanVersion} for repositories: ${targetRepos.join(', ')}`); + + const errors: string[] = []; + + // Process each repository + for (const repo of targetRepos) { + try { + await processRepo(repo, cleanVersion); + } catch (error) { + errors.push(`${repo}: ${error.message}`); + } + } + + if (errors.length > 0) { + core.setFailed(`Failed to process some repositories: ${errors.join('; ')}`); + process.exit(1); + } + + console.log('All repositories processed successfully'); +} + +// Execute main function +main().catch((error) => { + core.setFailed(`Unexpected error: ${error.message}`); + process.exit(1); +}); diff --git a/cyborg/bin/bump-website-version.ts b/cyborg/bin/bump-website-version.ts deleted file mode 100644 index 068047233b..0000000000 --- a/cyborg/bin/bump-website-version.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 websiteClient = obtainClient("WEBSITE_REPO_TOKEN") - try { - await websiteClient.rest.actions.createWorkflowDispatch({ - owner: "GreptimeTeam", - repo: "website", - 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}`); - } -} - -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; - -if (cleanVersion.includes('nightly')) { - console.log('Nightly version detected, skipping workflow trigger.'); - process.exit(0); -} - -try { - triggerWorkflow('bump-patch-version.yml', cleanVersion); -} catch (error) { - core.setFailed(`Error processing version: ${error.message}`); - process.exit(1); -}