-
Notifications
You must be signed in to change notification settings - Fork 7
191 lines (167 loc) · 6.87 KB
/
specimin_evaluation_CI.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: specimin_evaluation_CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
specimin-evaluation:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Set up Java JDK
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'adopt'
architecture: 'x64'
server-password: ${{ secrets.GITHUB_TOKEN }}
overwrite-settings: true
check-latest: false
- name: Install dependencies
run: |
set -ex # Exit immediately if a command exits with a non-zero status and print commands as they are executed
python -m pip install --upgrade pip
- name: Display CSV File Contents loaded in working environment
run: |
set -ex
if [ -f /home/runner/work/specimin/specimin/CI_repository_list.csv ]; then
cat /home/runner/work/specimin/specimin/CI_repository_list.csv
else
echo "File /home/runner/work/specimin/specimin/CI_repository_list.csv does not exist"
exit 1
fi
- name: Clone ASHE Project
run: |
set -ex
git clone https://github.com/njit-jerse/ASHE_Automated-Software-Hardening-for-Entrypoints ASHE
- name: Create ASHE Clone SPACE Directory
run: |
set -ex
mkdir -p $(pwd)/ASHE/CI_REPO_CLONE_SPACE
chmod 777 $(pwd)/ASHE/CI_REPO_CLONE_SPACE
ls -ld $(pwd)/ASHE/CI_REPO_CLONE_SPACE
- name: Verify example.properties exists
run: |
set -ex
if [ -f ASHE/src/main/resources/example.properties ]; then
echo "example.properties found"
else
echo "example.properties not found"
exit 1
fi
- name: Rename example.properties to config.properties file
run: |
set -ex
mv ASHE/src/main/resources/example.properties ASHE/src/main/resources/config.properties
if [ -f ASHE/src/main/resources/config.properties ]; then
echo "config.properties created"
else
echo "config.properties not created"
exit 1
fi
- name: Give write permissions to config.properties
run: |
set -ex
chmod +w ASHE/src/main/resources/config.properties
ls -l ASHE/src/main/resources/config.properties
- name: Update ASHE Config File to update SPECIMIN path
run: |
set -ex
chmod +w ASHE/src/main/resources/config.properties
# Update the specimin.tool.path key with the new value
sed -i 's|^specimin.tool.path=.*|specimin.tool.path='$(pwd)'|' ASHE/src/main/resources/config.properties
# Display the updated config.properties file for verification
cat ASHE/src/main/resources/config.properties
- name: Display updated config.properties
run: |
set -ex
cat ASHE/src/main/resources/config.properties
- name: Make all scripts under ashe_scripts executable
run: |
set -ex
chmod +x ashe_scripts/*.py
- name: List Files in ashe_scripts for Debugging
run: |
set -ex
ls -l ashe_scripts
- name: Run the script
run: |
set -ex
python3 ashe_scripts/run_ashe_for_stats.py \
$(pwd)/ASHE \
$(pwd)/CI_repository_list.csv \
$(pwd)/ASHE/CI_REPO_CLONE_SPACE \
$(pwd)/ASHE/src/main/resources/config.properties
- name: Parse accuracy percentage
id: parse_accuracy_percentage
run: |
set -ex
grep 'Fully successful from minimization to compilation' $(pwd)/ASHE/logs/specimin_statistics.txt | awk '{print $NF}' > current_run_accuracy_percentage.txt
cat current_run_accuracy_percentage.txt
- name: Read and update evaluation accuracy
id: read_and_update
run: |
set -ex
current_accuracy=$(cat current_run_accuracy_percentage.txt)
echo "Current accuracy: $current_accuracy"
previous_run_accuracy=${{ secrets.LATEST_SPECIMIN_EVAL_PERCENTAGE }}
if [ -z "$previous_run_accuracy" ]; then
previous_run_accuracy=0
fi
echo "Previous run accuracy: $previous_run_accuracy"
if (( $(echo "$current_accuracy > $previous_run_accuracy" | bc -l) )); then
echo "Updating LATEST_SPECIMIN_EVAL_PERCENTAGE to $current_accuracy"
echo "::set-output name=update_needed::true"
echo "::set-output name=new_accuracy::$current_accuracy"
else
echo "No update needed"
echo "::set-output name=update_needed::false"
echo "::set-output name=new_accuracy::$previous_run_accuracy"
fi
echo "Current accuracy: $current_accuracy" > comparison_values_for_current_run.txt
echo "Previous run accuracy: $previous_run_accuracy" >> comparison_values_for_current_run.txt
- name: Install jq and curl
run: |
set -ex
sudo apt-get update
sudo apt-get install -y jq curl
- name: Update Evaluation Accuracy Secret
if: steps.read_and_update.outputs.update_needed == 'true'
run: |
set -ex
new_accuracy=${{ steps.read_and_update.outputs.new_accuracy }}
repo_name="${{ github.repository }}"
api_url="https://api.github.com"
public_key_response=$(curl -s -H "Authorization: token ${{ secrets.LATEST_SPECIMIN_EVAL_PERCENTAGE_PAT }}" $api_url/repos/$repo_name/actions/secrets/public-key)
public_key=$(echo $public_key_response | jq -r .key)
key_id=$(echo $public_key_response | jq -r .key_id)
encrypted_value=$(echo -n "$new_accuracy" | openssl rsautl -encrypt -pubin -inkey <(echo "$public_key") | base64)
curl -s \
-X PUT \
-H "Authorization: token ${{ secrets.LATEST_SPECIMIN_EVAL_PERCENTAGE_PAT }}" \
-H "Content-Type: application/json" \
"$api_url/repos/$repo_name/actions/secrets/LATEST_SPECIMIN_EVAL_PERCENTAGE" \
-d "{\"encrypted_value\":\"$encrypted_value\",\"key_id\":\"$key_id\"}"
- name: Upload comparison values
if: always()
uses: actions/upload-artifact@v2
with:
name: comparison-values
path: comparison_values_for_current_run.txt
- name: Upload current run accuracy percentage
if: always()
uses: actions/upload-artifact@v2
with:
name: current-run-accuracy-percentage
path: current_run_accuracy_percentage.txt