Bläddra i källkod

CI: Move install steps to reusable 'install' action

Daniel Rudolf 3 år sedan
förälder
incheckning
23b00ba1e0
2 ändrade filer med 74 tillägg och 51 borttagningar
  1. 71 0
      .github/actions/install/action.yml
  2. 3 51
      .github/workflows/test.yml

+ 71 - 0
.github/actions/install/action.yml

@@ -0,0 +1,71 @@
+name: Install Pico CMS
+description: Install Pico CMS to the current working directory
+
+inputs:
+    php-version:
+        description: PHP version to setup.
+        required: true
+    php-tools:
+        description: Setup additional PHP tools.
+        required: false
+
+runs:
+    using: "composite"
+    steps:
+        - name: Setup PHP ${{ inputs.php-version }}
+          uses: shivammathur/setup-php@v2
+          with:
+              php-version: ${{ inputs.php-version }}
+              tools: composer, ${{ inputs.php-tools }}
+
+        - name: Read Pico version
+          shell: bash
+          run: |
+              PICO_VERSION="$(php -r 'require("./lib/Pico.php"); echo Pico::VERSION;')"
+              echo "PICO_VERSION=$PICO_VERSION" | tee -a "$GITHUB_ENV"
+
+        - name: Setup Composer
+          if: ${{ github.ref_type == 'branch' }}
+          shell: bash
+          run: |
+              COMPOSER_ROOT_VERSION=
+
+              COMPOSER_BRANCH_ALIAS="$(php -r "
+                  \$json = json_decode(file_get_contents('./composer.json'), true);
+                  if (\$json !== null) {
+                      if (isset(\$json['extra']['branch-alias']['dev-$GITHUB_REF_NAME'])) {
+                          echo 'dev-$GITHUB_REF_NAME';
+                      }
+                  }
+              ")"
+
+              if [ -z "$COMPOSER_BRANCH_ALIAS" ]; then
+                  PICO_VERSION_PATTERN="$(php -r "
+                      require('./lib/Pico.php');
+                      echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION);
+                  ")"
+              fi
+
+              if [ -n "$PICO_VERSION_PATTERN" ]; then
+                  COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN"
+                  echo "COMPOSER_ROOT_VERSION=$COMPOSER_ROOT_VERSION" | tee -a "$GITHUB_ENV"
+              fi
+
+        - name: Get Composer cache directory
+          shell: bash
+          run: |
+              COMPOSER_CACHE_DIR="$(composer config cache-dir)"
+              echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV"
+
+        - name: Restore Composer cache
+          uses: actions/cache@v2
+          with:
+              path: ${{ env.COMPOSER_CACHE_DIR }}
+              key: ${{ runner.os }}-composer-php${{ inputs.php-version }}
+              restore-keys: |
+                  ${{ runner.os }}-composer-
+
+        - name: Install Composer dependencies
+          shell: bash
+          run: |
+              composer install

+ 3 - 51
.github/workflows/test.yml

@@ -34,59 +34,11 @@ jobs:
             - name: Checkout repository
               uses: actions/checkout@v2
 
-            - name: Setup PHP ${{ env.PHP_VERSION }}
-              uses: shivammathur/setup-php@v2
+            - name: Install Pico CMS
+              uses: ./.github/actions/install
               with:
                   php-version: ${{ env.PHP_VERSION }}
-                  tools: composer, phpcs
-
-            - name: Read Pico version
-              run: |
-                  PICO_VERSION="$(php -r 'require("./lib/Pico.php"); echo Pico::VERSION;')"
-                  echo "PICO_VERSION=$PICO_VERSION" | tee -a "$GITHUB_ENV"
-
-            - name: Setup Composer
-              if: ${{ github.ref_type == 'branch' }}
-              run: |
-                  COMPOSER_ROOT_VERSION=
-
-                  COMPOSER_BRANCH_ALIAS="$(php -r "
-                      \$json = json_decode(file_get_contents('./composer.json'), true);
-                      if (\$json !== null) {
-                          if (isset(\$json['extra']['branch-alias']['dev-$GITHUB_REF_NAME'])) {
-                              echo 'dev-$GITHUB_REF_NAME';
-                          }
-                      }
-                  ")"
-
-                  if [ -z "$COMPOSER_BRANCH_ALIAS" ]; then
-                      PICO_VERSION_PATTERN="$(php -r "
-                          require_once('./lib/Pico.php');
-                          echo preg_replace('/\.[0-9]+-dev$/', '.x-dev', Pico::VERSION);
-                      ")"
-                  fi
-
-                  if [ -n "$PICO_VERSION_PATTERN" ]; then
-                      COMPOSER_ROOT_VERSION="$PICO_VERSION_PATTERN"
-                      echo "COMPOSER_ROOT_VERSION=$COMPOSER_ROOT_VERSION" | tee -a "$GITHUB_ENV"
-                  fi
-
-            - name: Get Composer cache directory
-              run: |
-                  COMPOSER_CACHE_DIR="$(composer config cache-dir)"
-                  echo "COMPOSER_CACHE_DIR=$COMPOSER_CACHE_DIR" | tee -a "$GITHUB_ENV"
-
-            - name: Restore Composer cache
-              uses: actions/cache@v2
-              with:
-                  path: ${{ env.COMPOSER_CACHE_DIR }}
-                  key: ${{ runner.os }}-composer-php${{ matrix.PHP_VERSION }}
-                  restore-keys: |
-                      ${{ runner.os }}-composer-
-
-            - name: Install Composer dependencies
-              run: |
-                  composer install
+                  php-tools: phpcs
 
             - name: Run PHP_CodeSniffer
               run: |