From 9794b55fea80318bfb729c094534e77f3fa93e90 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tim.dijen@minbzk.nl>
Date: Thu, 17 Dec 2020 19:48:47 +0100
Subject: [PATCH] Migrate from Travis to Actions (#1416)

---
 .appveyor.yml             |  26 -----
 .github/workflows/php.yml | 205 ++++++++++++++++++++++++++++++++++++++
 .travis.yml               | 137 -------------------------
 3 files changed, 205 insertions(+), 163 deletions(-)
 delete mode 100644 .appveyor.yml
 create mode 100644 .github/workflows/php.yml
 delete mode 100644 .travis.yml

diff --git a/.appveyor.yml b/.appveyor.yml
deleted file mode 100644
index a284967bc..000000000
--- a/.appveyor.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-build: false
-shallow_clone: false
-version: '2.0.0.{build}'
-platform: 'x64'
-clone_folder: C:\projects\simplesamlphp
-
-environment:
-  matrix:
-    - PHP_VERSION: "7.4"
-
-install:
-  - ps: Invoke-WebRequest "https://raw.githubusercontent.com/ChadSikorra/ps-install-php/master/Install-PHP.ps1" -OutFile "Install-PHP.ps1"
-  - ps: .\Install-PHP.ps1 -Version $Env:PHP_VERSION -Highest -Arch x64 -Extensions mbstring,intl,openssl,curl,pdo_mysql,pdo_sqlite
-  - refreshenv
-  - cd C:\projects\simplesamlphp
-  - php -r "readfile('https://getcomposer.org/installer');" | php
-
-before_test:
-  - cd C:\projects\simplesamlphp
-  # For 2.0 (or once the externalized modules are no longer included), remove the --ignore-platform-reqs
-  - php composer.phar install --no-interaction --no-progress --optimize-autoloader --prefer-source --no-ansi --ignore-platform-reqs
-
-test_script:
-  - cd C:\projects\simplesamlphp
-  - vendor\bin\phpunit.bat
-  
diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
new file mode 100644
index 000000000..99140f69a
--- /dev/null
+++ b/.github/workflows/php.yml
@@ -0,0 +1,205 @@
+name: CI
+
+on:
+  push:
+    branches: [ '**' ]
+  pull_request:
+    branches: [ master, release-* ]
+
+jobs:
+  basic-tests:
+    name: Syntax and unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}
+    runs-on: ${{ matrix.operating-system }}
+    strategy:
+      fail-fast: false
+      matrix:
+        operating-system: [ubuntu-latest, windows-latest]
+        php-versions: ['7.4']
+
+    steps:
+      - name: Setup PHP, with composer and extensions
+        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
+        with:
+          php-version: ${{ matrix.php-versions }}
+          extensions: mbstring, mysql, pdo, pdo_sqlite, xml
+          coverage: pcov
+
+      - name: Setup problem matchers for PHP
+        run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+
+      - name: Setup problem matchers for PHPUnit
+        run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
+
+      - name: Set git to use LF
+        run: |
+          git config --global core.autocrlf false
+          git config --global core.eol lf
+
+      - uses: actions/checkout@v2
+
+      - name: Get composer cache directory
+        id: composer-cache
+        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+      - name: Cache composer dependencies
+        uses: actions/cache@v1
+        with:
+          path: ${{ steps.composer-cache.outputs.dir }}
+          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+          restore-keys: ${{ runner.os }}-composer-
+
+      - name: Validate composer.json and composer.lock
+        run: composer validate
+
+      - name: Install Composer dependencies
+        run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
+
+      - name: Syntax check PHP
+        run: bash vendor/bin/check-syntax-php.sh
+
+      - name: Decide whether to run code coverage or not
+        if: ${{ matrix.php-versions != '7.4' || matrix.operating-system != 'ubuntu-latest' }}
+        run: |
+          echo "NO_COVERAGE=--no-coverage" >> $GITHUB_ENV
+
+      - name: Run unit tests
+        run: |
+          echo $NO_COVERAGE
+          ./vendor/bin/phpunit $NO_COVERAGE
+
+      - name: Save coverage data
+        if: ${{ matrix.php-versions == '7.4' && matrix.operating-system == 'ubuntu-latest' }}
+        uses: actions/upload-artifact@v1
+        with:
+            name: build-data
+            path: ${{ github.workspace }}/build
+
+  security:
+    name: Security checks
+    runs-on: [ubuntu-latest]
+    steps:
+      - name: Setup PHP, with composer and extensions
+        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
+        with:
+            php-version: '7.4'
+            extensions: mbstring, xml
+            coverage: none
+
+      - name: Setup problem matchers for PHP
+        run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+
+      - uses: actions/checkout@v2
+
+      - name: Get composer cache directory
+        id: composer-cache
+        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+      - name: Cache composer dependencies
+        uses: actions/cache@v1
+        with:
+            path: ${{ steps.composer-cache.outputs.dir }}
+            key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+            restore-keys: ${{ runner.os }}-composer-
+
+      - name: Install Composer dependencies
+        run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
+
+      - name: Security check for locked dependencies
+        run: ./vendor/bin/security-checker security:check
+
+      - name: Update Composer dependencies
+        run: composer update --no-progress --no-suggest --prefer-dist --optimize-autoloader
+
+      - name: Security check for updated dependencies
+        run: ./vendor/bin/security-checker security:check
+
+  sanity-check:
+    name: Sanity checks
+    runs-on: [ubuntu-latest]
+
+    steps:
+      - name: Setup PHP, with composer and extensions
+        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
+        with:
+          php-version: '7.4'
+          extensions: mbstring, xml
+          coverage: none
+
+      - name: Setup problem matchers for PHP
+        run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+
+      - uses: actions/checkout@v2
+
+      - name: Get composer cache directory
+        id: composer-cache
+        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+      - name: Cache composer dependencies
+        uses: actions/cache@v1
+        with:
+            path: ${{ steps.composer-cache.outputs.dir }}
+            key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+            restore-keys: ${{ runner.os }}-composer-
+
+      - name: Install Composer dependencies
+        run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
+
+      - name: Install test framework
+        run: composer require simplesamlphp/simplesamlphp-test-framework --dev
+
+      - name: Syntax check YAML / XML / JSON
+        run: |
+          bash vendor/bin/check-syntax-yaml.sh
+          bash vendor/bin/check-syntax-xml.sh
+          bash vendor/bin/check-syntax-json.sh
+
+  quality:
+    name: Quality control
+    runs-on: [ubuntu-latest]
+    needs: [basic-tests]
+
+    steps:
+      - name: Setup PHP, with composer and extensions
+        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
+        with:
+          php-version: '7.4'
+          extensions: mbstring, xml
+
+      - name: Setup problem matchers for PHP
+        run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+
+      - uses: actions/checkout@v2
+
+      - name: Get composer cache directory
+        id: composer-cache
+        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
+
+      - name: Cache composer dependencies
+        uses: actions/cache@v1
+        with:
+            path: ${{ steps.composer-cache.outputs.dir }}
+            key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+            restore-keys: ${{ runner.os }}-composer-
+
+      - name: Install Composer dependencies
+        run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
+
+      - uses: actions/download-artifact@v1
+        with:
+          name: build-data
+          path: ${{ github.workspace }}/build
+
+      - name: Codecov
+        uses: codecov/codecov-action@v1
+
+      - name: PHP Code Sniffer
+        continue-on-error: true
+        run: php vendor/bin/phpcs src/
+
+      - name: Psalm
+        continue-on-error: true
+        uses: docker://vimeo/psalm-github-actions
+
+      - name: Psalter
+        continue-on-error: true
+        run: php vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index b6ecc5f21..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,137 +0,0 @@
-sudo: required
-
-language: php
-
-# Stage order
-stages:
-  - pre-conditions
-  - test
-  - quality
-  - build
-
-
-################
-#  Test stage  #
-################
-
-php:
-  - 7.4
-#  - nightly
-
-env:
-  - COMMAND="composer install"
-  - COMMAND="composer update"
-
-before_script:
-  - ${COMMAND}
-
-script:
-  - php vendor/bin/phpunit --no-coverage
-
-jobs:
-  fast_finish: true
-  allow_failures:
-    - php: 7.4
-      env: Psalm
-    - php: 7.4
-      env: Security check (composer install)
-    - php: 7.4
-      env: Security check (composer update)
-    - php: 7.4
-      env: PHP Codesniffer
-
-  include:
-
-    ##########################
-    #  Pre-conditions stage  #
-    ##########################
-
-    - stage: pre-conditions
-      php: 7.4
-      env: Syntax check PHP
-      before_script:
-        - composer install
-      script:
-        - vendor/bin/check-syntax-php.sh
-
-#    - stage: pre-conditions
-#      php: nightly
-#      env: Syntax check PHP
-#      before_script:
-#        - composer install
-#      script:
-#        - vendor/bin/check-syntax-php.sh
-
-    - stage: pre-conditions
-      env: Syntax check YAML / XML / JSON
-      before_script:
-        - composer update
-      script:
-        - vendor/bin/check-syntax-yaml.sh
-        - vendor/bin/check-syntax-xml.sh
-        - vendor/bin/check-syntax-json.sh
-
-
-    ###################
-    #  Quality stage  #
-    ###################
-
-    - stage: quality
-      php: 7.4
-      env: Security check (composer install)
-      before_script:
-        - composer install
-      script:
-        - vendor/bin/security-checker security:check
-
-    - stage: quality
-      php: 7.4
-      env: Security check (composer update)
-      before_script:
-        - composer update
-      script:
-        - vendor/bin/security-checker security:check
-
-    - stage: quality
-      php: 7.4
-      env: Codecov
-      before_script:
-        - composer update
-        - XDEBUG_MODE=coverage php vendor/bin/phpunit
-      script:
-        - bash <(curl -s https://codecov.io/bash)
-
-    - stage: quality
-      php: 7.4
-      env: Psalm
-      before_script:
-        - composer update
-      script:
-        - vendor/bin/psalm
-        - vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run
-
-    - stage: quality
-      php: 7.4
-      env: PHP Codesniffer
-      before_script:
-        - composer update
-      script:
-        - vendor/bin/phpcs
-
-    ###################
-    #  Build stage    #
-    ###################
-
-    - stage: build
-      env: NPM build
-      language: node_js
-      node_js: 10
-      before_script:
-        - npm install
-        - npm audit fix
-      script:
-        - npm run build
-
-notifications:
-  slack:
-    secure: jgkeIXi7Hzkc907ZKGpuJZ9va+KjHNV0LZoWc22skkDqNIu2wshvqx4wOMFK8CXtRcRgCambtXxyTio17Q4B4mFu1uf7qVN6x18QyLNhfypB/d808kLoJCzlmGB7477jrw5xvgSVOMxWmic8QTjkcMOWSiG4fJE86zIthZP0OOY=
-- 
GitLab