Skip to content
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
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,44 @@

- name: "index.html: expected output"
run: test 'index.html test output' = "$(curl --silent https://setup-ddev-proj1.test)"

cache-save:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: ./
with:
ddevDir: tests/fixtures/ddevProj2
cacheDependencies: true

- name: Install dependencies to fill the cache
working-directory: tests/fixtures/ddevProj2
run: |
ddev composer install
ddev npm ci

cache-restore:
Comment on lines +81 to +97
needs: cache-save
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: ./
id: ddev
with:
ddevDir: tests/fixtures/ddevProj2
cacheDependencies: true

- name: Cache restored
env:
CACHE_HIT: ${{ steps.ddev.outputs.cache-hit }}
run: test "$CACHE_HIT" = 'true'

- name: Install dependencies without network access
working-directory: tests/fixtures/ddevProj2
run: |
ddev exec 'COMPOSER_DISABLE_NETWORK=1 composer install'
ddev npm ci --offline
Comment on lines +98 to +119
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ Example with custom script source:
version: "v1.24.8"
```

### cacheDependencies

Caches Composer, npm and Yarn downloads between workflow runs with [`actions/cache`](https://github.com/actions/cache), keyed on `composer.lock`, `package-lock.json` and `yarn.lock`. The caches are stored in `.ddev/.setup-ddev-cache` in the project, and a generated `.ddev/config.zz-setup-ddev-cache.yaml` points the package managers at them. The `cache-hit` output is `true` when the lock files matched a saved cache exactly.

default: `false`

```yaml
- uses: ddev/github-action-setup-ddev@v1
with:
cacheDependencies: true
- run: ddev composer install
- run: ddev npm ci
```

Pull requests can only restore caches saved on their own branch or the default branch, so run the workflow on pushes to the default branch too. Caching DDEV's Docker images doesn't help: restoring them takes longer than pulling them ([#15](https://github.com/ddev/github-action-setup-ddev/issues/15)).

## Common recipes

### SSH keys
Expand Down
34 changes: 34 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ inputs:
required: true
default: 'https://ddev.com/install.sh'

cacheDependencies:
description: 'Cache Composer, npm and Yarn downloads between workflow runs, keyed on the lock files.'
required: false
default: 'false'

outputs:
cache-hit:
description: 'Whether cacheDependencies restored an exact match for the lock files.'
value: ${{ steps.cache.outputs.cache-hit }}

runs:
using: 'composite'
steps:
Expand Down Expand Up @@ -57,6 +67,30 @@ runs:
/tmp/install_ddev.sh ${VERSION_ARG}
ddev config global --instrumentation-opt-in=false --omit-containers=ddev-ssh-agent

# DDEV's own caches live in a Docker volume that actions/cache can't reach,
# so point the package managers at a directory inside the project instead.
- name: Point package caches at the project
if: inputs.cacheDependencies == 'true'
shell: bash
working-directory: ${{ inputs.ddevDir }}
run: |
mkdir -p .ddev/.setup-ddev-cache
cat > .ddev/config.zz-setup-ddev-cache.yaml <<'EOF'
web_environment:
- COMPOSER_CACHE_DIR=/var/www/html/.ddev/.setup-ddev-cache/composer
- npm_config_cache=/var/www/html/.ddev/.setup-ddev-cache/npm
- YARN_CACHE_FOLDER=/var/www/html/.ddev/.setup-ddev-cache/yarn
EOF

- name: Cache dependencies
id: cache
if: inputs.cacheDependencies == 'true'
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ inputs.ddevDir }}/.ddev/.setup-ddev-cache
key: setup-ddev-deps-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles(format('{0}/composer.lock', inputs.ddevDir), format('{0}/package-lock.json', inputs.ddevDir), format('{0}/yarn.lock', inputs.ddevDir)) }}
restore-keys: setup-ddev-deps-${{ runner.os }}-${{ runner.arch }}-

- name: Start DDEV project
shell: bash
working-directory: ${{ inputs.ddevDir }}
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/ddevProj2/.ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: setup-ddev-proj2
type: php
docroot: ""
omit_containers: [db]
7 changes: 7 additions & 0 deletions tests/fixtures/ddevProj2/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "ddev/setup-ddev-cache-test",
"type": "project",
"require": {
"psr/log": "3.0.2"
}
}
70 changes: 70 additions & 0 deletions tests/fixtures/ddevProj2/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/fixtures/ddevProj2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/fixtures/ddevProj2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "setup-ddev-cache-test",
"private": true,
"dependencies": {
"is-number": "7.0.0"
}
}
Loading