From 0c3ab0f5a723131be9ca8229634213ad6f833d6e Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Mon, 19 May 2025 22:49:58 -0700 Subject: [PATCH] Split out dependency install steps into composite action Fix incorrect action paths shell must be defined for run steps in action.yml --- .github/workflows/tests.yml | 160 ++++-------------------- actions/install-dependencies/action.yml | 52 ++++++++ 2 files changed, 78 insertions(+), 134 deletions(-) create mode 100644 actions/install-dependencies/action.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5cc6475..1e84a2a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -256,40 +256,13 @@ jobs: run: .github/setup-database.sh "$DB" "$MYISAM" working-directory: ./phpBB3 - - name: Set up Node.js - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/setup-node@v4 + - name: Install Dependencies + uses: phpbb-extensions/test-framework/actions/install-dependencies@3.3.x-experimental with: - node-version: 20 - - - name: Cache NPM dependencies - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/cache@v4 - with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Run npm ci - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - run: npm ci - working-directory: ./phpBB3/phpBB/ext/${{ env.EXTNAME }} - - - name: Cache Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - uses: actions/cache@v4 - with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/vendor - key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ matrix.php }}- - ${{ runner.os }}-composer- - - - name: Install Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - run: composer install - working-directory: ./phpBB3/phpBB/ext/${{ env.EXTNAME }} + RUN_NPM_INSTALL: ${{ inputs.RUN_NPM_INSTALL }} + RUN_COMPOSER_INSTALL: ${{ inputs.RUN_COMPOSER_INSTALL }} + EXTNAME: ${{ env.EXTNAME }} + PHP_VERSION: ${{ matrix.php }} - name: Setup PHPUnit files env: @@ -431,40 +404,13 @@ jobs: run: .github/setup-database.sh "$DB" "$MYISAM" working-directory: ./phpBB3 - - name: Set up Node.js - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/setup-node@v4 + - name: Install Dependencies + uses: phpbb-extensions/test-framework/actions/install-dependencies@3.3.x-experimental with: - node-version: 20 - - - name: Cache NPM dependencies - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/cache@v4 - with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Run npm ci - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - run: npm ci - working-directory: ./phpBB3/phpBB/ext/${{ env.EXTNAME }} - - - name: Cache Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - uses: actions/cache@v4 - with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/vendor - key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ matrix.php }}- - ${{ runner.os }}-composer- - - - name: Install Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - run: composer install - working-directory: ./phpBB3/phpBB/ext/${{ env.EXTNAME }} + RUN_NPM_INSTALL: ${{ inputs.RUN_NPM_INSTALL }} + RUN_COMPOSER_INSTALL: ${{ inputs.RUN_COMPOSER_INSTALL }} + EXTNAME: ${{ env.EXTNAME }} + PHP_VERSION: ${{ matrix.php }} - name: Setup PHPUnit files run: mkdir -p "phpBB/ext/$EXTNAME/.github" && cp .github/phpunit* "$_" @@ -577,40 +523,13 @@ jobs: run: .github/setup-database.sh "$DB" "$MYISAM" working-directory: ./phpBB3 - - name: Set up Node.js - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/setup-node@v4 - with: - node-version: 20 - - - name: Cache NPM dependencies - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/cache@v4 - with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Run npm ci - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - run: npm ci - working-directory: ./phpBB3/phpBB/ext/${{ env.EXTNAME }} - - - name: Cache Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - uses: actions/cache@v4 + - name: Install Dependencies + uses: phpbb-extensions/test-framework/actions/install-dependencies@3.3.x-experimental with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/vendor - key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ matrix.php }}- - ${{ runner.os }}-composer- - - - name: Install Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - run: composer install - working-directory: ./phpBB3/phpBB/ext/${{ env.EXTNAME }} + RUN_NPM_INSTALL: ${{ inputs.RUN_NPM_INSTALL }} + RUN_COMPOSER_INSTALL: ${{ inputs.RUN_COMPOSER_INSTALL }} + EXTNAME: ${{ env.EXTNAME }} + PHP_VERSION: ${{ matrix.php }} - name: Setup PHPUnit files run: mkdir -p "phpBB/ext/$EXTNAME/.github" && cp .github/phpunit* "$_" @@ -733,40 +652,13 @@ jobs: Set-MpPreference -ExclusionPath "${env:PGDATA}" # Exclude PGDATA directory from Windows Defender Set-MpPreference -DisableRealtimeMonitoring $true - - name: Set up Node.js - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/setup-node@v4 - with: - node-version: 20 - - - name: Cache NPM dependencies - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - uses: actions/cache@v4 + - name: Install Dependencies + uses: phpbb-extensions/test-framework/actions/install-dependencies@3.3.x-experimental with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/node_modules - key: ${{ runner.os }}-node-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - name: Run npm ci - if: ${{ inputs.RUN_NPM_INSTALL == '1' }} - run: npm ci - working-directory: .\phpBB3\phpBB\ext\${{ env.EXTNAME }} - - - name: Cache Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - uses: actions/cache@v4 - with: - path: ./phpBB3/phpBB/ext/${{ env.EXTNAME }}/vendor - key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('phpBB3/phpBB/ext/${{ env.EXTNAME }}/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer-${{ matrix.php }}- - ${{ runner.os }}-composer- - - - name: Install Composer dependencies - if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} - run: composer install - working-directory: .\phpBB3\phpBB\ext\${{ env.EXTNAME }} + RUN_NPM_INSTALL: ${{ inputs.RUN_NPM_INSTALL }} + RUN_COMPOSER_INSTALL: ${{ inputs.RUN_COMPOSER_INSTALL }} + EXTNAME: ${{ env.EXTNAME }} + PHP_VERSION: ${{ matrix.php }} - name: Setup PHPUnit files run: | @@ -774,7 +666,7 @@ jobs: mkdir "phpBB\ext\$env:EXTNAME\.github" } Copy-Item ".github\phpunit*" -Destination "phpBB\ext\$env:EXTNAME\.github" -Force - working-directory: .\phpBB3 + working-directory: ./phpBB3 - name: Run unit tests run: | @@ -791,5 +683,5 @@ jobs: } phpBB/vendor/bin/phpunit @args - working-directory: .\phpBB3 + working-directory: ./phpBB3 # END IIS & PostgreSQL on Windows Tests Job diff --git a/actions/install-dependencies/action.yml b/actions/install-dependencies/action.yml new file mode 100644 index 0000000..f9861a6 --- /dev/null +++ b/actions/install-dependencies/action.yml @@ -0,0 +1,52 @@ +name: Install Dependencies +description: Sets up Node.js, npm, and Composer for the extension + +inputs: + RUN_NPM_INSTALL: + required: true + RUN_COMPOSER_INSTALL: + required: true + EXTNAME: + required: true + PHP_VERSION: + required: false + +runs: + using: "composite" + steps: + - name: Set up Node.js + if: ${{ inputs.RUN_NPM_INSTALL == '1' }} + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Cache NPM dependencies + if: ${{ inputs.RUN_NPM_INSTALL == '1' }} + uses: actions/cache@v4 + with: + path: ./phpBB3/phpBB/ext/${{ inputs.EXTNAME }}/node_modules + key: ${{ runner.os }}-node-${{ hashFiles(format('phpBB3/phpBB/ext/{0}/package-lock.json', inputs.EXTNAME)) }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Run npm ci + if: ${{ inputs.RUN_NPM_INSTALL == '1' }} + run: npm ci + shell: bash + working-directory: ./phpBB3/phpBB/ext/${{ inputs.EXTNAME }} + + - name: Cache Composer dependencies + if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} + uses: actions/cache@v4 + with: + path: ./phpBB3/phpBB/ext/${{ inputs.EXTNAME }}/vendor + key: ${{ runner.os }}-composer-${{ inputs.PHP_VERSION || 'default' }}-${{ hashFiles(format('phpBB3/phpBB/ext/{0}/composer.lock', inputs.EXTNAME)) }} + restore-keys: | + ${{ runner.os }}-composer-${{ inputs.PHP_VERSION || 'default' }}- + ${{ runner.os }}-composer- + + - name: Install Composer dependencies + if: ${{ inputs.RUN_COMPOSER_INSTALL == '1' }} + run: composer install + shell: bash + working-directory: ./phpBB3/phpBB/ext/${{ inputs.EXTNAME }}