From 7cd7fb8b08410248a1a5b1197842ad12b90dbf21 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Sat, 23 Nov 2024 16:10:09 +0100 Subject: [PATCH 1/2] Improved action workflow --- .github/workflows/action.yaml | 51 +++++++++++++---------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/.github/workflows/action.yaml b/.github/workflows/action.yaml index ec14b5a65..ec95ab3da 100644 --- a/.github/workflows/action.yaml +++ b/.github/workflows/action.yaml @@ -24,38 +24,31 @@ jobs: id: npm-cache-dir-path run: echo "dir=$(npm get cache)" >> $GITHUB_OUTPUT - - name: Calculate package-lock.json hash - id: npm-lock-hash - run: | - echo "hash=$(md5sum package-lock.json)" >> $GITHUB_OUTPUT - - name: Get Composer Cache Directory id: composer-cache run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Calculate composer.lock hash - id: composer-lock-hash - run: | - echo "hash=$(md5sum composer.lock)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - id: npm-cache # use this to check for `cache-hit` (`steps.npm-cache.outputs.cache-hit != 'true'`) + id: npm-cache with: path: ${{ steps.npm-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-npm-${{ steps.npm-lock-hash.outputs.hash }} + key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} restore-keys: ${{ runner.os }}-npm- - uses: actions/cache@v4 + id: vendor-cache with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-no-dev-${{ steps.composer-lock-hash.outputs.hash }} + key: ${{ runner.os }}-composer-no-dev-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer-no-dev- - run: cp .env.example .env - name: Composer install + if: steps.vendor-cache.outputs.cache-hit != 'true' run: composer install --no-dev --no-progress - name: NPM install + if: steps.npm-cache.outputs.cache-hit != 'true' run: npm ci --include=dev env: NODE_ENV: production @@ -75,19 +68,16 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Calculate composer.lock hash - id: composer-lock-hash - run: | - echo "hash=$(md5sum composer.lock)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 + id: vendor-cache with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ steps.composer-lock-hash.outputs.hash }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - run: cp .env.example .env - name: Composer install + if: steps.vendor-cache.outputs.cache-hit != 'true' run: composer install --no-scripts --no-progress - name: Run unit tests @@ -104,24 +94,22 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Get Composer Cache Directory + - name: Get Composer cache directory id: composer-cache run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Calculate composer.lock hash - id: composer-lock-hash - run: | - echo "hash=$(md5sum composer.lock)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v4 + - name: Cache vendor directory + id: cache-vendor + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ steps.composer-lock-hash.outputs.hash }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - run: cp .env.example .env - name: Composer install + if: steps.cache-vendor.outputs.cache-hit != 'true' run: composer install --no-scripts --no-progress - name: Run Npm audit @@ -144,18 +132,15 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Calculate tools/composer.lock hash - id: composer-lock-hash - run: | - echo "hash=$(md5sum tools/composer.lock)" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 + id: vendor-cache with: path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-tools-${{ steps.composer-lock-hash.outputs.hash }} + key: ${{ runner.os }}-composer-tools-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer-tools- - name: Composer tools install + if: steps.vendor-cache.outputs.cache-hit != 'true' run: composer -d tools install --no-scripts --no-progress - name: php-cs-fixer dry-run From 99de788ff9f37e8e71a001eb0c91bf5196a53be1 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Sat, 23 Nov 2024 16:22:39 +0100 Subject: [PATCH 2/2] Remove cache hit check --- .github/workflows/action.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/action.yaml b/.github/workflows/action.yaml index ec95ab3da..d2a68aee1 100644 --- a/.github/workflows/action.yaml +++ b/.github/workflows/action.yaml @@ -37,7 +37,6 @@ jobs: restore-keys: ${{ runner.os }}-npm- - uses: actions/cache@v4 - id: vendor-cache with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-no-dev-${{ hashFiles('**/composer.lock') }} @@ -45,10 +44,8 @@ jobs: - run: cp .env.example .env - name: Composer install - if: steps.vendor-cache.outputs.cache-hit != 'true' run: composer install --no-dev --no-progress - name: NPM install - if: steps.npm-cache.outputs.cache-hit != 'true' run: npm ci --include=dev env: NODE_ENV: production @@ -69,7 +66,6 @@ jobs: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 - id: vendor-cache with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} @@ -77,7 +73,6 @@ jobs: - run: cp .env.example .env - name: Composer install - if: steps.vendor-cache.outputs.cache-hit != 'true' run: composer install --no-scripts --no-progress - name: Run unit tests @@ -100,7 +95,6 @@ jobs: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache vendor directory - id: cache-vendor uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} @@ -109,7 +103,6 @@ jobs: - run: cp .env.example .env - name: Composer install - if: steps.cache-vendor.outputs.cache-hit != 'true' run: composer install --no-scripts --no-progress - name: Run Npm audit @@ -133,14 +126,12 @@ jobs: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 - id: vendor-cache with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-tools-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer-tools- - name: Composer tools install - if: steps.vendor-cache.outputs.cache-hit != 'true' run: composer -d tools install --no-scripts --no-progress - name: php-cs-fixer dry-run