(id: string)
| 132 | * @param id ID of the package manager, should be "maven" or "gradle" |
| 133 | */ |
| 134 | export async function save(id: string) { |
| 135 | const packageManager = findPackageManager(id); |
| 136 | const matchedKey = core.getState(CACHE_MATCHED_KEY); |
| 137 | |
| 138 | // Inputs are re-evaluated before the post action, so we want the original key used for restore |
| 139 | const primaryKey = core.getState(STATE_CACHE_PRIMARY_KEY); |
| 140 | |
| 141 | if (!primaryKey) { |
| 142 | core.warning('Error retrieving key from state.'); |
| 143 | return; |
| 144 | } else if (matchedKey === primaryKey) { |
| 145 | // no change in target directories |
| 146 | core.info( |
| 147 | `Cache hit occurred on the primary key ${primaryKey}, not saving cache.` |
| 148 | ); |
| 149 | return; |
| 150 | } |
| 151 | try { |
| 152 | const cacheId = await cache.saveCache(packageManager.path, primaryKey); |
| 153 | if (cacheId === -1) { |
| 154 | // saveCache returns -1 without throwing when the cache was not saved, |
| 155 | // e.g. a reserve collision or a read-only token (fork PR). @actions/cache |
| 156 | // has already logged the reason at the appropriate severity, so just |
| 157 | // trace it instead of misreporting that the cache was saved. |
| 158 | core.debug(`Cache was not saved for the key: ${primaryKey}`); |
| 159 | return; |
| 160 | } |
| 161 | core.info(`Cache saved with the key: ${primaryKey}`); |
| 162 | } catch (error) { |
| 163 | const err = error as Error; |
| 164 | |
| 165 | if (err.name === cache.ReserveCacheError.name) { |
| 166 | core.info(err.message); |
| 167 | } else { |
| 168 | if (isProbablyGradleDaemonProblem(packageManager, err)) { |
| 169 | core.warning( |
| 170 | 'Failed to save Gradle cache on Windows. If tar.exe reported "Permission denied", try to run Gradle with `--no-daemon` option. Refer to https://github.com/actions/cache/issues/454 for details.' |
| 171 | ); |
| 172 | } |
| 173 | throw error; |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @param packageManager the specified package manager by user |
no test coverage detected