Skip to content

Commit

Permalink
ci: Reactivate and improve the Test workflow
Browse files Browse the repository at this point in the history
* Now both tests (Maven and Make) will runs on 3 platforms, they are
  Ubuntu, Windows, and MacOS.
* Refactored and improved jobs setup
* Updated several dependencies to the latest major version
* Several changes and improvements
  • Loading branch information
mitsuki31 committed Jan 11, 2024
1 parent 813fafb commit 6145636
Showing 1 changed file with 113 additions and 103 deletions.
216 changes: 113 additions & 103 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Project Tester
name: Test

on:
# Run on push, pull request, and manual trigger
push:
# Only run when the specific files are changed
paths:
- 'src/**/*.java' # Java files
- 'src/**/*.py' # Python files
- '**/*.java' # Java files
- '**/*.py' # Python files

# Unlike push, the workflow always runs on pull requests
pull_request:
Expand All @@ -20,139 +20,149 @@ on:
required: false
type: boolean

# Environment variables definitions
env:
## For Java installation
java-dist: temurin

## For Python installation
arch: x64

## Other environments
debug: ${{ inputs.debug }}
deps: requirements.txt

jobs:
# ::---:: Maven Test ::---:: #
maven-test:
name: Maven Test / ${{ matrix.os }}
name: Maven Test / ${{ matrix.os }} / ${{ matrix.java-ver }}
runs-on: ${{ matrix.os }}-latest

env:
java-ver: 11
java-dist: temurin
DEBUG: ${{ inputs.debug }}
# Maven's debug flag (`-X`)
mvnDebugFlag: ${{ env.debug == true && '-X' || '' }}

strategy:
# Set to maximum number of processes to speed up jobs run
max-parallel: 6
matrix:
os: [Ubuntu, Windows]
os: [Ubuntu, Windows, macOS]
java-ver: [11, latest] # JDK 11 & latest

steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Caching Maven deps
- name: Cache Maven dependencies
id: cache-maven
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
${{ runner.os }}-maven-
${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-${{ hashFiles('**/pom.xml') }}
${{ runner.os }}-jdk-${{ matrix.java-ver }}-${{ env.java-dist }}-maven-
# Setup Java
- name: Setup Java / ${{ matrix.os }}
uses: actions/setup-java@v3
- name: Setup Java / ${{ matrix.os }} / ${{ matrix.java-ver }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.java-ver }}
java-version: ${{ matrix.java-ver }}
distribution: ${{ env.java-dist }}

# Install deps
- name: Install dependencies
if: ${{ steps.cache-maven.outputs.cache-hit != true && env.DEBUG != true }}
run: mvn clean install -DskipTests

- name: Install dependencies (Debug)
if: ${{ steps.cache-maven.outputs.cache-hit != true && env.DEBUG == true }}
run: mvn clean install -DskipTests -X
if: ${{ steps.cache-maven.outputs.cache-hit != true }}
run: mvn clean install -DskipTests ${{ env.mvnDebugFlag }}
shell: bash

# Packaging and testing
- name: Packaging and testing
if: ${{ env.DEBUG != true }}
run: mvn test package -P include-src
- name: Packaging the project
run: mvn package -P include-src ${{ env.mvnDebugFlag }}
shell: bash

- name: Package source (Debug)
if: ${{ env.DEBUG == true }}
run: mvn test package -P include-src -X
# Build the docs
- name: Build the HTML docs
run: mvn site -P lint ${{ env.mvnDebugFlag }}
shell: bash

# Clean up
- name: Clean up the project
run: mvn clean
run: |
mvn clean ${{ env.mvnDebugFlag }}
[ -d docs/jmatrix-* ] && rm --recursive --force docs/jmatrix-*
shell: bash


# ::---:: Make Test ::---:: #
# make-test:
# name: Make Test
# runs-on: ubuntu-latest
# continue-on-error: true
#
# strategy:
# matrix:
# py-ver: ['3.7', '3.x']
#
# env:
# arch: x64
# DEPS_FILE: 'requirements.txt'
# DEBUG: ${{ inputs.debug }}
#
# steps:
# # Checkout
# - name: Checkout repository
# uses: actions/checkout@v3
#
# # Setup Python
# - name: Setup Python ${{ matrix.py-ver }}
# id: setup-py
# uses: actions/setup-python@v3
# with:
# python-version: ${{ matrix.py-ver }}
# architecture: ${{ env.arch }}
# cache: 'pip'
# cache-dependency-path: '**/${{ env.DEPS_FILE }}'
#
# # Install deps
# - name: Install dependencies
# if: ${{ steps.setup-py.outputs.cache-hit != true }}
# run: |
# if [ $DEBUG = 'true' ]; then
# python -m pip install -r $DEPS_FILE --debug
# else
# python -m pip install -r $DEPS_FILE
# fi
#
# # Sadly, Make cannot tests the project thoroughly due to unavailability
# # of necessary packages (e.g "org.junit"), so here it just tests
# # the project on compiling, packaging, and generating docs.
#
# # Compile
# - name: Compile the project
# run: |
# [ -d target/classes ] && make clean
# make compile VERBOSE=$DEBUG LINT=true
#
# # Package
# - name: Packaging the project
# run: |
# make package VERBOSE=$DEBUG
#
# - name: Packaging the project (with source)
# run: |
# make package INCLUDE-SRC=true VERBOSE=$DEBUG
#
# # Build docs
# - name: Build the docs
# run: |
# # Build docs
# # For more information on debugging, we prefer to change it
# # to "all" mode.
# if [ $DEBUG = 'true' ]; then
# make build-docs VERBOSE=all
# else
# make build-docs
# fi
#
# # Clean up
# - name: Clean up the project
# run: |
# [ -d target ] && echo "Clean the project" && make clean
make-test:
name: Make Test / ${{ matrix.os }} / ${{ matrix.py-ver }}
runs-on: ${{ matrix.os }}-latest

env:
MAKE: ${{ env.debug == true && 'make -d' || 'make' }}

strategy:
# Set to maximum number of processes to speed up jobs run
max-parallel: 6
matrix:
os: [Ubuntu, Windows, macOS]
py-ver: [3.7, 3.x] # Python 3.7 & latest

steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v4

# Setup Python
- name: Setup Python / ${{ matrix.os }} / ${{ matrix.py-ver }}
id: setup-py
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.py-ver }}
architecture: ${{ env.arch }}
cache: pip
cache-dependency-path: '**/${{ env.deps }}'

# Install deps
- name: Install dependencies
id: init
if: ${{ steps.setup-py.outputs.cache-hit != true }}
run: |
if [ $debug = 'true' ]; then
python -m pip install -r $(git ls-files **/$deps) --debug
else
python -m pip install -r $(git ls-files **/$deps)
fi
shell: bash

# Sadly, Make cannot tests the project thoroughly due to unavailability
# of necessary packages (e.g "org.junit"), so here it just tests
# the project on compiling, packaging, and generating docs.

# Compile
- name: Compile the project
needs: init
run: |
[ -d target ] && make clean > /dev/null
$MAKE compile LINT=true VERBOSE=$debug
shell: bash

# Package
- name: Packaging the project
run: $MAKE package INCLUDE_SRC=true VERBOSE=$debug
shell: bash

# Build docs
- name: Build the HTML docs
# For more information on debugging, it will implictly set the
# verbose mode to 'all' when the VERBOSE is true.
run: $MAKE build-docs LINT=true VERBOSE=$debug
shell: bash

# Clean up
- name: Clean up the project
run: $MAKE clean VERBOSE=$debug
shell: bash

0 comments on commit 6145636

Please sign in to comment.