Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SmartDataLab
public
applications
renovate
Commits
fa582255
Unverified
Commit
fa582255
authored
Nov 26, 2020
by
Sarun Intaralawan
Committed by
GitHub
Nov 26, 2020
Browse files
Options
Downloads
Patches
Plain Diff
fix: call every `postUpgradeTasks` in the branch (#7735)
parent
31a2e8ae
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/workers/branch/index.spec.ts
+151
-0
151 additions, 0 deletions
lib/workers/branch/index.spec.ts
lib/workers/branch/index.ts
+93
-74
93 additions, 74 deletions
lib/workers/branch/index.ts
with
244 additions
and
74 deletions
lib/workers/branch/index.spec.ts
+
151
−
0
View file @
fa582255
...
...
@@ -687,6 +687,16 @@ describe('workers/branch', () => {
localDir
:
'
/localDir
'
,
allowedPostUpgradeCommands
:
[
'
^echo {{{versioning}}}$
'
],
allowPostUpgradeCommandTemplating
:
true
,
upgrades
:
[
{
...
defaultConfig
,
depName
:
'
some-dep-name
'
,
postUpgradeTasks
:
{
commands
:
[
'
echo {{{versioning}}}
'
,
'
disallowed task
'
],
fileFilters
:
[
'
modified_file
'
,
'
deleted_file
'
],
},
}
as
never
,
],
});
expect
(
result
).
toEqual
(
ProcessBranchResult
.
Done
);
...
...
@@ -742,6 +752,16 @@ describe('workers/branch', () => {
localDir
:
'
/localDir
'
,
allowedPostUpgradeCommands
:
[
'
^echo {{{versioning}}}$
'
],
allowPostUpgradeCommandTemplating
:
false
,
upgrades
:
[
{
...
defaultConfig
,
depName
:
'
some-dep-name
'
,
postUpgradeTasks
:
{
commands
:
[
'
echo {{{versioning}}}
'
,
'
disallowed task
'
],
fileFilters
:
[
'
modified_file
'
,
'
deleted_file
'
],
},
}
as
never
,
],
});
expect
(
result
).
toEqual
(
ProcessBranchResult
.
Done
);
...
...
@@ -749,5 +769,136 @@ describe('workers/branch', () => {
cwd
:
'
/localDir
'
,
});
});
it
(
'
executes post-upgrade tasks with multiple dependecy in one branch
'
,
async
()
=>
{
const
updatedPackageFile
:
File
=
{
name
:
'
pom.xml
'
,
contents
:
'
pom.xml file contents
'
,
};
getUpdated
.
getUpdatedPackageFiles
.
mockResolvedValueOnce
({
updatedPackageFiles
:
[
updatedPackageFile
],
artifactErrors
:
[],
}
as
never
);
npmPostExtract
.
getAdditionalFiles
.
mockResolvedValueOnce
({
artifactErrors
:
[],
updatedArtifacts
:
[
{
name
:
'
yarn.lock
'
,
contents
:
Buffer
.
from
([
1
,
2
,
3
])
/* Binary content */
,
},
],
}
as
never
);
git
.
branchExists
.
mockReturnValueOnce
(
true
);
platform
.
getBranchPr
.
mockResolvedValueOnce
({
title
:
'
rebase!
'
,
state
:
PrState
.
Open
,
body
:
`- [x] <!-- rebase-check -->`
,
}
as
never
);
git
.
isBranchModified
.
mockResolvedValueOnce
(
true
);
git
.
getRepoStatus
.
mockResolvedValueOnce
({
modified
:
[
'
modified_file
'
,
'
modified_then_deleted_file
'
],
not_added
:
[],
deleted
:
[
'
deleted_file
'
,
'
deleted_then_created_file
'
],
}
as
StatusResult
)
.
mockResolvedValueOnce
({
modified
:
[
'
modified_file
'
,
'
deleted_then_created_file
'
],
not_added
:
[],
deleted
:
[
'
deleted_file
'
,
'
modified_then_deleted_file
'
],
}
as
StatusResult
);
global
.
trustLevel
=
'
high
'
;
fs
.
outputFile
.
mockReturnValue
();
fs
.
readFile
.
mockResolvedValueOnce
(
Buffer
.
from
(
'
modified file content
'
))
.
mockResolvedValueOnce
(
Buffer
.
from
(
'
this file will not exists
'
))
.
mockResolvedValueOnce
(
Buffer
.
from
(
'
modified file content again
'
))
.
mockResolvedValueOnce
(
Buffer
.
from
(
'
this file was once deleted
'
));
schedule
.
isScheduledNow
.
mockReturnValueOnce
(
false
);
commit
.
commitFilesToBranch
.
mockResolvedValueOnce
(
null
);
const
inconfig
=
{
...
config
,
postUpgradeTasks
:
{
commands
:
[
'
echo {{{depName}}}
'
,
'
disallowed task
'
],
fileFilters
:
[
'
modified_file
'
,
'
deleted_file
'
,
'
deleted_then_created_file
'
,
'
modified_then_deleted_file
'
,
],
},
localDir
:
'
/localDir
'
,
allowedPostUpgradeCommands
:
[
'
^echo {{{depName}}}$
'
],
allowPostUpgradeCommandTemplating
:
true
,
upgrades
:
[
{
...
defaultConfig
,
depName
:
'
some-dep-name-1
'
,
postUpgradeTasks
:
{
commands
:
[
'
echo {{{depName}}}
'
,
'
disallowed task
'
],
fileFilters
:
[
'
modified_file
'
,
'
deleted_file
'
,
'
deleted_then_created_file
'
,
'
modified_then_deleted_file
'
,
],
},
}
as
never
,
{
...
defaultConfig
,
depName
:
'
some-dep-name-2
'
,
postUpgradeTasks
:
{
commands
:
[
'
echo {{{depName}}}
'
,
'
disallowed task
'
],
fileFilters
:
[
'
modified_file
'
,
'
deleted_file
'
,
'
deleted_then_created_file
'
,
'
modified_then_deleted_file
'
,
],
},
}
as
never
,
],
};
const
result
=
await
branchWorker
.
processBranch
(
inconfig
);
expect
(
result
).
toEqual
(
ProcessBranchResult
.
Done
);
expect
(
exec
.
exec
).
toHaveBeenNthCalledWith
(
1
,
'
echo some-dep-name-1
'
,
{
cwd
:
'
/localDir
'
,
});
expect
(
exec
.
exec
).
toHaveBeenNthCalledWith
(
2
,
'
echo some-dep-name-2
'
,
{
cwd
:
'
/localDir
'
,
});
expect
(
exec
.
exec
).
toHaveBeenCalledTimes
(
2
);
expect
(
(
commit
.
commitFilesToBranch
.
mock
.
calls
[
0
][
0
].
updatedArtifacts
.
find
(
(
f
)
=>
f
.
name
===
'
modified_file
'
).
contents
as
Buffer
).
toString
()
).
toBe
(
'
modified file content again
'
);
expect
(
(
commit
.
commitFilesToBranch
.
mock
.
calls
[
0
][
0
].
updatedArtifacts
.
find
(
(
f
)
=>
f
.
name
===
'
deleted_then_created_file
'
).
contents
as
Buffer
).
toString
()
).
toBe
(
'
this file was once deleted
'
);
expect
(
commit
.
commitFilesToBranch
.
mock
.
calls
[
0
][
0
].
updatedArtifacts
.
find
(
(
f
)
=>
f
.
contents
===
'
deleted_then_created_file
'
&&
f
.
name
===
'
|delete|
'
)
).
toBeUndefined
();
expect
(
commit
.
commitFilesToBranch
.
mock
.
calls
[
0
][
0
].
updatedArtifacts
.
find
(
(
f
)
=>
f
.
name
===
'
modified_then_deleted_file
'
)
).
toBeUndefined
();
expect
(
commit
.
commitFilesToBranch
.
mock
.
calls
[
0
][
0
].
updatedArtifacts
.
find
(
(
f
)
=>
f
.
contents
===
'
modified_then_deleted_file
'
&&
f
.
name
===
'
|delete|
'
)
).
not
.
toBeUndefined
();
});
});
});
This diff is collapsed.
Click to expand it.
lib/workers/branch/index.ts
+
93
−
74
View file @
fa582255
...
...
@@ -12,7 +12,7 @@ import {
SYSTEM_INSUFFICIENT_DISK_SPACE
,
WORKER_FILE_UPDATE_FAILED
,
}
from
'
../../constants/error-messages
'
;
import
{
logger
}
from
'
../../logger
'
;
import
{
addMeta
,
logger
,
removeMeta
}
from
'
../../logger
'
;
import
{
getAdditionalFiles
}
from
'
../../manager/npm/post-update
'
;
import
{
Pr
,
platform
}
from
'
../../platform
'
;
import
{
BranchStatus
,
PrState
}
from
'
../../types
'
;
...
...
@@ -342,15 +342,17 @@ export async function processBranch(
global
.
trustLevel
===
'
high
'
&&
is
.
nonEmptyArray
(
config
.
allowedPostUpgradeCommands
)
)
{
logger
.
debug
(
for
(
const
upgrade
of
config
.
upgrades
)
{
addMeta
({
dep
:
upgrade
.
depName
});
logger
.
trace
(
{
tasks
:
config
.
postUpgradeTasks
,
tasks
:
upgrade
.
postUpgradeTasks
,
allowedCommands
:
config
.
allowedPostUpgradeCommands
,
},
'
Checking for post-upgrade tasks
'
);
const
commands
=
config
.
postUpgradeTasks
.
commands
||
[];
const
fileFilters
=
config
.
postUpgradeTasks
.
fileFilters
||
[];
const
commands
=
upgrade
.
postUpgradeTasks
.
commands
||
[];
const
fileFilters
=
upgrade
.
postUpgradeTasks
.
fileFilters
||
[];
if
(
is
.
nonEmptyArray
(
commands
))
{
// Persist updated files in file system so any executed commands can see them
...
...
@@ -383,7 +385,7 @@ export async function processBranch(
);
}
else
{
const
compiledCmd
=
config
.
allowPostUpgradeCommandTemplating
?
template
.
compile
(
cmd
,
config
)
?
template
.
compile
(
cmd
,
upgrade
)
:
cmd
;
logger
.
debug
({
cmd
:
compiledCmd
},
'
Executing post-upgrade task
'
);
...
...
@@ -409,11 +411,22 @@ export async function processBranch(
'
Post-upgrade file saved
'
);
const
existingContent
=
await
readLocalFile
(
relativePath
);
const
existingUpdatedArtifacts
=
config
.
updatedArtifacts
.
find
(
(
ua
)
=>
ua
.
name
===
relativePath
);
if
(
existingUpdatedArtifacts
)
{
existingUpdatedArtifacts
.
contents
=
existingContent
;
}
else
{
config
.
updatedArtifacts
.
push
({
name
:
relativePath
,
contents
:
existingContent
,
});
}
// If the file is deleted by a previous post-update command, remove the deletion from updatedArtifacts
config
.
updatedArtifacts
=
config
.
updatedArtifacts
.
filter
(
(
ua
)
=>
ua
.
name
!==
'
|delete|
'
||
ua
.
contents
!==
relativePath
);
}
}
}
...
...
@@ -428,11 +441,17 @@ export async function processBranch(
name
:
'
|delete|
'
,
contents
:
relativePath
,
});
// If the file is created or modified by a previous post-update command, remove the modification from updatedArtifacts
config
.
updatedArtifacts
=
config
.
updatedArtifacts
.
filter
(
(
ua
)
=>
ua
.
name
!==
relativePath
);
}
}
}
}
}
}
removeMeta
([
'
dep
'
]);
if
(
config
.
artifactErrors
?.
length
)
{
if
(
config
.
releaseTimestamp
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment