SquirrelJME/SquirrelJME

View on GitHub
.circleci/config.yml

Summary

Maintainability
Test Coverage
# ---------------------------------------------------------------------------
# Multi-Phasic Applications: SquirrelJME
#     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
#     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
# ---------------------------------------------------------------------------
# SquirrelJME is under the GNU General Public License v3, or later.
# See license.mkd for licensing and copyright information.
# ---------------------------------------------------------------------------
# DESCRIPTION: CircleCI Build Configuration
# SourceForge: squirreljme@frs.sourceforge.net
# SourceForge Root: /home/frs/project/squirreljme/AutoBuild/
# CircleCI Reference: https://circleci.com/docs/2.0/env-vars/

version: 2.1

executors:
  build-on-linux-amd64:
    docker:
      - image: cimg/openjdk:11.0
    resource_class: medium
    environment:
      # Allow Gradle to be fully cached
      GRADLE_USER_HOME: ${CIRCLE_WORKING_DIRECTORY}/.gradle/home
  build-on-linux-arm64:
    docker:
      - image: cimg/ubuntu-2004:current
    resource_class: arm.medium
    environment:
      # Allow Gradle to be fully cached
      GRADLE_USER_HOME: ${CIRCLE_WORKING_DIRECTORY}/.gradle/home

# This is in the documentation but does not actually work, new feature?
#  build-on-windows:
#    windows:
#      name: win/default
#      shell: cmd.exe
#    resource_class: medium
#    environment:
#      # Use a reduced amount of memory to all the VMs so that it does not
#      # try grabbing all the memory that is available to the system.
#      JAVA_OPTS: -Xmx3g

  build-on-macos:
    macos:
      xcode: 13.2.1
    resource_class: macos.x86.medium.gen2
    environment:
      # Do not auto-update brew as this takes forever, and we really just want
      # a single package
      HOMEBREW_NO_AUTO_UPDATE: 1

      # Do not auto-clean brew, this wastes time and everything will be thrown
      # out when the container finishes anyway
      HOMEBREW_CLEANUP_MAX_AGE_DAYS: 730

      # Do not send analytics
      HOMEBREW_NO_ANALYTICS: 1

      # Do not clean up after installation
      HOMEBREW_NO_INSTALL_CLEANUP: 1

  build-on-macos-m1:
    machine: true
    resource_class: squirreljme/squirreljme-macos-m1

orbs:
  win: circleci/windows@2.4.0

# Parameters to simplify commands
parameters:
  # Options to be used for any Gradle command, is faster this way
  standard-gradle-options:
    type: string
    default: --console plain --continue --parallel --no-daemon --stacktrace

  # Standard build for systems
  standard-build-options:
    type: string
    default: build testHosted -x testSpringCoat -x javadoc -x javadocJar -x sourcesJar -x markdownJavaDoc

# Commands that are used by almost everything
commands:
  # Save Gradle cache and such so subsequent builds are faster
  persist-gradle:
    steps:
      - persist_to_workspace:
          root: .
          paths:
            - '.gradle/*'
            - 'build/*'
            - '*/.gradle/*'
            - '*/build/*'
            - '*/*/build/*'

  # Saving of test results, since this is duplicated for many OSes
  save-test-results:
    parameters:
      where:
        type: string
      os:
        type: string
      vm:
        type: string
      shell:
        type: string
        default: "/bin/bash"
      home:
        type: string
        default: ./.no-persist/
      find:
        type: string
        default: find
      store-home:
        type: string
        default: ./.no-persist/
    steps:
      - run:
          shell: <<parameters.shell>>
          name: Save test results
          command: |
            mkdir -p "<<parameters.home>>/test-results/junit-<<parameters.os>>/"
            <<parameters.find>> . -type f -regex '.*/'"<<parameters.where>>"'/junit/.*\.xml' -exec cp {} "<<parameters.home>>/test-results/junit-<<parameters.os>>/" \;
          when: always
      - run:
          shell: <<parameters.shell>>
          name: Save test results
          command: |
            mkdir -p "<<parameters.home>>/test-results/csv-<<parameters.os>>/"
            <<parameters.find>> . -type f -regex '.*/'"<<parameters.where>>"'/csv/.*\.csv' -exec cp {} "<<parameters.home>>/test-results/csv-<<parameters.os>>/" \;
          when: always
      - run:
          shell: <<parameters.shell>>
          name: Save snapshots
          command: |
            mkdir -p "<<parameters.home>>/test-results/nps-<<parameters.vm>>-<<parameters.os>>/"
            <<parameters.find>> . -type f -regex '.*/'"<<parameters.where>>"'/nps/.*\.nps' -exec cp {} "<<parameters.home>>/test-results/nps-<<parameters.vm>>-<<parameters.os>>/" \;
          when: always
      - store_test_results:
          path: <<parameters.store-home>>/test-results
      - store_artifacts:
          path: <<parameters.store-home>>/test-results

  # Install standard packages in Debian/Ubuntu
  linux-install-required:
    steps:
      - run:
          name: Update package lists
          command: sudo apt-get update -y
      - run:
          name: Install required dependencies
          command: sudo apt-get install -y --no-install-recommends cmake build-essential curl wget openjdk-11-jdk gcc g++ make

