Merge branch 'move-class-CurrentTimeUTC' into master #6
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 is the main workflow, it runs the unit tests with various operating systems and Java | |
# versions. | |
# Beyond being run on commits & PRs it's also run under certain conditions by cron-*.yml | |
name: CI | |
on: [push, pull_request, workflow_call] # workflow_call is for the workflow files cron-*.yml | |
env: | |
# Also adapt the "matrix" section below when changing this. | |
FREENET_MINIMUM_JAVA_VERSION: 8 | |
jobs: | |
build: | |
strategy: | |
fail-fast: false # Don't cancel execution for all Java versions if one fails. | |
matrix: | |
# TODO: Also test on Debian stable as that's what fred targets. | |
# Unfortunately as of 2021-08-05 Debian is not available on GitHub Actions (yet?). | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
# 8 is $FREENET_MINIMUM_JAVA_VERSION currently. | |
# 9, 10 excluded because: Building fred fails there, probably because they're EOL. | |
# TODO: Trim the set of Java versions to respect GitHub's free service. | |
java-version: [8, 11, 12, 13, 14, 15, 16, 17, 18-ea] | |
# TODO: Bug: As of 2021-09-11 fred doesn't compile with Java > 15 on Windows due to its | |
# Gradle version 4.10.3 not working there. Try again once fred uses a more recent one. | |
# TODO: Code quality: GHA currently wrongly parses arrays such as "java-version: [16, 17]" | |
# into their literal string value instead of expanding them. They'll likely add a different | |
# syntax for arrays here, use it then, see | |
# https://github.com/github/feedback/discussions/7835 | |
exclude: | |
- os: windows-latest | |
java-version: 16 | |
- os: windows-latest | |
java-version: 17 | |
- os: windows-latest | |
java-version: 18-ea | |
runs-on: ${{ matrix.os }} | |
name: ${{ matrix.os }}, Java ${{ matrix.java-version }} | |
steps: | |
- name: Install dependencies | |
shell: bash | |
run: | | |
if [ '${{runner.os}}' = 'macOS' ] ; then | |
brew install coreutils # For step "Compile and test Freetalk" | |
# The remaining dependencies will be downloaded using Gradle. | |
elif [ '${{runner.os}}' = 'Linux' ] ; then | |
# TODO: Performance: Check if this is still needed or if they're installed by default | |
# on GHA. Also check if we can cache these. | |
sudo apt-get --assume-yes install ant ant-optional junit4 libhamcrest-java | |
fi | |
# On Windows the dependencies will be downloaded using Gradle. | |
- name: Install Java | |
uses: actions/setup-java@v2 | |
with: | |
# Using 'zulu' distribution because as of 2022-03-07 the other distributions either don't | |
# provide many old Java versions or lack an early access build of the upcoming version. | |
# For some overview of distributions see https://news.ycombinator.com/item?id=28820601 | |
# TODO: Code quality: Also (or only?) test against Oracle's JDK once it is available on GHA, | |
# upstream bugtracker issue: https://github.com/actions/setup-java/issues/69 | |
distribution: 'zulu' | |
java-version: ${{ matrix.java-version }} | |
- name: Load and print current fred branch next HEAD commit | |
shell: bash | |
run: | | |
set -o errexit | |
set -o pipefail | |
echo 'Current HEAD commit of fred branch next:' | |
git ls-remote 'https://github.com/freenet/fred.git' 'refs/heads/next' | cut -f 1 \ | |
| tee current_fred_commit | |
- name: Use/populate cache of fred JARs | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: fred/build/output/ | |
# The key must include the hash of the file to ensure the cache is invalidated whenever the | |
# file contents change. | |
# | |
# We use ${{runner.os}} instead of ${{matrix.os}} to ensure the "latest" part in e.g. | |
# the OS value "ubuntu-latest" is replaced with the actual OS version, which guarantees that | |
# the cache is invalidated if the OS version changes. | |
# TODO: Code quality: GHA does not actually implement this, ${{runner.os}} also holds a | |
# generic value. As of 2022-11-18 there is no other variable in the runner context which | |
# would hold a specific one. File a bug. | |
# fred JARs which were built on an old version should work though, so let's keep this as-is | |
# for now. | |
key: fred-jars_branch-next_${{runner.os}}_java${{matrix.java-version}}_${{hashFiles('current_fred_commit')}} | |
- name: Checkout fred git repository if no cache hit | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: actions/checkout@v2 | |
with: | |
repository: freenet/fred | |
ref: next | |
path: fred # Available via: "$GITHUB_WORKSPACE/fred" | |
- name: Checkout Freetalk git repository | |
uses: actions/checkout@v2 | |
with: | |
path: plugin-Freetalk # Available via: "$GITHUB_WORKSPACE/plugin-Freetalk" | |
# FIXME: The Gradle script should init submodules automatically like the Ant one did. | |
# Remove the command for that from the README.md once you implement it. | |
submodules: true | |
- name: Compile Freenet Git repository if no cache hit | |
if: steps.cache.outputs.cache-hit != 'true' | |
shell: bash | |
run: | | |
pushd "$GITHUB_WORKSPACE"/fred && | |
# TODO: freenet.jar won't contain class Version if we don't run the | |
# clean task in a separate execution of Gradle. I.e. this wouldn't work: | |
# $ gradle clean jar | |
# This is due to a bug in fred's Gradle script which could be fixed | |
# like this WoT commit did: 06c007204f40c712a398f0b58671f77fd9aeffd1 | |
# EDIT: A better long-term fix for such issues would be to use a file "Version.properties" | |
# instead of patching the "Version.java" source code, like Freetalk now does. | |
# See Freetalk commits 195cfd70aad92c592e0a591d9804712b1cb43a1e and | |
# 0d956c4bf0afbca7a8cb9ef855d0ea415f09bb9a | |
./gradlew clean && | |
# "copyRuntimeLibs" copies the JAR *and* dependencies - which Freetalk also | |
# needs - to build/output/ | |
./gradlew jar copyRuntimeLibs -x test && | |
popd | |
# TODO: Performance: To speed up the build we could use the Gradle organization's GitHub action | |
# which caches part of the build (albeit as of 2022-11-22 the following link sounds like the | |
# cache isn't actually used?): | |
# https://docs.github.com/en/actions/guides/building-and-testing-java-with-gradle#caching-dependencies | |
# However this has the security implication of running a non-official GitHub action and thus | |
# increasing the attack surface. Further, it might cache part of the compiled code and thus | |
# could cause incorrect Gradle state (due to bugs at their side) to persist. | |
# EDIT: There's an alternative solution: | |
# https://github.com/actions/cache/blob/6babf202a422aac73d74f0f40020ca0673b0a4ba/examples.md#java---gradle | |
- name: Compile and test Freetalk | |
shell: bash | |
run: | | |
set -o errexit | |
cd "$GITHUB_WORKSPACE/plugin-Freetalk" | |
# TODO: Put fred checksums and fred version info into separate "- name" steps so they | |
# can be viewed more easily on the web interface. | |
# TODO: Also print the checksums of other dependency JARs which Gradle has obtained from the | |
# Internet or the local system. | |
echo 'Checksums of fred JARs:' ; sha256sum ../fred/build/output/* | |
echo 'fred version:' | |
java -classpath '../fred/build/output/freenet.jar' 'freenet.node.Version' | |
echo 'gradle version:' | |
gradle --version | |
if [ "${{runner.os}}" != 'Linux' ] ; then | |
# We can't obtain the dependencies from /usr/share so download them instead. | |
export FREETALK__DOWNLOAD_DEPENDENCIES=1 | |
fi | |
# To test the Ant and Gradle builders against each other uncomment the following. | |
# (The scripts will use ./gradlew if there is one so we can ensure a specific Gradle version | |
# works if that becomes necessary someday.) | |
## tools/compare-gradle-jars-with-ant-jars | |
## tools/compare-gradle-tests-with-ant-tests | |
# Show stdout/stderr so random seeds of failed tests can be obtained by developers to | |
# reproduce failed test runs. Also prevents the 10 minute build timeout. | |
FREETALK__SHOW_GRADLE_TEST_OUTPUT=1 gradle clean test jar | |
# FIXME: Adapt to Freetalk and GitHub Actions (is Travis CI code currently) and enable. | |
# Will require adding "python3-pip" to the list of apt packages to install, see above at | |
# "name: Install apt packages". | |
# | |
# deploy: | |
# provider: script | |
# # Prevent Travis from deleting the JAR before we can deploy it (wtf?) | |
# skip_cleanup: true | |
# script: ./.travis.upload-jar-to-freenet.sh | |
# on: | |
# all_branches: true | |
# condition: $TRAVIS_JDK_VERSION = "openjdk$FREENET_MINIMUM_JAVA_VERSION" |