Java CI with Gradle #122
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
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '58 18 * * *' | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Make gradlew runnable | |
run: | | |
chmod +x gradlew | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v3 | |
- name: Execute Gradle build | |
run: ./gradlew build | |
- name: Archive JAR Artifact | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar | |
retention-days: 1 | |
codeforces: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar codeforces | |
- name: Upload Codeforces Ratings | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: codeforces_ratings | |
path: ./codeforces_ratings.txt | |
retention-days: 1 | |
gfg: | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
GFG_USERNAME: ${{ secrets.GFG_USERNAME }} | |
GFG_PASSWORD: ${{ secrets.GFG_PASSWORD }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Install gecko driver | |
# Run shell script in src/main/resources/gecko.sh | |
run: | | |
chmod +x src/main/resources/gecko.sh | |
./src/main/resources/gecko.sh | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar gfg | |
- name: Upload GFG Ratings | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: gfg_ratings | |
path: ./gfg_ratings.txt | |
retention-days: 1 | |
gfg_practice: | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
GFG_USERNAME: ${{ secrets.GFG_USERNAME }} | |
GFG_PASSWORD: ${{ secrets.GFG_PASSWORD }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Install gecko driver | |
# Run shell script in src/main/resources/gecko.sh | |
run: | | |
chmod +x src/main/resources/gecko.sh | |
./src/main/resources/gecko.sh | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar gfg_practice | |
- name: Upload GFG Practice Ratings | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: gfg_practice_ratings | |
path: ./gfg_practice_ratings.txt | |
retention-days: 1 | |
leetcode: | |
runs-on: windows-latest | |
needs: build | |
env: | |
USERNAME: ${{ secrets.TEMP_GITHUB_PASSWORD }} | |
PASSWD: ${{ secrets.TEMP_GITHUB_USERNAME }} | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar load_data | |
- name: Set up Python 3.10 # Set up Python version 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.10" | |
- name: Install dependencies # Install Python dependencies from requirements.txt | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r src/main/python/requirements.txt | |
- name: Run the program # Run the Python main.py script | |
uses: nick-fields/retry@v3 | |
with: | |
timeout_minutes: 20 | |
max_attempts: 10 | |
retry_on: error | |
command: python -u src/main/python/scrape_leetcode.py | |
- name: Upload LeetCode Ratings | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: leetcode_ratings | |
path: ./leetcode_ratings.txt | |
retention-days: 1 | |
codechef: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar codechef | |
- name: Upload CodeChef Ratings | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: codechef_ratings | |
path: ./codechef_ratings.txt | |
retention-days: 1 | |
hackerrank: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar hackerrank | |
- name: Upload HackerRank Ratings | |
uses: actions/upload-artifact@v4.0.0 | |
with: | |
name: hackerrank_ratings | |
path: ./hackerrank_ratings.txt | |
retention-days: 1 | |
build_leaderboard: | |
runs-on: ubuntu-latest | |
needs: [codeforces, gfg, gfg_practice, leetcode, codechef, hackerrank] | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.1 | |
with: | |
ref: ${{ github.ref }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
architecture: x64 | |
- name: Download JAR Artifact | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: jar-artifact | |
path: ./build/libs/ | |
# Download the previous ratings into root directory | |
- name: Download Codeforces Ratings | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: codeforces_ratings | |
path: ./ | |
- name: Download GFG Ratings | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: gfg_ratings | |
path: ./ | |
- name: Download GFG Practice Ratings | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: gfg_practice_ratings | |
path: ./ | |
- name: Download LeetCode Ratings | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: leetcode_ratings | |
path: ./ | |
- name: Download CodeChef Ratings | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: codechef_ratings | |
path: ./ | |
- name: Download HackerRank Ratings | |
uses: actions/download-artifact@v4.0.0 | |
with: | |
name: hackerrank_ratings | |
path: ./ | |
- name: Run JAR Artifact | |
run: java -jar ./build/libs/CMRIT2026Leaderboard-1.0-SNAPSHOT.jar build_leaderboard | |
- name: Get the current date | |
id: date | |
run: echo "NOW=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV | |
# Push the updated Leaderboard to the repository | |
- name: Push Leaderboard | |
if: github.event_name != 'pull_request' # Skip this job if triggered by pull request event | |
run: | | |
git config --global user.email "actions@github.com" | |
git config --global user.name "GitHub Actions" | |
git add ./Leaderboards/CurrentCMRITLeaderboard2026.xlsx | |
git commit -m "Add generated leaderboard data - $NOW" | |
git push --force |