jobs:
  ################################## WINDOWS #################################
  build_windows:
    executor:
      name: win/default
      shell: cmd.exe
      size: medium
    environment:
      # Use a reduced amount of memory to all the VMs so that it does not
      # try grabbing all the memory that is available to the system.
      JAVA_OPTS: -Xmx3g
    steps:
      - checkout
      - run:
          shell: cmd.exe
          name: Gradle Build and Test
          # According to documentation, Gradle on Windows has trouble and tries
          # to make way too many workers which causes extreme resource.
          # contention --max-workers=2
          command: gradlew <<pipeline.parameters.standard-build-options>> <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 7m
      - persist-gradle
      - save-test-results:
          where: "vm-test-hosted"
          os: "windows"
          vm: "hosted"
          shell: bash.exe
          find: /usr/bin/find
          home: "/c/users/circleci/"
          store-home: "c:/users/circleci/"

  build_windows_standalone:
    executor:
      name: win/default
      shell: cmd.exe
      size: medium
    environment:
      # Use a reduced amount of memory to all the VMs so that it does not
      # try grabbing all the memory that is available to the system.
      JAVA_OPTS: -Xmx3g
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          shell: bash.exe
          name: Construct Standalone
          command: ./gradlew :emulators:standalone:shadowJar <<pipeline.parameters.standard-gradle-options >>
      - run:
          shell: bash.exe
          name: Remove distracting JAR, if any
          command: rm emulators/standalone/build/libs/standalone-*.jar
      - store_artifacts:
          path: emulators/standalone/build/libs/
          destination: .

  ratufacoat_build_windows:
    executor:
      name: win/default
      shell: cmd.exe
      size: medium
    environment:
      # Use a reduced amount of memory to all the VMs so that it does not
      # try grabbing all the memory that is available to the system.
      JAVA_OPTS: -Xmx3g
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Install required dependencies
          working_directory: ratufacoat
          shell: cmd.exe
          command: choco install cmake.install
      - run:
          name: Setup CMake build
          working_directory: ratufacoat
          shell: bash.exe
          command: |
            "$PROGRAMFILES/CMake/bin/cmake.exe" .
      - run:
          name: Compile CMake build
          working_directory: ratufacoat
          shell: bash.exe
          command: |
            "$PROGRAMFILES/CMake/bin/cmake.exe" --build .
      - store_artifacts:
          path: ratufacoat\src\Debug\SquirrelJME.exe
          destination: SquirrelJME.exe

  ################################# MAC OS X #################################
  build_macosx:
    executor: build-on-macos
    steps:
      - checkout
      - run:
          # Only OpenJDK is required, Gradle always uses Gradle wrapper so
          # we do not need that
          name: Install OpenJDK 11
          command: brew install openjdk@11 coreutils
      - run:
          name: Gradle Build and Test
          command: timeout --foreground 7m ./gradlew <<pipeline.parameters.standard-build-options>> <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 7m
      - persist-gradle
      - save-test-results:
          where: "vm-test-hosted"
          os: "macosx"
          vm: "hosted"
  build_macosx_m1:
    executor: build-on-macos-m1
    steps:
      - checkout
      - run:
          name: Gradle Build and Test
          command: timeout --foreground 7m ./gradlew <<pipeline.parameters.standard-build-options>> <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 7m
      - persist-gradle
      - save-test-results:
          where: "vm-test-hosted"
          os: "macosx-m1"
          vm: "hosted"

  build_macosx_standalone:
    executor: build-on-macos
    steps:
      - checkout
      - run:
          # Only OpenJDK is required, Gradle always uses Gradle wrapper so
          # we do not need that
          name: Install OpenJDK 11
          command: brew install openjdk@11 coreutils
      - attach_workspace:
          at: .
      - run:
          name: Construct Standalone
          command: ./gradlew :emulators:standalone:shadowJar <<pipeline.parameters.standard-gradle-options>>
      - run:
          name: Remove distracting JAR, if any
          command: rm emulators/standalone/build/libs/standalone-*.jar
      - store_artifacts:
          path: emulators/standalone/build/libs/
          destination: .
  build_macosx_m1_standalone:
    executor: build-on-macos-m1
    steps:
      - checkout
      - attach_workspace:
          at: .
      - run:
          name: Construct Standalone
          command: ./gradlew :emulators:standalone:shadowJar <<pipeline.parameters.standard-gradle-options>>
      - run:
          name: Remove distracting JAR, if any
          command: rm emulators/standalone/build/libs/standalone-*.jar
      - store_artifacts:
          path: emulators/standalone/build/libs/
          destination: .

  ratufacoat_build_macosx:
    executor: build-on-macos
    steps:
      - checkout
      - run:
          name: Install CMake
          command: brew install cmake coreutils
      - attach_workspace:
          at: .
      - run:
          name: Setup CMake build
          working_directory: ratufacoat
          command: cmake .
      - run:
          name: Compile CMake build
          working_directory: ratufacoat
          command: cmake --build .
      - store_artifacts:
          path: ratufacoat/src/SquirrelJME
          destination: SquirrelJME

  ################################### LINUX ##################################
  build_linux_amd64:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - run:
          name: Gradle Build and Test
          command: timeout --foreground 7m ./gradlew <<pipeline.parameters.standard-build-options>> <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 7m
      - save-test-results:
          where: "vm-test-hosted"
          os: "linux-amd64"
          vm: "hosted"
      - persist-gradle
  build_linux_amd64_standalone:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct Standalone
          command: ./gradlew :emulators:standalone:shadowJar <<pipeline.parameters.standard-gradle-options>>
      - run:
          name: Remove distracting JAR, if any
          command: rm emulators/standalone/build/libs/standalone-*.jar
      - store_artifacts:
          path: emulators/standalone/build/libs/
          destination: .

  build_linux_arm64:
    executor: build-on-linux-arm64
    steps:
      - checkout
      - linux-install-required
      - run:
          name: Gradle Build and Test
          command: timeout --foreground 7m ./gradlew <<pipeline.parameters.standard-build-options>> <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 7m
      - save-test-results:
          where: "vm-test-hosted"
          os: "linux-arm64"
          vm: "hosted"
      - persist-gradle
  build_linux_arm64_standalone:
    executor: build-on-linux-arm64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct Standalone
          command: ./gradlew :emulators:standalone:shadowJar <<pipeline.parameters.standard-gradle-options>>
      - run:
          name: Remove distracting JAR, if any
          command: rm emulators/standalone/build/libs/standalone-*.jar
      - store_artifacts:
          path: emulators/standalone/build/libs/
          destination: .

  ### OSS SonaType Nexus
  sonatype_publish:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Publish to OSS SonaType
          command: ./gradlew publishMavenPublicationToMavenRepository <<pipeline.parameters.standard-gradle-options>> || circleci-agent step halt

  ### RatufaCoat
  ratufacoat_build_linux:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Setup CMake build
          working_directory: ratufacoat
          command: cmake .
      - run:
          name: Compile CMake build
          working_directory: ratufacoat
          command: cmake --build .
      - store_artifacts:
          path: ratufacoat/src/SquirrelJME
          destination: SquirrelJME

  ### SpringCoat
  test_springcoat:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: SpringCoat Tests
          command: timeout --foreground 17m ./gradlew testSpringCoat <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 17m
      - save-test-results:
          where: "vm-test-springcoat"
          os: "linux"
          vm: "springcoat"
  test_summercoat:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: SummerCoat Tests
          command: timeout --foreground 15m ./gradlew testSummerCoat <<pipeline.parameters.standard-gradle-options>>
          no_output_timeout: 15m
      - save-test-results:
          where: "vm-test-summercoat"
          os: "linux"
          vm: "summercoat"

  ################################### USERS ##################################
  export_user_guide:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - run:
          name: Checkout Wiki
          command: git clone git@github.com:SquirrelJME/SquirrelJME.wiki.git /tmp/wiki
      - run:
          name: Wikify
          command: .circleci/squirreljme-wikify-user-guide.sh "$(pwd)" "/tmp/wiki"
      - run:
          name: Update Git User
          command: |
            cd "/tmp/wiki" && git config user.name "SquirrelJME Automation" && git config user.email "xerthesquirrel+squirreljme@gmail.com"
      - run:
          name: Commit changes
          command: |
            cd "/tmp/wiki" && git commit -m "Synchronize User-Guide" || echo "Ignoring commit."
      - add_ssh_keys:
          fingerprints:
            - "26:b8:ae:4d:53:64:4c:6a:59:3d:a6:60:44:90:9d:6c"
      - run:
          name: Push changes
          command: |
            cd "/tmp/wiki" && git push

  ################################ CONSTRUCTION ###############################
  # Runs the `testJar` task so any operations following this will run faster
  # when they need to use these JARs
  construct_testJars:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct Test JARs
          command: ./gradlew testJar <<pipeline.parameters.standard-gradle-options>>
      - persist-gradle

  # Constructs the ROM fragment libraries for SummerCoat, since they are used
  # for general ROM construction
  construct_libSummerCoat:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct SummerCoat Libraries
          command: ./gradlew libSummerCoat <<pipeline.parameters.standard-gradle-options>>
      - persist-gradle

  # All the tests so that they can run from within SummerCoat
  construct_libTestSummerCoat:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct Test SummerCoat Libraries
          command: ./gradlew libTestSummerCoat <<pipeline.parameters.standard-gradle-options>>
      - persist-gradle

  # Constructs the standard SummerCoat ROM, could be uploaded later
  construct_romSummerCoat:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct SummerCoat ROM
          command: ./gradlew romSummerCoat <<pipeline.parameters.standard-gradle-options>>
      - persist-gradle

  # Constructs the test SummerCoat ROM, could be uploaded later, this is so
  # that any RatufaCoats have an actual ROM that can be tested to ensure that
  # it properly works.
  construct_romTestSummerCoat:
    executor: build-on-linux-amd64
    steps:
      - checkout
      - linux-install-required
      - attach_workspace:
          at: .
      - run:
          name: Construct Test SummerCoat ROM
          command: ./gradlew romTestSummerCoat <<pipeline.parameters.standard-gradle-options>>
      - persist-gradle

