From 297810a469c3884919cae28126669fc5908d328c Mon Sep 17 00:00:00 2001 From: n0099 Date: Tue, 13 Feb 2024 05:56:03 +0800 Subject: [PATCH] * fix not saving `action/cache` after failed jobs @ actions/{be,fe,c#}/action.yml @ .github --- .github/actions/be/action.yml | 22 ++++++++++++++++------ .github/actions/c#/action.yml | 21 ++++++++++++++++++--- .github/actions/fe/action.yml | 28 +++++++++++++++++++++++----- .github/workflows/fe.yml | 2 +- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/.github/actions/be/action.yml b/.github/actions/be/action.yml index 512c6d57..9903eac3 100644 --- a/.github/actions/be/action.yml +++ b/.github/actions/be/action.yml @@ -15,19 +15,29 @@ runs: ini-values: opcache.enable_cli=1 env: # https://github.com/shivammathur/setup-php/blob/6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d/README.md#force-update-setup update: 'true' - # https://github.com/shivammathur/setup-php/blob/6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d/README.md#cache-composer-dependencies + # https://github.com/shivammathur/setup-php/blob/6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d/README.md#problem-matchers - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" working-directory: be shell: bash - - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + # https://github.com/shivammathur/setup-php/blob/6d7209f44a25a59e904b1ee9f3b0c33ab2cd888d/README.md#cache-composer-dependencies + # https://github.com/actions/cache/blob/a2ed59d39b352305bdd2f628719a53b2cc4f9613/examples.md#php---composer + - id: get-composer-cache-dir + run: echo "path=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT working-directory: be shell: bash - - uses: actions/cache@v4 + - id: cache-restore + uses: actions/cache/restore@v4 with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('be/composer.lock') }} + path: ${{ steps.get-composer-cache-dir.outputs.path }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - run: composer install --prefer-dist working-directory: be shell: bash + # https://github.com/actions/runner/issues/1478 + # https://github.com/actions/setup-node/issues/410#issuecomment-1939482965 + - uses: actions/cache/save@v4 + if: ${{ steps.cache-restore.outputs.cache-hit != 'true' }} + with: + path: ${{ steps.get-composer-cache-dir.outputs.path }} + key: ${{ steps.cache-restore.outputs.cache-primary-key }} diff --git a/.github/actions/c#/action.yml b/.github/actions/c#/action.yml index e6686bd4..9c7ee5e0 100644 --- a/.github/actions/c#/action.yml +++ b/.github/actions/c#/action.yml @@ -9,12 +9,27 @@ runs: - uses: actions/setup-dotnet@v4 with: # https://github.com/actions/setup-dotnet/tree/v4 dotnet-version: 7 - cache: true - # https://github.com/actions/setup-node/issues/624#issuecomment-1328681525 - cache-dependency-path: ${{ github.workspace }}/c#/*/packages.lock.json + # cache: true + # # https://github.com/actions/setup-node/issues/624#issuecomment-1328681525 + # cache-dependency-path: ${{ github.workspace }}/c#/*/packages.lock.json + # in favor of https://github.com/actions/cache/blob/a2ed59d39b352305bdd2f628719a53b2cc4f9613/examples.md#c---nuget + # to allow saving cache even jobs failed + - id: cache-restore + uses: actions/cache/restore@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} + restore-keys: ${{ runner.os }}-nuget- - run: dotnet new globaljson --sdk-version 7.0.405 working-directory: c# shell: bash - run: dotnet restore working-directory: c# shell: bash + # https://github.com/actions/runner/issues/1478 + # https://github.com/actions/setup-node/issues/410#issuecomment-1939482965 + - uses: actions/cache/save@v4 + if: ${{ steps.cache-restore.outputs.cache-hit != 'true' }} + with: + path: ~/.nuget/packages + key: ${{ steps.cache-restore.outputs.cache-primary-key }} diff --git a/.github/actions/fe/action.yml b/.github/actions/fe/action.yml index 546d7ec2..55ea3b0a 100644 --- a/.github/actions/fe/action.yml +++ b/.github/actions/fe/action.yml @@ -7,10 +7,28 @@ runs: - uses: actions/setup-node@v4 with: # https://github.com/actions/setup-node/tree/v4 node-version: lts/* - cache: yarn - # https://github.com/actions/setup-node/issues/624#issuecomment-1328681525 - cache-dependency-path: ${{ github.workspace }}/fe/yarn.lock - - name: install - run: yarn install --immutable + # cache: yarn + # # https://github.com/actions/setup-node/issues/624#issuecomment-1328681525 + # cache-dependency-path: ${{ github.workspace }}/fe/yarn.lock + # in favor of https://github.com/actions/cache/blob/a2ed59d39b352305bdd2f628719a53b2cc4f9613/examples.md#node---yarn-2 + # to allow saving cache even jobs failed + - id: get-yarn-cache-dir + run: echo "path=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT working-directory: fe shell: bash + - id: cache-restore + uses: actions/cache/restore@v4 + with: + path: ${{ steps.get-yarn-cache-dir.outputs.path }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: ${{ runner.os }}-yarn- + - run: yarn install --immutable + working-directory: fe + shell: bash + # https://github.com/actions/runner/issues/1478 + # https://github.com/actions/setup-node/issues/410#issuecomment-1939482965 + - uses: actions/cache/save@v4 + if: ${{ steps.cache-restore.outputs.cache-hit != 'true' }} + with: + path: ${{ steps.get-yarn-cache-dir.outputs.path }} + key: ${{ steps.cache-restore.outputs.cache-primary-key }} diff --git a/.github/workflows/fe.yml b/.github/workflows/fe.yml index 33273113..ebcf29ed 100644 --- a/.github/workflows/fe.yml +++ b/.github/workflows/fe.yml @@ -1,7 +1,7 @@ name: fe on: push: - paths: [fe/**] + #paths: [fe/**] defaults: run: working-directory: fe