Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to node20 +semver:minor #16

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,28 @@ jobs:
# The npm script to run to build the action. This is typically 'npm run build' if the
# action needs to be compiled. For composite-run-steps actions this is typically empty.
build-command: 'npm run build'

create-cache:
runs-on: ubuntu-latest

env:
NUGET_CACHE_KEY: ''

outputs:
NUGET_CACHE_KEY: ${{ env.NUGET_CACHE_KEY }}

steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set Cache Keys
run: echo "NUGET_CACHE_KEY=nuget-${{ hashFiles('**/*.csproj') }}" >> $GITHUB_ENV

- name: Check for a nuget cache
id: has-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: '~/.nuget/packages'
key: ${{ env.NUGET_CACHE_KEY }}
Expand All @@ -93,15 +93,15 @@ jobs:
# This action creates a post-job step that will upload the ./.nuget/packages dir to the cache if the job completes successfully
- name: Setup caching for nuget packages if cache does not exist
if: steps.has-cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
uses: actions/cache@v4
with:
key: ${{ env.NUGET_CACHE_KEY }}
path: ~/.nuget/packages
enableCrossOsArchive: true

- name: Setup .NET Core if cache does not exist
if: steps.has-cache.outputs.cache-hit != 'true'
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.x
env:
Expand All @@ -111,7 +111,7 @@ jobs:
if: steps.has-cache.outputs.cache-hit != 'true'
working-directory: ./test/minimal-dotnet-proj
run: dotnet restore

test:
runs-on: ubuntu-latest
needs: [create-cache]
Expand All @@ -121,7 +121,7 @@ jobs:
BAD_CACHE_KEY: 'abc123'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand All @@ -130,7 +130,7 @@ jobs:
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When restoring a cache with a bad key and required=true
uses: ./
if: always()
Expand All @@ -140,25 +140,25 @@ jobs:
key: '${{ env.BAD_CACHE_KEY }}'
required: true
path: ~/.nuget/packages

- name: Then the outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.required.outcome }}"

- name: And the cache-hit output should be empty
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "" --actual "${{ steps.required.outputs.cache-hit }}"

- name: And the primary key output should match the key input
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "${{ env.BAD_CACHE_KEY }}" --actual "${{ steps.required.outputs.primary-key }}"

#--------------------------------------
# NO CACHE HIT - NO FAILURE
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When restoring a cache with a bad key and required=false
uses: ./
if: always()
Expand All @@ -167,25 +167,25 @@ jobs:
key: '${{ env.BAD_CACHE_KEY }}'
required: false
path: ~/.nuget/packages

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.not-required.outcome }}"

- name: And the cache-hit output should be false
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "false" --actual "${{ steps.not-required.outputs.cache-hit }}"
run: ./test/assert-values-match.sh --name "cache-hit" --expected "false" --actual "${{ steps.not-required.outputs.cache-hit }}"

- name: And the primary key output should match the key input
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "${{ env.BAD_CACHE_KEY }}" --actual "${{ steps.not-required.outputs.primary-key }}"

#--------------------------------------
# USING RESTORE KEYS
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When restoring a cache with a bad key and a list of restore keys
uses: ./
if: always()
Expand All @@ -198,25 +198,25 @@ jobs:
'bad-key-a'
'bad-key-b'
'bad-key-c'

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.restore-keys.outcome }}"

- name: And the cache-hit output should be false
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "false" --actual "${{ steps.restore-keys.outputs.cache-hit }}"

- name: And the primary key output should match the key input
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "${{ env.BAD_CACHE_KEY }}" --actual "${{ steps.restore-keys.outputs.primary-key }}"

#--------------------------------------
# EXACT MATCH
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When restoring a cache with the cache key
uses: ./
if: always()
Expand All @@ -225,18 +225,18 @@ jobs:
key: '${{ env.NUGET_CACHE_KEY }}'
required: true
path: ~/.nuget/packages

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.success.outcome }}"

- name: And the cache-hit output should be true
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "true" --actual "${{ steps.success.outputs.cache-hit }}"

- name: And the primary key output should match the key input
if: always()
run: ./test/assert-values-match.sh --name "cache-hit" --expected "${{ env.NUGET_CACHE_KEY }}" --actual "${{ steps.success.outputs.primary-key }}"

- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
run: echo ""
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# restore-cache

This is a fork of [martijnhols/actions-cache] at version 3.0.4 but only contains a slimmed down version of the [restore] action.
This is a fork of [martijnhols/actions-cache] at version 3.0.4 but only contains a slimmed down version of the [restore] action.

This action will restore a cache but will not save the cache in a post-job step.

Expand Down Expand Up @@ -37,6 +37,7 @@ If you need an action that saves a cache, check out the official [actions/cache]
| `cache-hit` | Flag indicating whether an exact match was found for the cache key | `true,false` |
| `primary-key` | The primary key that should be used when saving the cache. | |


## Usage Examples

```yml
Expand All @@ -46,28 +47,28 @@ jobs:
runs-on: ubuntu-20.04
outputs:
NPM_CACHE_KEY: ${{ env.NPM_CACHE_KEY }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set Cache Keys
run: echo "NPM_CACHE_KEY=node_modules-${{ hashFiles('**/package-lock.json') }}" >> $GITHUB_ENV

- name: Check for an npm cache
id: has-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ env.NPM_CACHE_KEY }}
lookup-only: true
enableCrossOsArchive: true

# This action will upload the node_modules dir to the cache if the job completes successfully.
# Subsequent jobs/workflow runs can use this cached copy if the package-lock.json hasn't changed
# and they are also using a ubuntu-20.04 runner to restore the cache from.
- name: Setup caching for node_modules directory if cache does not exist
if: steps.has-cache.outputs.cache-hit != 'true'
uses: actions/cache@v3
uses: actions/cache@v4
with:
key: ${{ env.NPM_CACHE_KEY }}
path: '**/node_modules'
Expand All @@ -76,15 +77,15 @@ jobs:
- name: npm ci if cache does not exist
if: steps.has-cache.outputs.cache-hit != 'true'
run: npm ci

jest:
runs-on: ubuntu-20.04
needs: [ npm-cache ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Download npm cache
uses: im-open/restore-cache@v1.2.0
uses: im-open/restore-cache@v1.3.0
with:
key: ${{ needs.npm-cache.outputs.NPM_CACHE_KEY }}
path: '**/node_modules'
Expand All @@ -94,8 +95,8 @@ jobs:

- name: jest test with coverage
run: npm test -- --json --outputFile=jest-results.json --coverage


```

## Contributing
Expand All @@ -122,7 +123,7 @@ This repo uses [git-version-lite] in its workflows to examine commit messages to

### Source Code Changes

The files and directories that are considered source code are listed in the `files-with-code` and `dirs-with-code` arguments in both the [build-and-review-pr] and [increment-version-on-merge] workflows.
The files and directories that are considered source code are listed in the `files-with-code` and `dirs-with-code` arguments in both the [build-and-review-pr] and [increment-version-on-merge] workflows.

If a PR contains source code changes, the README.md should be updated with the latest action version and the action should be recompiled. The [build-and-review-pr] workflow will ensure these steps are performed when they are required. The workflow will provide instructions for completing these steps if the PR Author does not initially complete them.

Expand All @@ -143,7 +144,7 @@ If changes are made to the action's [source code], the [usage examples] section

### Tests

The build and review PR workflow includes tests which are linked to a status check. That status check needs to succeed before a PR is merged to the default branch. The tests do not need special permissions, so they should succeed whether they come from a branch or a fork.
The build and review PR workflow includes tests which are linked to a status check. That status check needs to succeed before a PR is merged to the default branch. The tests do not need special permissions, so they should succeed whether they come from a branch or a fork.

## Code of Conduct

Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ outputs:
primary-key:
description: 'The primary key that should be used when saving the cache.'
runs:
using: 'node16'
using: 'node20'
main: './dist/index.js'
Loading