| # Copyright (C) 2025 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| name: run install-build-deps (with caching) |
| description: Restore and conditionally save the buildtools cache |
| inputs: |
| install-flags: |
| required: false |
| description: Optional flags to pass to install-build-deps (e.g., --android) |
| |
| runs: |
| using: "composite" |
| steps: |
| - name: Compute cache key |
| id: cachekey |
| shell: bash |
| run: | |
| # Replace spaces with underscores to keep the cache key valid |
| flags="${{ inputs.install-flags }}" |
| if [ -z "$flags" ]; then |
| echo "suffix=default" >> "$GITHUB_OUTPUT" |
| else |
| echo "suffix=$(echo "$flags" | tr ' -' '_')" >> "$GITHUB_OUTPUT" |
| fi |
| |
| - name: Restore build-deps from cache |
| uses: actions/cache/restore@v4 |
| with: |
| path: buildtools |
| # TODO(lalitm): buildtools folder has other files that are not |
| # covered by the cache key. This can lead to incorrect buildtools |
| # contents. Expand the cache key to include all files that are |
| # relevant for the buildtools folder or refactor the buildtools folder |
| # into two: one for the cachable outputs and the other for extra |
| # files which should not be cached. |
| key: buildtools-${{ hashFiles('buildtools/BUILD.gn') }}-${{ steps.cachekey.outputs.suffix }}-${{ hashFiles('tools/install-build-deps') }} |
| restore-keys: | |
| buildtools-${{ hashFiles('buildtools/BUILD.gn') }}-${{ steps.cachekey.outputs.suffix }}- |
| buildtools-${{ hashFiles('buildtools/BUILD.gn') }} |
| |
| - name: install-build-deps |
| run: tools/install-build-deps ${{ inputs.install-flags }} |
| shell: bash |
| |
| - name: Save build-deps cache (only on main) |
| if: github.ref == 'refs/heads/main' |
| uses: actions/cache/save@v4 |
| with: |
| path: buildtools |
| # TODO(lalitm): see the comment above about the cache key. |
| key: buildtools-${{ hashFiles('buildtools/BUILD.gn') }}-${{ steps.cachekey.outputs.suffix }}-${{ hashFiles('tools/install-build-deps') }} |