openrewrite / openrewrite/rewrite-github-actions

Prefer `actions/setup` caching over `actions/cache`

Open
#47 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
1
Forks
9
Avg merge
5h 27m
Merged PRs (30d)
12

Description

  1. Remove actions/cache
  2. Add the cache key to the corresponding actions/setup

See :
https://github.com/actions/setup-java#caching-packages-dependencies
https://github.com/actions/setup-node#caching-packages-dependencies
https://github.com/actions/setup-python
https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs

Examples:


diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 4555776..785bc33 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -17,16 +17,11 @@ jobs:
       checks: write
     steps:
       - uses: actions/checkout@v3
-      - uses: actions/cache@v3
-        with:
-          path: ~/.m2/repository
-          key: ${{ runner.os }}-main-maven-${{ hashFiles('**/pom.xml') }}
-          restore-keys: |
-            ${{ runner.os }}-main-maven-
       - uses: actions/setup-java@v3
         with:
           java-version: 8
          distribution: 'zulu'
+          cache: 'maven'
       - run: cd tests && mvn clean test --batch-mode -Dmaven.test.failure.ignore=true
       - uses: ./
         if: github.ref != 'refs/heads/master'

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 785bc33..e2d8a91 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -52,12 +52,7 @@ jobs:
       - uses: actions/setup-node@v3
         with:
           node-version: 16
-      - uses: actions/cache@v3
-        with:
-          path: ~/.npm
-          key: ${{ runner.os }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
-          restore-keys: |
-            ${{ runner.os }}-npm-cache-
+          cache: npm
       - run: npm install
       - run: npm run eslint
       - run: npm run test

I think that the main challenge here is to determine what type to use.

For example, for actions/setup-java we have maven, gradle and sbt as options. The recipe should be able to detect the package manager and make the correct selection

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with .github/workflows/build.yml and the linked actions/setup-java, setup-node, setup-python, and setup-go caching documentation. Inspect how the recipe identifies actions/cache steps and determine the matching package-manager cache option for each setup action; done means the manual cache steps are replaced with the corresponding setup cache keys.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, yaml
Domain
ci-cd
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.