-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
100 lines (84 loc) · 3.53 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: 'SCC Complexity Check'
description: 'Automatically analyzes code complexity using the SCC tool when a Pull Request is opened, providing metrics about complexity and lines of code differences between branches'
author: 'Azion Technologies'
branding:
icon: 'file-text'
color: 'blue'
inputs:
github_token:
description: 'GitHub token for API access'
required: false
default: ${{ github.token }}
runs:
using: 'composite'
steps:
- name: Install dependencies and SCC
shell: bash
run: |
# Ensure jq and curl are installed
sudo apt-get update
sudo apt-get install -y jq curl
# Verify jq and curl installation
jq --version
curl --version
# Create bin directory if it doesn't exist
mkdir -p $HOME/bin
# Download and install SCC - using the latest release URL
LATEST_SCC_VERSION=$(curl -s https://api.github.com/repos/boyter/scc/releases/latest | jq -r '.tag_name')
curl -sSLf https://github.com/boyter/scc/releases/download/${LATEST_SCC_VERSION}/scc_Linux_x86_64.tar.gz -o scc.tar.gz
mkdir -p scc_temp && tar -xzf scc.tar.gz -C scc_temp
mv scc_temp/scc $HOME/bin/
rm -rf scc_temp scc.tar.gz
chmod +x $HOME/bin/scc
export PATH=$HOME/bin:$PATH
echo "PATH=$HOME/bin:$PATH" >> $GITHUB_ENV
# Verify SCC installation
scc --version
# Checkout target branch (base_ref)
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
fetch-depth: 0
- name: Calculate target branch complexity
shell: bash
id: target-complexity
run: |
echo "TARGET_COMPLEXITY=$(scc --format=json | jq -r '[.[].Complexity] | add')" >> $GITHUB_ENV
echo "TARGET_CODE=$(scc --format=json | jq -r '[.[].Code] | add')" >> $GITHUB_ENV
# Checkout source branch (head_ref)
- name: Checkout source branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Calculate source branch complexity
shell: bash
id: source-complexity
run: |
echo "SOURCE_COMPLEXITY=$(scc --format=json | jq -r '[.[].Complexity] | add')" >> $GITHUB_ENV
echo "SOURCE_CODE=$(scc --format=json | jq -r '[.[].Code] | add')" >> $GITHUB_ENV
- name: Calculate differences
shell: bash
id: calculate-diff
run: |
echo "COMPLEXITY_DIFF=$(($SOURCE_COMPLEXITY - $TARGET_COMPLEXITY))" >> $GITHUB_ENV
echo "CODE_DIFF=$(($SOURCE_CODE - $TARGET_CODE))" >> $GITHUB_ENV
- name: Add PR comment
uses: actions/github-script@v6
with:
github-token: ${{ inputs.github_token }}
script: |
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `## SCC Complexity Analysis
- Title: ${{ github.event.pull_request.title }}
- Author: ${{ github.event.pull_request.user.login }}
| Metric | Source Branch (${{ github.head_ref }}) | Target Branch (${{ github.base_ref }}) | Difference |
|--------|--------------|--------------|------------|
| Complexity | ${{ env.SOURCE_COMPLEXITY }} | ${{ env.TARGET_COMPLEXITY }} | ${{ env.COMPLEXITY_DIFF }} |
| Code | ${{ env.SOURCE_CODE }} | ${{ env.TARGET_CODE }} | ${{ env.CODE_DIFF }} |`
});