Skip to content

Commit fd33271

Browse files
committed
feat: Add GitHub workflows for stale issues, label generation, dependency review, and semantic PR checks
Signed-off-by: Gabryel Nóbrega <gabryelster@gmail.com>
1 parent 6e7f32b commit fd33271

File tree

7 files changed

+355
-3
lines changed

7 files changed

+355
-3
lines changed

.github/ci-scripts/labeler.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// module.exports = async ({ github, context }) => {
2+
/**
3+
* GitHub Action to automatically label pull requests based on modified files.
4+
*
5+
* @param {Object} params - The parameters for the action.
6+
* @param {Object} params.github - The GitHub API object.
7+
* @param {Object} params.context - The context of the GitHub Action.
8+
* @param {Object} params.context.repo - The repository context.
9+
* @param {string} params.context.repo.owner - The owner of the repository.
10+
* @param {string} params.context.repo.repo - The name of the repository.
11+
* @param {Object} params.context.issue - The issue context.
12+
* @param {number} params.context.issue.number - The pull request number.
13+
*
14+
* @returns {Promise<void>} A promise that resolves when the action is complete.
15+
*/
16+
export default async ({ github, context }) => {
17+
let newCompLbls = new Set(); // Set of new label strings
18+
19+
// Fetch files modified in the PR
20+
const pulledFiles = await github.rest.pulls.listFiles({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
pull_number: context.issue.number,
24+
});
25+
26+
// Identify labels based on file paths
27+
for (const f of pulledFiles.data) {
28+
switch (true) {
29+
case /^ci-scripts\/.*/.test(f.filename):
30+
console.log("CI-related file changed: " + f.filename);
31+
newCompLbls.add("component: ci");
32+
newCompLbls.add("component: ci-scripts");
33+
break;
34+
35+
case /^\.github\/workflows\/.*/.test(f.filename):
36+
console.log("CI-related file changed: " + f.filename);
37+
newCompLbls.add("component: ci");
38+
newCompLbls.add("component: workflows");
39+
break;
40+
41+
case /^third_party\/build\/.*/.test(f.filename):
42+
console.log("Third party file changed: " + f.filename);
43+
newCompLbls.add("component: orc8r");
44+
break;
45+
46+
case /^docs\/.*/.test(f.filename):
47+
console.log("Docs-related file changed: " + f.filename);
48+
newCompLbls.add("component: docs");
49+
break;
50+
}
51+
}
52+
53+
const curLblObjs = await github.rest.issues.listLabelsOnIssue({
54+
issue_number: context.issue.number,
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
});
58+
59+
// Remove outdated labels and keep only new ones
60+
for (const l of curLblObjs.data) {
61+
if (l.name.startsWith("component: ")) {
62+
if (newCompLbls.has(l.name)) {
63+
newCompLbls.delete(l.name);
64+
} else {
65+
await github.rest.issues.removeLabel({
66+
issue_number: context.issue.number,
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
name: l.name,
70+
});
71+
}
72+
}
73+
}
74+
75+
if (newCompLbls.size > 0) {
76+
let uniqLbls = Array.from(newCompLbls);
77+
await github.rest.issues.addLabels({
78+
issue_number: context.issue.number,
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
labels: uniqLbls,
82+
});
83+
} else {
84+
console.log("No new component files changed in this PR.");
85+
}
86+
};

.github/workflows/codeql.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
branches: [ "main" ]
19+
schedule:
20+
- cron: '27 2 * * 6'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
45+
# Use `c-cpp` to analyze code written in C, C++ or both
46+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
47+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
48+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
49+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
50+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
51+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
52+
53+
# matrix:
54+
# include:
55+
steps:
56+
- name: Checkout repository
57+
uses: actions/checkout@v4
58+
59+
# Add any setup steps before running the `github/codeql-action/init` action.
60+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
61+
# or others). This is typically only required for manual builds.
62+
# - name: Setup runtime (example)
63+
# uses: actions/setup-example@v1
64+
65+
# Initializes the CodeQL tools for scanning.
66+
- name: Initialize CodeQL
67+
uses: github/codeql-action/init@v3
68+
with:
69+
languages: ${{ matrix.language }}
70+
build-mode: ${{ matrix.build-mode }}
71+
# If you wish to specify custom queries, you can do so here or in a config file.
72+
# By default, queries listed here will override any specified in a config file.
73+
# Prefix the list here with "+" to use these queries and those in the config file.
74+
75+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
76+
# queries: security-extended,security-and-quality
77+
78+
# If the analyze step fails for one of the languages you are analyzing with
79+
# "We were unable to automatically build your code", modify the matrix above
80+
# to set the build mode to "manual" for that language. Then modify this step
81+
# to build your code.
82+
# ℹ️ Command-line programs to run using the OS shell.
83+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
84+
- if: matrix.build-mode == 'manual'
85+
shell: bash
86+
run: |
87+
echo 'If you are using a "manual" build mode for one or more of the' \
88+
'languages you are analyzing, replace this with the commands to build' \
89+
'your code, for example:'
90+
echo ' make bootstrap'
91+
echo ' make release'
92+
exit 1
93+
94+
- name: Perform CodeQL Analysis
95+
uses: github/codeql-action/analyze@v3
96+
with:
97+
category: "/language:${{matrix.language}}"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Dependency Review Action
2+
#
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable
6+
# packages will be blocked from merging.
7+
#
8+
# Source repository: https://github.com/actions/dependency-review-action
9+
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
10+
name: 'Dependency review'
11+
on:
12+
pull_request:
13+
branches: [ "main" ]
14+
15+
# If using a dependency submission action in this workflow this permission will need to be set to:
16+
#
17+
# permissions:
18+
# contents: write
19+
#
20+
# https://docs.github.com/en/enterprise-cloud@latest/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api
21+
permissions:
22+
contents: read
23+
# Write permissions for pull-requests are required for using the `comment-summary-in-pr` option, comment out if you aren't using this option
24+
pull-requests: write
25+
26+
jobs:
27+
dependency-review:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: 'Checkout repository'
31+
uses: actions/checkout@v4
32+
- name: 'Dependency Review'
33+
uses: actions/dependency-review-action@v4
34+
# Commonly enabled options, see https://github.com/actions/dependency-review-action#configuration-options for all available options.
35+
with:
36+
comment-summary-in-pr: always
37+
# fail-on-severity: moderate
38+
# deny-licenses: GPL-1.0-or-later, LGPL-2.0-or-later
39+
# retry-on-snapshot-warnings: true

