|
| 1 | +# -------------------------------------------------------------------- |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed |
| 5 | +# with this work for additional information regarding copyright |
| 6 | +# ownership. The ASF licenses this file to You under the Apache |
| 7 | +# License, Version 2.0 (the "License"); you may not use this file |
| 8 | +# except in compliance with the License. You may obtain a copy of the |
| 9 | +# License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 16 | +# implied. See the License for the specific language governing |
| 17 | +# permissions and limitations under the License. |
| 18 | +# |
| 19 | +# -------------------------------------------------------------------- |
| 20 | +# GitHub Actions Workflow: Brand Name Check for Changes |
| 21 | +# -------------------------------------------------------------------- |
| 22 | +# Description: |
| 23 | +# This GitHub Actions workflow checks pull requests (PRs) for deprecated |
| 24 | +# terms related to "Cloudberry" and "Greenplum". It ensures consistent |
| 25 | +# usage of updated branding throughout the project. |
| 26 | +# |
| 27 | +# Purpose: |
| 28 | +# - Identify outdated terms such as "Cloudberry Database" or "Greenplum". |
| 29 | +# - Automatically comment on the PR, suggesting replacements where needed. |
| 30 | +# - Encourage the use of "Apache Cloudberry" or "Cloudberry" as standards. |
| 31 | +# |
| 32 | +# How it works: |
| 33 | +# - Triggers when a PR is opened, edited, or synchronized with its branch. |
| 34 | +# - Scans only the changes (diffs) in the PR, focusing on modified content. |
| 35 | +# - Posts a comment if deprecated terms are detected in the changes. |
| 36 | +# |
| 37 | +# Note: This GitHub Actions is not a required option for merging one |
| 38 | +# Pull Request, just as one reference for the brand check. |
| 39 | + |
| 40 | +name: Brand Name Checks for Diffs |
| 41 | + |
| 42 | +on: |
| 43 | + pull_request: |
| 44 | + types: [opened, edited, synchronize] |
| 45 | + |
| 46 | +jobs: |
| 47 | + check-brand-name: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + permissions: |
| 50 | + pull-requests: write |
| 51 | + contents: read |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Checkout code |
| 55 | + uses: actions/checkout@v3 |
| 56 | + |
| 57 | + - name: Check for Old Names in PR Diffs |
| 58 | + uses: actions/github-script@v6 |
| 59 | + with: |
| 60 | + script: | |
| 61 | + const prNumber = context.payload.pull_request.number; |
| 62 | + const owner = context.repo.owner; |
| 63 | + const repo = context.repo.repo; |
| 64 | +
|
| 65 | + // List of deprecated terms to check in PR changes |
| 66 | + const deprecatedTerms = [ |
| 67 | + "Cloudberry Database", |
| 68 | + "CloudberryDB", |
| 69 | + "Cloudberry DB", |
| 70 | + "Greenplum Database", |
| 71 | + "Greenplum", |
| 72 | + "GPDB" |
| 73 | + ]; |
| 74 | +
|
| 75 | + try { |
| 76 | + // Fetch the list of changed files in the PR |
| 77 | + const { data: files } = await github.rest.pulls.listFiles({ |
| 78 | + owner, |
| 79 | + repo, |
| 80 | + pull_number: prNumber, |
| 81 | + }); |
| 82 | +
|
| 83 | + // Check if there are any files changed in the PR |
| 84 | + if (!files.length) { |
| 85 | + console.log("No files changed in this PR."); |
| 86 | + return; |
| 87 | + } |
| 88 | +
|
| 89 | + // Initialize a set to store the found deprecated terms |
| 90 | + const foundTerms = new Set(); |
| 91 | +
|
| 92 | + // Iterate over each file in the PR changes |
| 93 | + for (const file of files) { |
| 94 | + // Check if the file has a patch (i.e., it has changes) |
| 95 | + if (file.patch) { |
| 96 | + // Iterate over each deprecated term |
| 97 | + for (const term of deprecatedTerms) { |
| 98 | + // Check if the deprecated term is in the file's patch |
| 99 | + if (file.patch.includes(term)) { |
| 100 | + // Add the deprecated term to the set of found terms |
| 101 | + foundTerms.add(term); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +
|
| 107 | + // Check if any deprecated terms were found |
| 108 | + if (foundTerms.size > 0) { |
| 109 | + // Create a comment body with the found deprecated terms |
| 110 | + const commentBody = ` |
| 111 | + > [!NOTE] |
| 112 | + > This is not a required check for merging this PR, just for your reference. |
| 113 | +
|
| 114 | + **Attention:** The following old brand terms were found in your changes: ${Array.from(foundTerms).map(term => `\`${term}\``)} |
| 115 | +
|
| 116 | + Please consider replacing them with "Apache Cloudberry" or "Cloudberry" where appropriate. Thank you for ensuring consistency in our branding! 🙏 |
| 117 | + `; |
| 118 | +
|
| 119 | + // Post a comment on the PR with the found deprecated terms |
| 120 | + await github.rest.issues.createComment({ |
| 121 | + owner, |
| 122 | + repo, |
| 123 | + issue_number: prNumber, |
| 124 | + body: commentBody, |
| 125 | + }); |
| 126 | + } |
| 127 | + } catch (error) { |
| 128 | + // Log any errors that occur during the script execution |
| 129 | + console.error("Error checking for deprecated terms:", error); |
| 130 | + } |
0 commit comments