Download Random JARs from Maven #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |