forked from GreptimeTeam/greptimedb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: replace pull-request actions with cyborg (GreptimeTeam#3854)
* ci: replace pull-request actions with cyborg Signed-off-by: tison <[email protected]> * skip cron maintenance in forks Signed-off-by: tison <[email protected]> --------- Signed-off-by: tison <[email protected]>
- Loading branch information
Showing
13 changed files
with
233 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: "Semantic Pull Request" | ||
|
||
on: | ||
pull_request_target: | ||
types: | ||
- opened | ||
- reopened | ||
- edited | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-20.04 | ||
timeout-minutes: 10 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
- uses: pnpm/action-setup@v3 | ||
with: | ||
package_json_file: 'cyborg/package.json' | ||
run_install: true | ||
- name: Describe the Environment | ||
working-directory: cyborg | ||
run: pnpm tsx -v | ||
- name: Check Pull Request | ||
working-directory: cyborg | ||
run: pnpm tsx bin/check-pull-request.ts | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* 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 {handleError, obtainClient} from "@/common"; | ||
import {context} from "@actions/github"; | ||
import {PullRequestEvent} from "@octokit/webhooks-types"; | ||
import {Options, sync as conventionalCommitsParser} from 'conventional-commits-parser'; | ||
import conventionalCommitTypes from 'conventional-commit-types'; | ||
import _ from "lodash"; | ||
|
||
const defaultTypes = Object.keys(conventionalCommitTypes.types) | ||
const breakingChangeLabel = "breaking-change" | ||
|
||
// These options are copied from [1]. | ||
// [1] https://github.com/conventional-changelog/conventional-changelog/blob/3f60b464/packages/conventional-changelog-conventionalcommits/src/parser.js | ||
export const parserOpts: Options = { | ||
headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/, | ||
breakingHeaderPattern: /^(\w*)(?:\((.*)\))?!: (.*)$/, | ||
headerCorrespondence: [ | ||
'type', | ||
'scope', | ||
'subject' | ||
], | ||
noteKeywords: ['BREAKING CHANGE', 'BREAKING-CHANGE'], | ||
revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i, | ||
revertCorrespondence: ['header', 'hash'], | ||
issuePrefixes: ['#'] | ||
} | ||
|
||
async function main() { | ||
if (!context.payload.pull_request) { | ||
throw new Error(`Only pull request event supported. ${context.eventName} is unsupported.`) | ||
} | ||
|
||
const client = obtainClient("GITHUB_TOKEN") | ||
const payload = context.payload as PullRequestEvent | ||
const { owner, repo, number } = { | ||
owner: payload.pull_request.base.user.login, | ||
repo: payload.pull_request.base.repo.name, | ||
number: payload.pull_request.number, | ||
} | ||
const { data: pull_request } = await client.rest.pulls.get({ | ||
owner, repo, pull_number: number, | ||
}) | ||
|
||
const commit = conventionalCommitsParser(pull_request.title, parserOpts) | ||
core.info(`Receive commit: ${JSON.stringify(commit)}`) | ||
|
||
if (!commit.type) { | ||
throw Error(`Malformed commit: ${JSON.stringify(commit)}`) | ||
} | ||
|
||
if (!defaultTypes.includes(commit.type)) { | ||
throw Error(`Unexpected type ${JSON.stringify(commit.type)} of commit: ${JSON.stringify(commit)}`) | ||
} | ||
|
||
const breakingChanges = _.filter(commit.notes, _.matches({ title: 'BREAKING CHANGE'})) | ||
if (breakingChanges.length > 0) { | ||
await client.rest.issues.addLabels({ | ||
owner, repo, issue_number: number, labels: [breakingChangeLabel] | ||
}) | ||
} | ||
} | ||
|
||
main().catch(handleError) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 {config} from "dotenv"; | ||
import {getOctokit} from "@actions/github"; | ||
import {GitHub} from "@actions/github/lib/utils"; | ||
|
||
export function handleError(err: any): void { | ||
console.error(err) | ||
core.setFailed(`Unhandled error: ${err}`) | ||
} | ||
|
||
export function obtainClient(token: string): InstanceType<typeof GitHub> { | ||
config() | ||
return getOctokit(process.env[token]) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.