Repository navigation
fix: prepare cache paths for restore on Linux #23
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import * as core from '@actions/core' | ||
| import { logger } from '../onegetjs/logger' | ||
| import * as cache from '@actions/cache' | ||
| import { exec } from '@actions/exec' | ||
| import { isLinux } from '../platform' | ||
| import { restoreCacheByPrimaryKey } from '../utils' | ||
|
|
||
| export class CacheManager { | ||
|
|
@@ -17,6 +19,7 @@ export class CacheManager { | |
| key: string, | ||
| paths: string[] | ||
| ): Promise<string | undefined> { | ||
| await this.prepareCachePaths(paths) | ||
| const matchedKey = await restoreCacheByPrimaryKey(paths, key) | ||
| this.logCacheResult(matchedKey, key) | ||
| return matchedKey | ||
|
|
@@ -39,6 +42,31 @@ export class CacheManager { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Подготавливает каталоги кэша к распаковке архива actions/cache. | ||
| * | ||
| * Установленные продукты 1С лежат в системных каталогах (/opt/1C, /etc/1C/...), | ||
| * которые недоступны на запись пользователю раннера. actions/cache распаковывает | ||
| * архив tar от имени раннера без sudo, поэтому без подготовки путей restore | ||
| * всегда падает с `Cannot mkdir: Permission denied` и кэш фактически не работает. | ||
| * | ||
| * Для каждого пути: создаёт каталог и передаёт владение пользователю раннера. | ||
| * Только Linux; на Windows/macOS распаковка в системные каталоги и так проходит | ||
| * от имени процесса раннера. | ||
| */ | ||
| private async prepareCachePaths(paths: string[]): Promise<void> { | ||
| if (!isLinux()) { | ||
| return | ||
| } | ||
|
|
||
| const user = process.env['USER'] || 'runner' | ||
| for (const dir of paths) { | ||
| logger.info(`Preparing cache path ${dir}`) | ||
| await exec('sudo', ['mkdir', '-p', dir]) | ||
| await exec('sudo', ['chown', '-R', `${user}:`, dir]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
| private logCacheResult(matchedKey: string | undefined, primaryKey: string) { | ||
| if (matchedKey) { | ||
| logger.info(`Cache restored from key: ${matchedKey}`) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: 1CDevFlow/onec-setup-action
Length of output: 3187
Script executed:
Repository: 1CDevFlow/onec-setup-action
Length of output: 9849
Use the process effective IDs for cache ownership.
When
useCacheis enabled,restoreInstalledawaitsprepareCachePathsbefore the cache lookup. IfUSERis unset or names an account different from the process account,sudo chowncan fail or assign ownership incorrectly. The rejected command prevents the cache lookup and the later installer fallback.Use the effective UID and GID instead of
USERand therunnerfallback.Suggested fix