-
Notifications
You must be signed in to change notification settings - Fork 54
198 lines (160 loc) · 7.64 KB
/
CI_pipeline.yml
File metadata and controls
198 lines (160 loc) · 7.64 KB
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
192
193
194
195
196
197
198
name: CI Pipeline
on:
push:
branches:
- v2
pull_request:
branches:
- v2
jobs:
verify-docker:
runs-on: ubuntu-latest
env:
CONDA_PLUGINS_AUTO_ACCEPT_TOS: true
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Build image
run: docker build -f Dockerfile --platform linux/x86_64 -t iris:latest .
- name: Run image
run: docker run --platform=linux/amd64 iris:latest
get-projects:
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.read-json.outputs.projects }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Read projects and parameters from JSON
id: read-json
run: |
JSON_FILE=".github/workflows/to_build.json"
PROJECTS_JSON=$(cat "$JSON_FILE" | jq -c .)
echo "Detected projects and parameters: $PROJECTS_JSON"
echo "projects=$PROJECTS_JSON" >> $GITHUB_OUTPUT
build-and-analyze:
needs: get-projects
runs-on: ubuntu-latest
strategy:
matrix:
include: ${{ fromJson(needs.get-projects.outputs.projects) }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
auto-activate-base: false
activate-environment: iris
auto-update-conda: true
- name: Set up Java version ${{ matrix.java_version }}
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java_version }}
- name: Install Maven ${{ matrix.maven_version }}
if: ${{ matrix.maven_version != '' }}
run: |
MAVEN_VERSION="${{ matrix.maven_version }}"
MAVEN_TAR="apache-maven-${MAVEN_VERSION}-bin.tar.gz"
MAVEN_URL="https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/${MAVEN_TAR}"
MAVEN_INSTALL_DIR="/opt/maven/apache-maven-${MAVEN_VERSION}"
echo "Downloading Maven ${MAVEN_VERSION}..."
sudo curl -fSL "$MAVEN_URL" -o "/tmp/${MAVEN_TAR}" || { echo "Failed to download Maven!"; exit 1; }
echo "Creating Maven install directory: ${MAVEN_INSTALL_DIR}"
sudo mkdir -p "${MAVEN_INSTALL_DIR}"
echo "Extracting Maven to ${MAVEN_INSTALL_DIR}..."
sudo tar -xzf "/tmp/${MAVEN_TAR}" -C "/opt/maven/" || { echo "Failed to extract Maven!"; exit 1; }
echo "Setting MAVEN_HOME and adding to PATH..."
echo "MAVEN_HOME=${MAVEN_INSTALL_DIR}" >> $GITHUB_ENV
echo "M2_HOME=${MAVEN_INSTALL_DIR}" >> $GITHUB_ENV
echo "${MAVEN_INSTALL_DIR}/bin" >> $GITHUB_PATH
echo "Maven ${MAVEN_VERSION} installed to ${MAVEN_INSTALL_DIR}"
echo "------------------------------------------------"
- name: Install Gradle ${{ matrix.gradle_version }}
if: ${{ matrix.gradle_version != '' }}
run: |
GRADLE_VERSION="${{ matrix.gradle_version }}"
GRADLE_ZIP="gradle-${GRADLE_VERSION}-bin.zip"
GRADLE_URL="https://services.gradle.org/distributions/${GRADLE_ZIP}"
GRADLE_INSTALL_DIR="/opt/gradle/gradle-${GRADLE_VERSION}"
echo "Downloading Gradle ${GRADLE_VERSION}..."
sudo curl -fSL "$GRADLE_URL" -o "/tmp/${GRADLE_ZIP}" || { echo "Failed to download Gradle!"; exit 1; }
echo "Creating Gradle install directory: ${GRADLE_INSTALL_DIR}"
sudo mkdir -p "${GRADLE_INSTALL_DIR}"
echo "Extracting Gradle to ${GRADLE_INSTALL_DIR}..."
sudo unzip -q "/tmp/${GRADLE_ZIP}" -d "/opt/gradle/" || { echo "Failed to extract Gradle!"; exit 1; }
echo "Setting GRADLE_HOME and adding to PATH..."
echo "GRADLE_HOME=${GRADLE_INSTALL_DIR}" >> $GITHUB_ENV
echo "${GRADLE_INSTALL_DIR}/bin" >> $GITHUB_PATH
echo "Gradle ${GRADLE_VERSION} installed to ${GRADLE_INSTALL_DIR}"
echo "------------------------------------------------"
- name: Download and Extract CodeQL Bundle
run: |
# Download the CodeQL bundle
curl -L https://github.com/github/codeql-action/releases/download/codeql-bundle-v2.23.2/codeql-bundle-linux64.tar.gz -o codeql-bundle.tar.gz || exit 1
# Extract the bundle
tar -xzf codeql-bundle.tar.gz || exit 1
# Store the absolute path to the extracted CodeQL directory in GITHUB_ENV.
echo "CODEQL_PATH=$(pwd)/codeql" >> $GITHUB_ENV
# Add the CodeQL executable's directory to the PATH for all subsequent steps.
echo "$(pwd)/codeql" >> $GITHUB_PATH
- name: Update CodeQL Query version in config
run: sed -i "s/^CODEQL_QUERY_VERSION = \".*\"$/CODEQL_QUERY_VERSION = \"1.8.1\"/" src/config.py
- name: Update JDK Path in dep_configs.json for ${{ matrix.java_version }}
run: |
sudo apt-get update && sudo apt-get install -y moreutils
CURRENT_JAVA_VERSION="${{ matrix.java_version }}"
JAVA_HOME_TO_USE=""
case "$CURRENT_JAVA_VERSION" in
"8")
JAVA_HOME_TO_USE="/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/8.0.472-8/x64"
;;
"11")
JAVA_HOME_TO_USE="/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/11.0.23-9/x64"
;;
"17")
JAVA_HOME_TO_USE="/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.11-9/x64"
;;
*)
echo "Error: Unsupported Java version '$CURRENT_JAVA_VERSION'."
exit 1
;;
esac
jq \
--arg current_java_version "$CURRENT_JAVA_VERSION" \
--arg java_home_path "$JAVA_HOME_TO_USE" \
'.jdks[$current_java_version] = $java_home_path' \
"dep_configs.json" | sponge "dep_configs.json"
- name: Relocate cached output for ${{ matrix.project_slug }}
run: |
mkdir -p output/${{ matrix.project_slug }}/test/analysis/${{ matrix.cwe }}
mv .github/cached_output/${{ matrix.project_slug }}/* output/${{ matrix.project_slug }}/test/analysis/${{ matrix.cwe }}/
- name: Build project ${{ matrix.project_slug }}
run: |
echo "--- Building ${{ matrix.project_slug }} ---"
conda run -n iris python scripts/fetch_and_build.py --filter ${{ matrix.project_slug }}
echo "--------------------------------"
- name: Generate CodeQL database for ${{ matrix.project_slug }}
run: |
echo "--- Generating CodeQL database for ${{ matrix.project_slug }} ---"
conda run -n iris python scripts/build_codeql_dbs.py --project ${{ matrix.project_slug }}
echo "----------------------------------"
- name: Run IRIS for ${{ matrix.project_slug }} with CWE ${{ matrix.cwe }}
run: |
echo "--- Running IRIS for ${{ matrix.project_slug }} ---"
conda run -n iris python src/iris.py --query ${{ matrix.cwe }} --run-id test --overwrite-api-candidates --overwrite-func-param-candidates --skip-posthoc-filter ${{ matrix.project_slug }}
echo "--------------------"
- name: Verify output file existence
run: |
JSON_FILE="output/${{ matrix.project_slug }}/test/${{ matrix.cwe }}-final/results.json"
echo "Checking for .json file: $JSON_FILE"
if [ -f "$JSON_FILE" ]; then
echo ".json file found: $JSON_FILE"
else
echo "Error: .json file not found at $JSON_FILE"
exit 1
fi