.github/workflows/label.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: PR Generate Labels
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened, synchronize]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
AutoLabelPR:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repository
16+
uses: actions/checkout@v4
17+
18+
- name: Apply Labels Based on File Paths
19+
uses: actions/labeler@v4
20+
with:
21+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
22+
23+
- name: Apply Labels Dynamically with GitHub Script
24+
uses: actions/github-script@v7
25+
with:
26+
script: |
27+
const labeler = require('./.github/ci-scripts/labeler.js');
28+
await labeler({ github, context });

.github/workflows/semantic.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: PR Check Title Or Commit Message
2+
3+
on:
4+
# Semantic PR module only works with pull_request_target
5+
pull_request_target:
6+
types:
7+
- opened
8+
- reopened
9+
- edited
10+
- synchronize
11+
- ready_for_review
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
check-semantic-pr:
19+
runs-on: ubuntu-latest
20+
steps:
21+
22+
- uses: amannn/action-semantic-pull-request@v5
23+
id: semantic-pr
24+
if: ${{ ! startsWith(github.event.pull_request.title, 'Revert ') }}
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
with:
28+
# Configure which types are allowed.
29+
# Default: https://github.com/commitizen/conventional-commit-types
30+
types: |
31+
feat
32+
fix
33+
docs
34+
style
35+
refactor
36+
perf
37+
test
38+
build
39+
ci
40+
chore
41+
revert
42+
# Configure which scopes are allowed.
43+
scopes: |
44+
api
45+
cli
46+
core
47+
docs
48+
infra
49+
plugins
50+
tests
51+
# Configure that a scope must always be provided.
52+
requireScope: false
53+
# For work-in-progress PRs you can typically use draft pull requests
54+
# from GitHub. However, private repositories on the free plan don't have
55+
# this option and therefore this action allows you to opt in to using the
56+
# special "[WIP]" prefix to indicate this state. This will avoid the
57+
# validation of the PR title and the pull request checks remain pending.
58+
# Note that a second check will be reported if this is enabled.
59+
wip: true
60+
# When using "Squash and merge" on a PR with only one commit, GitHub
61+
# will suggest using that commit message instead of the PR title for the
62+
# merge commit, and it's easy to commit this by mistake. Enable this option
63+
# to also validate the commit message for one commit PRs.
64+
validateSingleCommit: true
65+
66+
- uses: actions/checkout@v4
67+
if: always()
68+
69+
- uses: ./.github/workflows/composite/comment-on-pr
70+
if: always()
71+
env:
72+
check-type: Semantic PR check
73+
check-documentation: |
74+
See instructions on [development process](https://github.com/see7e/github-templates/wiki/03-Development-Process).
75+
with:
76+
check-type: ${{ env.check-type }}
77+
check-documentation: ${{ env.check-documentation }}
78+
job-status: ${{ steps.semantic-pr.outcome }}

.github/workflows/stale.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time.
2+
#
3+
# You can adjust the behavior by modifying this file.
4+
# For more information, see:
5+
# https://github.com/actions/stale
6+
name: Mark stale issues and pull requests
7+
8+
on:
9+
schedule:
10+
- cron: '25 6 * * *'
11+
12+
jobs:
13+
stale:
14+
15+
runs-on: ubuntu-latest
16+
permissions:
17+
issues: write
18+
pull-requests: write
19+
20+
steps:
21+
- uses: actions/stale@v5
22+
with:
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
24+
stale-issue-message: 'Stale issue message'
25+
stale-pr-message: 'Stale pull request message'
26+
stale-issue-label: 'no-issue-activity'
27+
stale-pr-label: 'no-pr-activity'

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# TODO
2-
- [ ] Add Action Workflows
3-
41
# References
52
> If I forgot to add any reference, please contact me so I can fix it.
63

0 commit comments

Comments
 (0)