Skip to content

Commit

Permalink
Fix bug with default before_script and after_script
Browse files Browse the repository at this point in the history
  • Loading branch information
firecow committed Feb 22, 2021
1 parent e9a7fc2 commit c6cc35d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "gitlab-ci-local",
"main": "src/index.js",
"bin": "src/index.js",
"version": "4.9.5",
"version": "4.9.6",
"scripts": {
"prepublishOnly": "npm run check-all && chmod +x src/index.js",
"pkg-linux": "pkg src/index.js --public -t linux-x64 -o bin/linux/gitlab-ci-local && chmod +x bin/linux/gitlab-ci-local && gzip -c bin/linux/gitlab-ci-local > bin/linux.gz",
Expand Down
4 changes: 2 additions & 2 deletions src/job-expanders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function beforeScripts(gitlabData: any) {
forEachRealJob(gitlabData, (_, jobData) => {
const expandedBeforeScripts = [].concat(jobData.before_script || (gitlabData.default || {}).before_script || gitlabData.before_script || []);
if (expandedBeforeScripts.length > 0) {
jobData.beforeScripts = expandedBeforeScripts;
jobData.before_script = expandedBeforeScripts;
}
});
}
Expand All @@ -68,7 +68,7 @@ export function afterScripts(gitlabData: any) {
forEachRealJob(gitlabData, (_, jobData) => {
const expandedAfterScripts = [].concat(jobData.after_script || (gitlabData.default || {}).after_script || gitlabData.after_script || []);
if (expandedAfterScripts.length > 0) {
jobData.afterScripts = expandedAfterScripts;
jobData.after_script = expandedAfterScripts;
}
});
}
Expand Down
20 changes: 20 additions & 0 deletions src/tests/cases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ test('before-script <test-job>', async () => {
expect(mockProcessExit).toBeCalledTimes(0);
});

test('before-script-default <test-job>', async () => {
await defaultCmd.handler({
cwd: 'src/tests/test-cases/before-script-default',
job: 'test-job'
});
expect(mockProcessStdout).toHaveBeenCalledWith("Before test\n");
expect(mockProcessStderr).toBeCalledTimes(0);
expect(mockProcessExit).toBeCalledTimes(0);
});

test('after-script <test-job>', async () => {
await defaultCmd.handler({
cwd: 'src/tests/test-cases/after-script',
Expand All @@ -133,6 +143,16 @@ test('after-script <test-job>', async () => {
expect(mockProcessExit).toBeCalledTimes(0);
});

test('after-script-default <test-job>', async () => {
await defaultCmd.handler({
cwd: 'src/tests/test-cases/after-script-default',
job: 'test-job'
});
expect(mockProcessStdout).toHaveBeenCalledWith("Cleanup after test\n");
expect(mockProcessStderr).toBeCalledTimes(0);
expect(mockProcessExit).toBeCalledTimes(0);
});

test('artifacts <test-root-file>', async () => {
await defaultCmd.handler({
cwd: 'src/tests/test-cases/artifacts',
Expand Down
2 changes: 2 additions & 0 deletions src/tests/test-cases/after-script-default/.gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[remote "origin"]
url = [email protected]/gcl/test-case.git
8 changes: 8 additions & 0 deletions src/tests/test-cases/after-script-default/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
default:
after_script:
- echo "Cleanup after test"

test-job:
script:
- echo "Test something"
2 changes: 2 additions & 0 deletions src/tests/test-cases/before-script-default/.gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[remote "origin"]
url = [email protected]/gcl/test-case.git
8 changes: 8 additions & 0 deletions src/tests/test-cases/before-script-default/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
default:
before_script:
- echo "Before test"

test-job:
script:
- echo "Test something"

0 comments on commit c6cc35d

Please sign in to comment.