-
-
Notifications
You must be signed in to change notification settings - Fork 82
141 lines (121 loc) · 5.24 KB
/
test-jars.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
name: Download Random JARs from Maven
on:
schedule:
- cron: '0 9 * * 1' # '0' : 0th minute, '9' : Hour (9 AM) '*' : Day of the month '*' : Month '1' : Day of the week (0 is sunday, 1 is monday)
workflow_dispatch: # Manual trigger of this action
jobs:
download-jars:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run:
pip install requests
# - name: Download Metadata
# id: download-metadata
# uses: actions/download-artifact@v3
# with:
# name: metadata
# path: metadata
# continue-on-error: true # Allows workflow to continue even if the artifact metadata is not found (obviously it will not be found for the first run)
- name: Download random JARs
id: download
run: |
python .github/download_jars.py
env:
METADATA_PATH: metadata/metadata.json
- name: Upload Metadata
uses: actions/upload-artifact@v3
with:
name: metadata
path: metadata/metadata.json
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-package: 'jdk'
java-version: '8'
- name: Install Maven
run: |
sudo apt-get update
sudo apt-get install -y maven
- name: Run Maven
run: |
mvn clean install -DskipTests
- name: Run tests on downloaded JARs
run: |
# Get the current date in YYYY-MM-DD format
current_date=$(date +"%Y-%m-%d")
echo "CURRENT_DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
# Loop through each artifact in metadata.json that matches the current date
for row in $(jq -c --arg date "$current_date" '.jars[] | select(.date == $date)' ${{ github.workspace }}/metadata/metadata.json); do
# Extract artifactId and download_url from each object
artifactId=$(echo "$row" | jq -r '.name')
downloadUrl=$(echo "$row" | jq -r '.download_url')
echo "Testing $artifactId from $downloadUrl"
mvn test -Dtest=sootup.java.bytecode.frontend.inputlocation.RandomJarTest#testJar -DjarPath="$downloadUrl" -pl sootup.java.bytecode.frontend
done
- name: Check for jar_failure.csv
id: check_file
if: ${{ hashFiles('sootup.java.bytecode.frontend/jar_failure.csv') != '' }}
run: |
echo "jar_failure.csv exists"
# Read all jar_names from the CSV and store them in an environment variable
jar_names=$(awk -F, 'NR>1 {print $1}' sootup.java.bytecode.frontend/jar_failure.csv | paste -sd "," -)
echo "JAR_NAMES=${jar_names}" >> $GITHUB_ENV
- name: Set branch name with timestamp
id: set_branch_name
if: env.JAR_NAMES != ''
run: |
# Get the current week number and timestamp
current_date=$(date +%Y%m%d)
branch_name="failed-jars-branch-${current_date}"
echo "BRANCH_NAME=${branch_name}" >> $GITHUB_ENV
- name: Create a Test File
if: env.JAR_NAMES != ''
run: |
mvn test -Dtest=sootup.java.bytecode.frontend.inputlocation.RandomJarTest#writeFile -pl sootup.java.bytecode.frontend
- name: Configure Git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
- name: Create new branch and prepare files
if: env.JAR_NAMES != ''
run: |
# Create a branch named `failed-jars-branch`
git checkout -b ${{ env.BRANCH_NAME }}
echo 'New Branch Checked Out'
# Add jar_failure.csv to the new directory
git add sootup.java.bytecode.frontend/jar_failure.csv
git add sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/inputlocation/FixJars.java
echo 'CSV file Added to git'
- name: Create Issue
if: env.JAR_NAMES != ''
run: |
echo "Repository: ${{ github.repository }}"
echo "Token: ${{ secrets.GITHUB_TOKEN }}"
ISSUE_RESPONSE=$(curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d '{"title":"Issue Title","body":"This is the issue body"}' \
https://api.github.com/repos/${{ github.repository }}/issues)
ISSUE_NUMBER=$(echo "$ISSUE_RESPONSE" | jq '.number')
echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $GITHUB_ENV
- name: Move files and commit changes
if: env.JAR_NAMES != ''
run: |
echo " Token: ${{ secrets.GITHUB_TOKEN }}"
# Move jar files listed in jar_failure.csv
git mv sootup.java.bytecode.frontend/jar_failure.csv sootup.java.bytecode.frontend/src/test/resources/jar_failure.csv
echo 'jar_failure.csv moved to the branch'
# Commit and push changes
git add .
git commit -m "Linking issue #${{ env.ISSUE_NUMBER }} to the branch"
git push origin ${{ env.BRANCH_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}