workflows:
  version: 2
  tests:
    jobs:
      ############################# STANDARD TESTS ############################
      - build_linux_amd64
#      - build_linux_arm64
      - test_springcoat:
          requires:
            - construct_testJars
#      - test_summercoat:
#          requires:
#            - construct_libTestSummerCoat
      - build_linux_amd64_standalone:
           requires:
             - build_linux_amd64
#      - build_linux_arm64_standalone:
#          requires:
#            - build_linux_arm64

      # Mac OS X runs decently however the jobs for it have a higher cost, so
      # only perform builds and tests for trunk to lower costs.
      # Currently I have an overabundance of credits...
      - build_macosx
#          filters:
#            branches:
#              only:
#                - trunk
      - build_macosx_m1
#          filters:
#            branches:
#              only:
#                - trunk
      - build_macosx_standalone:
           requires:
             - build_macosx
      - build_macosx_m1_standalone:
           requires:
             - build_macosx_m1

      # Building on Windows is currently expensive and takes longer, so only
      # run these builds on trunk to lower costs.
      # Currently have an overabundance of credits...
      - build_windows
#          requires:
#            - build_linux
#          filters:
#            branches:
#              only:
#                - trunk
      - build_windows_standalone:
           requires:
             - build_windows

      # Publishing to OSS Sonatype Nexus (https://oss.sonatype.org)
      - sonatype_publish:
          requires:
            - build_linux_amd64
          filters:
            branches:
              only:
                - trunk
                - wip-centralpublish

      ###################### LIBRARY AND ROM CONSTRUCTION #####################
      - construct_testJars:
          requires:
            - build_linux_amd64
#      - construct_libSummerCoat:
#          requires:
#            - build_linux_amd64
#      - construct_libTestSummerCoat:
#          requires:
#            - construct_testJars
#      - construct_romSummerCoat:
#          requires:
#            - construct_libSummerCoat
#      - construct_romTestSummerCoat:
#          requires:
#            - construct_libTestSummerCoat

      ############################## RATUFACOAT ##############################
#      - ratufacoat_build_windows:
#          requires:
#            - build_windows
#            - construct_romTestSummerCoat
#      - ratufacoat_build_linux:
#          requires:
#            - build_linux_amd64
#            - construct_romTestSummerCoat
#      - ratufacoat_build_macosx:
#          requires:
#            - build_macosx
#            - construct_romTestSummerCoat

  #################### TASKS TO INCREASE USER FRIENDLINESS ####################
  friendliness:
    jobs:
      - export_user_guide:
          filters:
            branches:
              only:
                - trunk
                - wip-userguide