mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-08-31 15:42:51 +08:00
chore: use esbuild builder
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
parent
c2afb80acd
commit
9f1a5b87e1
24
.devcontainer/devcontainer-lock.json
Normal file
24
.devcontainer/devcontainer-lock.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/common-utils:2": {
|
||||
"version": "2.5.9",
|
||||
"resolved": "ghcr.io/devcontainers/features/common-utils@sha256:cb0c4d3c276f157eed17935747e364178d75fee17f55c4e129966f64633deb3a",
|
||||
"integrity": "sha256:cb0c4d3c276f157eed17935747e364178d75fee17f55c4e129966f64633deb3a"
|
||||
},
|
||||
"ghcr.io/devcontainers/features/docker-in-docker:4": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:4fa87399214366e320d489991769c4f3f461e1ffe461f54eea78a41b34945bb5",
|
||||
"integrity": "sha256:4fa87399214366e320d489991769c4f3f461e1ffe461f54eea78a41b34945bb5"
|
||||
},
|
||||
"ghcr.io/devcontainers/features/github-cli:1": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671",
|
||||
"integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671"
|
||||
},
|
||||
"ghcr.io/devcontainers/features/node:2": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "ghcr.io/devcontainers/features/node@sha256:586c9a6f7dd40bd3ba2cd41e7f2f88dcc31fbe5d1442afcbf07ffbc66b686857",
|
||||
"integrity": "sha256:586c9a6f7dd40bd3ba2cd41e7f2f88dcc31fbe5d1442afcbf07ffbc66b686857"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,30 +1,32 @@
|
||||
{
|
||||
"name": "Debian",
|
||||
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/node:2": {},
|
||||
"ghcr.io/devcontainers/features/docker-in-docker:": {},
|
||||
"ghcr.io/devcontainers/features/github-cli:1": {}
|
||||
},
|
||||
"remoteEnv": {
|
||||
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"eamodio.gitlens",
|
||||
"github.copilot",
|
||||
"github.copilot-chat",
|
||||
"github.vscode-github-actions",
|
||||
"ms-vscode.makefile-tools",
|
||||
"bierner.markdown-preview-github-styles",
|
||||
"esbenp.prettier-vscode",
|
||||
"biomejs.biome",
|
||||
"vitest.explorer"
|
||||
],
|
||||
"settings": {
|
||||
"terminal.integrated.defaultProfile.linux": "zsh"
|
||||
}
|
||||
}
|
||||
}
|
||||
"name": "Debian",
|
||||
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/common-utils:2": {
|
||||
"configureZshAsDefaultShell": true
|
||||
},
|
||||
"ghcr.io/devcontainers/features/node:2": {},
|
||||
"ghcr.io/devcontainers/features/docker-in-docker:4": {
|
||||
"moby": false
|
||||
},
|
||||
"ghcr.io/devcontainers/features/github-cli:1": {}
|
||||
},
|
||||
"remoteEnv": {
|
||||
"GITHUB_TOKEN": "${localEnv:GITHUB_TOKEN}"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"eamodio.gitlens",
|
||||
"github.copilot",
|
||||
"github.copilot-chat",
|
||||
"github.vscode-github-actions",
|
||||
"ms-vscode.makefile-tools",
|
||||
"bierner.markdown-preview-github-styles",
|
||||
"esbenp.prettier-vscode",
|
||||
"biomejs.biome",
|
||||
"vitest.explorer"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
.github/linters/.jscpd.json
vendored
2
.github/linters/.jscpd.json
vendored
@ -1,3 +1,3 @@
|
||||
{
|
||||
"ignore": ["**/dist/**", "**/node_modules/**", "**/coverage/**"]
|
||||
"ignore": ["**/dist/**", "**/node_modules/**", "**/coverage/**"]
|
||||
}
|
||||
|
||||
30
.github/release-config.yml
vendored
30
.github/release-config.yml
vendored
@ -1,30 +0,0 @@
|
||||
---
|
||||
template: |
|
||||
# What's Changed
|
||||
$CHANGES
|
||||
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION
|
||||
name-template: "Version $RESOLVED_VERSION"
|
||||
tag-template: "$RESOLVED_VERSION"
|
||||
tag-prefix: ""
|
||||
prerelease-identifier: "rc"
|
||||
version-resolver:
|
||||
major:
|
||||
labels:
|
||||
- "release-major"
|
||||
minor:
|
||||
labels:
|
||||
- "release-minor"
|
||||
patch:
|
||||
labels:
|
||||
- "release-patch"
|
||||
default: patch
|
||||
autolabeler:
|
||||
- label: "release-major"
|
||||
title:
|
||||
- "/^BREAKING CHANGE:/"
|
||||
- "/^\\w+!:/"
|
||||
- "/^\\w+\\(.+\\)!:/"
|
||||
- label: "release-minor"
|
||||
title:
|
||||
- "/^feat:/"
|
||||
- "/^feat\\(.+\\):/"
|
||||
2
.github/workflows/main-ci.yml
vendored
2
.github/workflows/main-ci.yml
vendored
@ -66,6 +66,8 @@ jobs:
|
||||
with:
|
||||
client-id: ${{ vars.CI_BOT_APP_CLIENT_ID }}
|
||||
private-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }} # zizmor: ignore[secrets-outside-env] repository automation uses a dedicated app secret without untrusted code execution
|
||||
permission-contents: write
|
||||
permission-pull-requests: write
|
||||
|
||||
- uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@2334d395217f9811699dbd4ace9d8559e4d99e0d # 0.37.3
|
||||
with:
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
FROM ghcr.io/hoverkraft-tech/docker-base-images/super-linter:0.6.0
|
||||
FROM ghcr.io/hoverkraft-tech/docker-base-images/super-linter:0.4.1
|
||||
HEALTHCHECK --interval=5m --timeout=10s --start-period=30s --retries=3 CMD ["/bin/sh","-c","test -d /github/home"]
|
||||
ARG UID=1000
|
||||
ARG GID=1000
|
||||
|
||||
69
biome.json
69
biome.json
@ -1,34 +1,39 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.16/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
"useIgnoreFile": true
|
||||
},
|
||||
"files": {
|
||||
"includes": ["**", "!!**/dist"]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"indentStyle": "tab"
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "double"
|
||||
}
|
||||
},
|
||||
"assist": {
|
||||
"enabled": true,
|
||||
"actions": {
|
||||
"source": {
|
||||
"organizeImports": "on"
|
||||
}
|
||||
}
|
||||
}
|
||||
"$schema": "https://biomejs.dev/schemas/2.4.16/schema.json",
|
||||
"vcs": {
|
||||
"enabled": true,
|
||||
"clientKind": "git",
|
||||
"useIgnoreFile": true
|
||||
},
|
||||
"files": {
|
||||
"includes": [
|
||||
"**",
|
||||
"!!**/dist",
|
||||
"!!.github/logo.svg",
|
||||
"!!.github/social-preview.svg"
|
||||
]
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"indentStyle": "space"
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "double"
|
||||
}
|
||||
},
|
||||
"assist": {
|
||||
"enabled": true,
|
||||
"actions": {
|
||||
"source": {
|
||||
"organizeImports": "on"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
76801
dist/index.js
generated
vendored
76801
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
634
dist/licenses.txt
generated
vendored
634
dist/licenses.txt
generated
vendored
@ -1,634 +0,0 @@
|
||||
@actions/core
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/exec
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/github
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/http-client
|
||||
MIT
|
||||
Actions Http Client for Node.js
|
||||
|
||||
Copyright (c) GitHub, Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@actions/io
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/tool-cache
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@octokit/auth-token
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/core
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/endpoint
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/graphql
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/plugin-paginate-rest
|
||||
MIT
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/plugin-rest-endpoint-methods
|
||||
MIT
|
||||
MIT License Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/request
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2018 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
@octokit/request-error
|
||||
MIT
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
before-after-hook
|
||||
Apache-2.0
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2018 Gregor Martynus and other contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
docker-compose
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 - 2021 PDMLab
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
fast-content-type-parse
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 The Fastify Team
|
||||
|
||||
The Fastify team members are listed at https://github.com/fastify/fastify#team
|
||||
and in the README file.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
json-with-bigint
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Ivan Korolenko
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
semver
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
tunnel
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Koichi Kobayashi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
undici
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) Matteo Collina and Undici contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
universal-user-agent
|
||||
ISC
|
||||
# [ISC License](https://spdx.org/licenses/ISC)
|
||||
|
||||
Copyright (c) 2018-2021, Gregor Martynus (https://github.com/gr2m)
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
yaml
|
||||
ISC
|
||||
Copyright Eemeli Aro <eemeli@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose
|
||||
with or without fee is hereby granted, provided that the above copyright notice
|
||||
and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
3
dist/package.json
generated
vendored
3
dist/package.json
generated
vendored
@ -1,3 +0,0 @@
|
||||
{
|
||||
"type": "module"
|
||||
}
|
||||
66603
dist/post.js
generated
vendored
66603
dist/post.js
generated
vendored
File diff suppressed because one or more lines are too long
6836
package-lock.json
generated
6836
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
126
package.json
126
package.json
@ -1,64 +1,66 @@
|
||||
{
|
||||
"name": "compose-action",
|
||||
"description": "Docker Compose Action",
|
||||
"version": "0.0.0",
|
||||
"author": "hoverkraft",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/hoverkraft-tech/compose-action",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hoverkraft-tech/compose-action.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/hoverkraft-tech/compose-action/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"docker-compose"
|
||||
],
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/github": "^9.1.1",
|
||||
"@actions/tool-cache": "^4.0.0",
|
||||
"@octokit/action": "^8.0.4",
|
||||
"docker-compose": "^1.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ts-dev-tools/core": "^1.12.4",
|
||||
"@vercel/ncc": "^0.44.0"
|
||||
},
|
||||
"scripts": {
|
||||
"package": "npm run package:index && npm run package:post",
|
||||
"package:index": "ncc build src/index.ts -o dist --license licenses.txt",
|
||||
"package:post": "ncc build src/post.ts -o dist/post && mv dist/post/index.js dist/post.js && rm -rf dist/post",
|
||||
"package:watch": "npm run package -- --watch",
|
||||
"lint": "biome lint --error-on-warnings .",
|
||||
"lint:ci": "biome lint --error-on-warnings . --reporter=sarif | tee biome-report.sarif",
|
||||
"all": "npm run format && npm run lint:ci && npm run test:ci && npm run package",
|
||||
"build": "tsc --noEmit",
|
||||
"format": "biome format --write .",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"test:cov": "vitest run --reporter=default --reporter=junit --outputFile=junit.xml --coverage.enabled --coverage.reporter=lcov --coverage.reporter=text",
|
||||
"test:ci": "npm run test:cov",
|
||||
"prepare": "ts-dev-tools install",
|
||||
"check": "biome check --error-on-warnings --write .",
|
||||
"vitest": "vitest"
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"tsDevTools": {
|
||||
"version": "20260604100000-migrate-to-vitest"
|
||||
}
|
||||
"name": "compose-action",
|
||||
"description": "Docker Compose Action",
|
||||
"version": "0.0.0",
|
||||
"author": "hoverkraft",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/hoverkraft-tech/compose-action",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hoverkraft-tech/compose-action.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/hoverkraft-tech/compose-action/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"docker-compose"
|
||||
],
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=24"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^3.0.1",
|
||||
"@actions/github": "^9.1.1",
|
||||
"@actions/tool-cache": "^4.0.0",
|
||||
"@octokit/action": "^8.0.4",
|
||||
"docker-compose": "^1.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ts-dev-tools/core": "^1.13.1",
|
||||
"esbuild": "^0.27.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepackage": "rm -rf dist",
|
||||
"package": "esbuild src/index.ts src/post.ts --bundle --format=esm --platform=node --target=node24 --outdir=dist --entry-names=[name] --banner:js='import { createRequire } from \"node:module\";const require = createRequire(import.meta.url);'",
|
||||
"package:watch": "npm run package -- --watch",
|
||||
"lint": "biome lint --error-on-warnings .",
|
||||
"lint:ci": "biome lint --error-on-warnings . --reporter=sarif | tee biome-report.sarif",
|
||||
"all": "npm run format && npm run lint:ci && npm run test:ci && npm run package",
|
||||
"build": "tsc --noEmit",
|
||||
"format": "biome format --write .",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"test:cov": "vitest run --reporter=default --reporter=junit --outputFile=junit.xml --coverage.enabled --coverage.reporter=lcov --coverage.reporter=text",
|
||||
"test:ci": "npm run test:cov",
|
||||
"prepare": "ts-dev-tools install",
|
||||
"check": "biome check --error-on-warnings --write .",
|
||||
"vitest": "vitest"
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"tsDevTools": {
|
||||
"version": "20260604100000-migrate-to-vitest"
|
||||
},
|
||||
"allowScripts": {
|
||||
"esbuild@0.27.7": true
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,204 +1,204 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock @actions/core
|
||||
const setFailedMock = vi.fn();
|
||||
|
||||
vi.doMock("@actions/core", () => ({
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock docker-compose
|
||||
vi.doMock("docker-compose", () => ({
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
down: vi.fn(),
|
||||
logs: vi.fn(),
|
||||
version: vi
|
||||
.fn<() => Promise<{ data: { version: string } }>>()
|
||||
.mockResolvedValue({ data: { version: "1.2.3" } }),
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
down: vi.fn(),
|
||||
logs: vi.fn(),
|
||||
version: vi
|
||||
.fn<() => Promise<{ data: { version: string } }>>()
|
||||
.mockResolvedValue({ data: { version: "1.2.3" } }),
|
||||
}));
|
||||
|
||||
// Mock node:fs
|
||||
vi.doMock("node:fs", async () => {
|
||||
const actualFs = await vi.importActual<typeof import("node:fs")>("node:fs");
|
||||
const actualFs = await vi.importActual<typeof import("node:fs")>("node:fs");
|
||||
|
||||
return {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
},
|
||||
};
|
||||
return {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// Dynamic imports after mock setup
|
||||
const { run } = await import("./index-runner.js");
|
||||
const { InputService } = await import("./services/input.service.js");
|
||||
const { LoggerService, LogLevel } = await import(
|
||||
"./services/logger.service.js"
|
||||
"./services/logger.service.js"
|
||||
);
|
||||
const { DockerComposeInstallerService } = await import(
|
||||
"./services/docker-compose-installer.service.js"
|
||||
"./services/docker-compose-installer.service.js"
|
||||
);
|
||||
const { DockerComposeService } = await import(
|
||||
"./services/docker-compose.service.js"
|
||||
"./services/docker-compose.service.js"
|
||||
);
|
||||
|
||||
describe("run", () => {
|
||||
let infoMock: ReturnType<typeof vi.spyOn>;
|
||||
let debugMock: ReturnType<typeof vi.spyOn>;
|
||||
let getInputsMock: ReturnType<typeof vi.spyOn>;
|
||||
let installMock: ReturnType<typeof vi.spyOn>;
|
||||
let upMock: ReturnType<typeof vi.spyOn>;
|
||||
let infoMock: ReturnType<typeof vi.spyOn>;
|
||||
let debugMock: ReturnType<typeof vi.spyOn>;
|
||||
let getInputsMock: ReturnType<typeof vi.spyOn>;
|
||||
let installMock: ReturnType<typeof vi.spyOn>;
|
||||
let upMock: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
installMock = vi.spyOn(DockerComposeInstallerService.prototype, "install");
|
||||
upMock = vi.spyOn(DockerComposeService.prototype, "up");
|
||||
});
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
installMock = vi.spyOn(DockerComposeInstallerService.prototype, "install");
|
||||
upMock = vi.spyOn(DockerComposeService.prototype, "up");
|
||||
});
|
||||
|
||||
it("should install docker compose with specified version", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: "1.29.2",
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
it("should install docker compose with specified version", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: "1.29.2",
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
installMock.mockResolvedValue("1.29.2");
|
||||
installMock.mockResolvedValue("1.29.2");
|
||||
|
||||
upMock.mockResolvedValue();
|
||||
upMock.mockResolvedValue();
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
"Setting up docker compose version 1.29.2",
|
||||
);
|
||||
// Assert
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
"Setting up docker compose version 1.29.2",
|
||||
);
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null,"serviceLogLevel":"debug"}',
|
||||
);
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null,"serviceLogLevel":"debug"}',
|
||||
);
|
||||
|
||||
expect(installMock).toHaveBeenCalledWith({
|
||||
composeVersion: "1.29.2",
|
||||
cwd: "/current/working/dir",
|
||||
githubToken: null,
|
||||
});
|
||||
expect(installMock).toHaveBeenCalledWith({
|
||||
composeVersion: "1.29.2",
|
||||
cwd: "/current/working/dir",
|
||||
githubToken: null,
|
||||
});
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should bring up docker compose services", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
it("should bring up docker compose services", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: ["web"],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
// Assert
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: ["web"],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should handle errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Test error");
|
||||
upMock.mockRejectedValue(error);
|
||||
it("should handle errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Test error");
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: Test error");
|
||||
});
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: Test error");
|
||||
});
|
||||
|
||||
it("should handle unknown errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = "Test error";
|
||||
upMock.mockRejectedValue(error);
|
||||
it("should handle unknown errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = "Test error";
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith('"Test error"');
|
||||
});
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith('"Test error"');
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,51 +1,51 @@
|
||||
import { setFailed } from "@actions/core";
|
||||
import { InputService } from "./services/input.service.js";
|
||||
import { LoggerService } from "./services/logger.service.js";
|
||||
import { DockerComposeService } from "./services/docker-compose.service.js";
|
||||
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service.js";
|
||||
import { InputService } from "./services/input.service.js";
|
||||
import { ManualInstallerAdapter } from "./services/installer-adapter/manual-installer-adapter.js";
|
||||
import { LoggerService } from "./services/logger.service.js";
|
||||
|
||||
/**
|
||||
* The run function for the action.
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const loggerService = new LoggerService();
|
||||
const inputService = new InputService();
|
||||
const dockerComposeInstallerService = new DockerComposeInstallerService(
|
||||
new ManualInstallerAdapter(),
|
||||
);
|
||||
const dockerComposeService = new DockerComposeService();
|
||||
try {
|
||||
const loggerService = new LoggerService();
|
||||
const inputService = new InputService();
|
||||
const dockerComposeInstallerService = new DockerComposeInstallerService(
|
||||
new ManualInstallerAdapter(),
|
||||
);
|
||||
const dockerComposeService = new DockerComposeService();
|
||||
|
||||
const inputs = inputService.getInputs();
|
||||
loggerService.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||
const inputs = inputService.getInputs();
|
||||
loggerService.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||
|
||||
loggerService.info(
|
||||
"Setting up docker compose" +
|
||||
(inputs.composeVersion ? ` version ${inputs.composeVersion}` : ""),
|
||||
);
|
||||
loggerService.info(
|
||||
"Setting up docker compose" +
|
||||
(inputs.composeVersion ? ` version ${inputs.composeVersion}` : ""),
|
||||
);
|
||||
|
||||
const installedVersion = await dockerComposeInstallerService.install({
|
||||
composeVersion: inputs.composeVersion,
|
||||
cwd: inputs.cwd,
|
||||
githubToken: inputs.githubToken,
|
||||
});
|
||||
const installedVersion = await dockerComposeInstallerService.install({
|
||||
composeVersion: inputs.composeVersion,
|
||||
cwd: inputs.cwd,
|
||||
githubToken: inputs.githubToken,
|
||||
});
|
||||
|
||||
loggerService.info(`docker compose version: ${installedVersion}`);
|
||||
loggerService.info(`docker compose version: ${installedVersion}`);
|
||||
|
||||
loggerService.info("Bringing up docker compose service(s)");
|
||||
await dockerComposeService.up({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
loggerService.info("Bringing up docker compose service(s)");
|
||||
await dockerComposeService.up({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,52 +1,52 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock @actions/core
|
||||
const setFailedMock = vi.fn();
|
||||
|
||||
vi.doMock("@actions/core", () => ({
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock docker-compose
|
||||
vi.doMock("docker-compose", () => ({
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
down: vi.fn(),
|
||||
logs: vi.fn(),
|
||||
version: vi
|
||||
.fn<() => Promise<{ data: { version: string } }>>()
|
||||
.mockResolvedValue({ data: { version: "1.2.3" } }),
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
down: vi.fn(),
|
||||
logs: vi.fn(),
|
||||
version: vi
|
||||
.fn<() => Promise<{ data: { version: string } }>>()
|
||||
.mockResolvedValue({ data: { version: "1.2.3" } }),
|
||||
}));
|
||||
|
||||
// Mock node:fs
|
||||
vi.doMock("node:fs", async () => {
|
||||
const actualFs = await vi.importActual<typeof import("node:fs")>("node:fs");
|
||||
const actualFs = await vi.importActual<typeof import("node:fs")>("node:fs");
|
||||
|
||||
return {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
},
|
||||
};
|
||||
return {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: {
|
||||
...actualFs,
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// Dynamic imports after mock setup
|
||||
const { InputService } = await import("./services/input.service.js");
|
||||
const { LoggerService, LogLevel } = await import(
|
||||
"./services/logger.service.js"
|
||||
"./services/logger.service.js"
|
||||
);
|
||||
const { DockerComposeInstallerService } = await import(
|
||||
"./services/docker-compose-installer.service.js"
|
||||
"./services/docker-compose-installer.service.js"
|
||||
);
|
||||
const { DockerComposeService } = await import(
|
||||
"./services/docker-compose.service.js"
|
||||
"./services/docker-compose.service.js"
|
||||
);
|
||||
|
||||
let getInputsMock: ReturnType<typeof vi.spyOn>;
|
||||
@ -56,72 +56,72 @@ let installMock: ReturnType<typeof vi.spyOn>;
|
||||
let upMock: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
describe("index", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
installMock = vi.spyOn(DockerComposeInstallerService.prototype, "install");
|
||||
upMock = vi.spyOn(DockerComposeService.prototype, "up");
|
||||
});
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
installMock = vi.spyOn(DockerComposeInstallerService.prototype, "install");
|
||||
upMock = vi.spyOn(DockerComposeService.prototype, "up");
|
||||
});
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
installMock.mockResolvedValue("1.2.3");
|
||||
upMock.mockResolvedValueOnce();
|
||||
installMock.mockResolvedValue("1.2.3");
|
||||
upMock.mockResolvedValueOnce();
|
||||
|
||||
await import("./index.js");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await import("./index.js");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(1, "Setting up docker compose");
|
||||
expect(infoMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"docker compose version: 1.2.3",
|
||||
);
|
||||
expect(infoMock).toHaveBeenNthCalledWith(1, "Setting up docker compose");
|
||||
expect(infoMock).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"docker compose version: 1.2.3",
|
||||
);
|
||||
|
||||
// Verify that all of the functions were called correctly
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null,"serviceLogLevel":"debug"}',
|
||||
);
|
||||
// Verify that all of the functions were called correctly
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'inputs: {"dockerFlags":[],"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null,"serviceLogLevel":"debug"}',
|
||||
);
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
"Bringing up docker compose service(s)",
|
||||
);
|
||||
expect(infoMock).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
"Bringing up docker compose service(s)",
|
||||
);
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(
|
||||
4,
|
||||
"docker compose service(s) are up",
|
||||
);
|
||||
});
|
||||
expect(infoMock).toHaveBeenNthCalledWith(
|
||||
4,
|
||||
"docker compose service(s) are up",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock @actions/core
|
||||
const setFailedMock = vi.fn();
|
||||
|
||||
vi.doMock("@actions/core", () => ({
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock docker-compose
|
||||
@ -17,189 +17,189 @@ const logsMock = vi.fn();
|
||||
const downMock = vi.fn();
|
||||
|
||||
vi.doMock("docker-compose", () => ({
|
||||
logs: logsMock,
|
||||
down: downMock,
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
logs: logsMock,
|
||||
down: downMock,
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock node:fs
|
||||
vi.doMock("node:fs", () => ({
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: { existsSync: vi.fn().mockReturnValue(true) },
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: { existsSync: vi.fn().mockReturnValue(true) },
|
||||
}));
|
||||
|
||||
// Dynamic imports after mock setup
|
||||
const { run } = await import("./post-runner.js");
|
||||
const { InputService } = await import("./services/input.service.js");
|
||||
const { LoggerService, LogLevel } = await import(
|
||||
"./services/logger.service.js"
|
||||
"./services/logger.service.js"
|
||||
);
|
||||
const { DockerComposeService } = await import(
|
||||
"./services/docker-compose.service.js"
|
||||
"./services/docker-compose.service.js"
|
||||
);
|
||||
|
||||
describe("run", () => {
|
||||
let infoMock: ReturnType<typeof vi.spyOn>;
|
||||
let debugMock: ReturnType<typeof vi.spyOn>;
|
||||
let getInputsMock: ReturnType<typeof vi.spyOn>;
|
||||
let serviceDownMock: ReturnType<typeof vi.spyOn>;
|
||||
let serviceLogsMock: ReturnType<typeof vi.spyOn>;
|
||||
let infoMock: ReturnType<typeof vi.spyOn>;
|
||||
let debugMock: ReturnType<typeof vi.spyOn>;
|
||||
let getInputsMock: ReturnType<typeof vi.spyOn>;
|
||||
let serviceDownMock: ReturnType<typeof vi.spyOn>;
|
||||
let serviceLogsMock: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
serviceDownMock = vi.spyOn(DockerComposeService.prototype, "down");
|
||||
serviceLogsMock = vi.spyOn(DockerComposeService.prototype, "logs");
|
||||
});
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
serviceDownMock = vi.spyOn(DockerComposeService.prototype, "down");
|
||||
serviceLogsMock = vi.spyOn(DockerComposeService.prototype, "logs");
|
||||
});
|
||||
|
||||
it("should bring down docker compose service(s) and log output", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
it("should bring down docker compose service(s) and log output", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
serviceLogsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||
serviceDownMock.mockResolvedValue();
|
||||
serviceLogsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||
serviceDownMock.mockResolvedValue();
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(serviceLogsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
// Assert
|
||||
expect(serviceLogsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
|
||||
expect(serviceDownMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(serviceDownMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
|
||||
expect(infoMock).toHaveBeenCalledWith("docker compose is down");
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(debugMock).toHaveBeenCalledWith("docker compose logs:\ntest logs");
|
||||
expect(infoMock).toHaveBeenCalledWith("docker compose is down");
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should log docker composer errors if any", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
it("should log docker composer errors if any", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
serviceLogsMock.mockResolvedValue({
|
||||
error: "test logs error",
|
||||
output: "test logs output",
|
||||
});
|
||||
serviceLogsMock.mockResolvedValue({
|
||||
error: "test logs error",
|
||||
output: "test logs output",
|
||||
});
|
||||
|
||||
serviceDownMock.mockResolvedValue();
|
||||
serviceDownMock.mockResolvedValue();
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
"docker compose error:\ntest logs error",
|
||||
);
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
"docker compose logs:\ntest logs output",
|
||||
);
|
||||
expect(infoMock).toHaveBeenCalledWith("docker compose is down");
|
||||
});
|
||||
// Assert
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
"docker compose error:\ntest logs error",
|
||||
);
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
"docker compose logs:\ntest logs output",
|
||||
);
|
||||
expect(infoMock).toHaveBeenCalledWith("docker compose is down");
|
||||
});
|
||||
|
||||
it("should set failed when an error occurs", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => {
|
||||
throw new Error("An error occurred");
|
||||
});
|
||||
it("should set failed when an error occurs", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => {
|
||||
throw new Error("An error occurred");
|
||||
});
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: An error occurred");
|
||||
});
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: An error occurred");
|
||||
});
|
||||
|
||||
it("should handle errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Test error");
|
||||
serviceDownMock.mockRejectedValue(error);
|
||||
it("should handle errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Test error");
|
||||
serviceDownMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: Test error");
|
||||
});
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: Test error");
|
||||
});
|
||||
|
||||
it("should handle unknown errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = "Test error";
|
||||
serviceDownMock.mockRejectedValue(error);
|
||||
it("should handle unknown errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = "Test error";
|
||||
serviceDownMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await run();
|
||||
// Act
|
||||
await run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith('"Test error"');
|
||||
});
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith('"Test error"');
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,46 +1,46 @@
|
||||
import { setFailed } from "@actions/core";
|
||||
import { DockerComposeService } from "./services/docker-compose.service.js";
|
||||
import { InputService } from "./services/input.service.js";
|
||||
import { LoggerService } from "./services/logger.service.js";
|
||||
import { DockerComposeService } from "./services/docker-compose.service.js";
|
||||
|
||||
/**
|
||||
* The run function for the action.
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const loggerService = new LoggerService();
|
||||
const inputService = new InputService();
|
||||
const dockerComposeService = new DockerComposeService();
|
||||
try {
|
||||
const loggerService = new LoggerService();
|
||||
const inputService = new InputService();
|
||||
const dockerComposeService = new DockerComposeService();
|
||||
|
||||
const inputs = inputService.getInputs();
|
||||
const inputs = inputService.getInputs();
|
||||
|
||||
const { error, output } = await dockerComposeService.logs({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
services: inputs.services,
|
||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
||||
});
|
||||
const { error, output } = await dockerComposeService.logs({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
services: inputs.services,
|
||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
||||
});
|
||||
|
||||
if (error) {
|
||||
loggerService.debug("docker compose error:\n" + error);
|
||||
}
|
||||
if (error) {
|
||||
loggerService.debug(`docker compose error:\n${error}`);
|
||||
}
|
||||
|
||||
loggerService.debug("docker compose logs:\n" + output);
|
||||
loggerService.debug(`docker compose logs:\n${output}`);
|
||||
|
||||
await dockerComposeService.down({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
||||
});
|
||||
await dockerComposeService.down({
|
||||
dockerFlags: inputs.dockerFlags,
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
serviceLogger: loggerService.getServiceLogger(inputs.serviceLogLevel),
|
||||
});
|
||||
|
||||
loggerService.info("docker compose is down");
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
loggerService.info("docker compose is down");
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
134
src/post.test.ts
134
src/post.test.ts
@ -1,15 +1,15 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock @actions/core
|
||||
const setFailedMock = vi.fn();
|
||||
|
||||
vi.doMock("@actions/core", () => ({
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
setFailed: setFailedMock,
|
||||
getInput: vi.fn().mockReturnValue(""),
|
||||
getMultilineInput: vi.fn().mockReturnValue([]),
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock docker-compose
|
||||
@ -17,25 +17,25 @@ const logsMock = vi.fn();
|
||||
const downMock = vi.fn();
|
||||
|
||||
vi.doMock("docker-compose", () => ({
|
||||
logs: logsMock,
|
||||
down: downMock,
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
logs: logsMock,
|
||||
down: downMock,
|
||||
upAll: vi.fn(),
|
||||
upMany: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock node:fs
|
||||
vi.doMock("node:fs", () => ({
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: { existsSync: vi.fn().mockReturnValue(true) },
|
||||
existsSync: vi.fn().mockReturnValue(true),
|
||||
default: { existsSync: vi.fn().mockReturnValue(true) },
|
||||
}));
|
||||
|
||||
// Dynamic imports after mock setup
|
||||
const { InputService } = await import("./services/input.service.js");
|
||||
const { LoggerService, LogLevel } = await import(
|
||||
"./services/logger.service.js"
|
||||
"./services/logger.service.js"
|
||||
);
|
||||
const { DockerComposeService } = await import(
|
||||
"./services/docker-compose.service.js"
|
||||
"./services/docker-compose.service.js"
|
||||
);
|
||||
|
||||
let getInputsMock: ReturnType<typeof vi.spyOn>;
|
||||
@ -45,64 +45,64 @@ let serviceLogsMock: ReturnType<typeof vi.spyOn>;
|
||||
let serviceDownMock: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
describe("post", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
serviceLogsMock = vi.spyOn(DockerComposeService.prototype, "logs");
|
||||
serviceDownMock = vi.spyOn(DockerComposeService.prototype, "down");
|
||||
});
|
||||
infoMock = vi
|
||||
.spyOn(LoggerService.prototype, "info")
|
||||
.mockImplementation(() => {});
|
||||
debugMock = vi
|
||||
.spyOn(LoggerService.prototype, "debug")
|
||||
.mockImplementation(() => {});
|
||||
getInputsMock = vi.spyOn(InputService.prototype, "getInputs");
|
||||
serviceLogsMock = vi.spyOn(DockerComposeService.prototype, "logs");
|
||||
serviceDownMock = vi.spyOn(DockerComposeService.prototype, "down");
|
||||
});
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
it("calls run when imported", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
serviceLogLevel: LogLevel.Debug,
|
||||
}));
|
||||
|
||||
serviceLogsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||
serviceDownMock.mockResolvedValueOnce();
|
||||
serviceLogsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||
serviceDownMock.mockResolvedValueOnce();
|
||||
|
||||
await import("./post.js");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await import("./post.js");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(serviceLogsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(serviceLogsMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
|
||||
expect(serviceDownMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
expect(serviceDownMock).toHaveBeenCalledWith({
|
||||
dockerFlags: [],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
serviceLogger: debugMock,
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
"docker compose logs:\ntest logs",
|
||||
);
|
||||
expect(infoMock).toHaveBeenNthCalledWith(1, "docker compose is down");
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
"docker compose logs:\ntest logs",
|
||||
);
|
||||
expect(infoMock).toHaveBeenNthCalledWith(1, "docker compose is down");
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,302 +1,302 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
||||
import type { IDockerComposeResult } from "docker-compose";
|
||||
import { MockAgent, setGlobalDispatcher } from "undici";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock docker-compose before importing the module under test
|
||||
const versionMock =
|
||||
vi.fn<() => Promise<IDockerComposeResult & { data: { version: string } }>>();
|
||||
vi.fn<() => Promise<IDockerComposeResult & { data: { version: string } }>>();
|
||||
|
||||
vi.doMock("docker-compose", () => ({
|
||||
version: versionMock,
|
||||
version: versionMock,
|
||||
}));
|
||||
|
||||
// Create manual installer adapter mock
|
||||
const manualInstallerAdapterMock = {
|
||||
install: vi.fn<(version: string) => Promise<void>>(),
|
||||
install: vi.fn<(version: string) => Promise<void>>(),
|
||||
};
|
||||
|
||||
// Dynamic import after mock setup
|
||||
const { DockerComposeInstallerService } = await import(
|
||||
"./docker-compose-installer.service.js"
|
||||
"./docker-compose-installer.service.js"
|
||||
);
|
||||
|
||||
describe("DockerComposeInstallerService", () => {
|
||||
let mockAgent: MockAgent;
|
||||
let service: InstanceType<typeof DockerComposeInstallerService>;
|
||||
let mockAgent: MockAgent;
|
||||
let service: InstanceType<typeof DockerComposeInstallerService>;
|
||||
|
||||
const composeVersionResponse = (version: string) => ({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version,
|
||||
},
|
||||
});
|
||||
const composeVersionResponse = (version: string) => ({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version,
|
||||
},
|
||||
});
|
||||
|
||||
const installCompose = (
|
||||
composeVersion: string | null,
|
||||
githubToken: string | null,
|
||||
) =>
|
||||
service.install({
|
||||
composeVersion,
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken,
|
||||
});
|
||||
const installCompose = (
|
||||
composeVersion: string | null,
|
||||
githubToken: string | null,
|
||||
) =>
|
||||
service.install({
|
||||
composeVersion,
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken,
|
||||
});
|
||||
|
||||
const setPlatform = (platform: NodeJS.Platform) => {
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: platform,
|
||||
});
|
||||
};
|
||||
const setPlatform = (platform: NodeJS.Platform) => {
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: platform,
|
||||
});
|
||||
};
|
||||
|
||||
const mockLatestRelease = (version: string) => {
|
||||
const mockClient = mockAgent.get("https://api.github.com");
|
||||
mockClient
|
||||
.intercept({
|
||||
path: "/repos/docker/compose/releases/latest",
|
||||
method: "GET",
|
||||
})
|
||||
.reply(
|
||||
200,
|
||||
{
|
||||
tag_name: version,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
setGlobalDispatcher(mockClient);
|
||||
Object.defineProperty(globalThis, "fetch", {
|
||||
value: vi.fn(),
|
||||
});
|
||||
};
|
||||
const mockLatestRelease = (version: string) => {
|
||||
const mockClient = mockAgent.get("https://api.github.com");
|
||||
mockClient
|
||||
.intercept({
|
||||
path: "/repos/docker/compose/releases/latest",
|
||||
method: "GET",
|
||||
})
|
||||
.reply(
|
||||
200,
|
||||
{
|
||||
tag_name: version,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
},
|
||||
);
|
||||
setGlobalDispatcher(mockClient);
|
||||
Object.defineProperty(globalThis, "fetch", {
|
||||
value: vi.fn(),
|
||||
});
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockAgent = new MockAgent();
|
||||
mockAgent.disableNetConnect();
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockAgent = new MockAgent();
|
||||
mockAgent.disableNetConnect();
|
||||
|
||||
service = new DockerComposeInstallerService(
|
||||
manualInstallerAdapterMock as never,
|
||||
);
|
||||
});
|
||||
service = new DockerComposeInstallerService(
|
||||
manualInstallerAdapterMock as never,
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
describe("install", () => {
|
||||
it("should install latest when compose version is not specified and Compose is missing", async () => {
|
||||
// Arrange: first call to version() fails (Compose missing)
|
||||
versionMock.mockRejectedValueOnce(new Error("version not installed"));
|
||||
describe("install", () => {
|
||||
it("should install latest when compose version is not specified and Compose is missing", async () => {
|
||||
// Arrange: first call to version() fails (Compose missing)
|
||||
versionMock.mockRejectedValueOnce(new Error("version not installed"));
|
||||
|
||||
const latestVersion = "v2.0.0";
|
||||
mockLatestRelease(latestVersion);
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse(latestVersion));
|
||||
setPlatform("linux");
|
||||
const latestVersion = "v2.0.0";
|
||||
mockLatestRelease(latestVersion);
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse(latestVersion));
|
||||
setPlatform("linux");
|
||||
|
||||
// Act
|
||||
const result = await installCompose(null, "token");
|
||||
// Act
|
||||
const result = await installCompose(null, "token");
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(latestVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
latestVersion,
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe(latestVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
latestVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it("should return current version when no version is provided", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue(composeVersionResponse("2.0.0"));
|
||||
it("should return current version when no version is provided", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue(composeVersionResponse("2.0.0"));
|
||||
|
||||
// Act
|
||||
const result = await installCompose(null, null);
|
||||
// Act
|
||||
const result = await installCompose(null, null);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe("2.0.0");
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe("2.0.0");
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not install anything when expected version is already installed", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue(composeVersionResponse("1.2.3"));
|
||||
it("should not install anything when expected version is already installed", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue(composeVersionResponse("1.2.3"));
|
||||
|
||||
// Act
|
||||
const result = await installCompose("v1.2.3", null);
|
||||
// Act
|
||||
const result = await installCompose("v1.2.3", null);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe("1.2.3");
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe("1.2.3");
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should install the requested version if it is not already installed", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
it("should install the requested version if it is not already installed", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
|
||||
const expectedVersion = "1.3.0";
|
||||
versionMock.mockResolvedValueOnce(
|
||||
composeVersionResponse(expectedVersion),
|
||||
);
|
||||
setPlatform("linux");
|
||||
const expectedVersion = "1.3.0";
|
||||
versionMock.mockResolvedValueOnce(
|
||||
composeVersionResponse(expectedVersion),
|
||||
);
|
||||
setPlatform("linux");
|
||||
|
||||
// Act
|
||||
const result = await installCompose(expectedVersion, null);
|
||||
// Act
|
||||
const result = await installCompose(expectedVersion, null);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expectedVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
expectedVersion,
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe(expectedVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
expectedVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it("should install the latest version if requested", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
it("should install the latest version if requested", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
|
||||
const latestVersion = "v1.4.0";
|
||||
mockLatestRelease(latestVersion);
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse(latestVersion));
|
||||
setPlatform("linux");
|
||||
const latestVersion = "v1.4.0";
|
||||
mockLatestRelease(latestVersion);
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse(latestVersion));
|
||||
setPlatform("linux");
|
||||
|
||||
// Act
|
||||
const result = await installCompose("latest", "token");
|
||||
// Act
|
||||
const result = await installCompose("latest", "token");
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(latestVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
latestVersion,
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe(latestVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
latestVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw an error if the latest version if requested and no Github token is provided", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
it("should throw an error if the latest version if requested and no Github token is provided", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
|
||||
// Act & Assert
|
||||
await expect(installCompose("latest", null)).rejects.toThrow(
|
||||
"GitHub token is required to install the latest version",
|
||||
);
|
||||
});
|
||||
// Act & Assert
|
||||
await expect(installCompose("latest", null)).rejects.toThrow(
|
||||
"GitHub token is required to install the latest version",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw an error on unsupported platforms", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
it("should throw an error on unsupported platforms", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
|
||||
const expectedVersion = "1.3.0";
|
||||
versionMock.mockResolvedValueOnce(
|
||||
composeVersionResponse(expectedVersion),
|
||||
);
|
||||
setPlatform("win32");
|
||||
const expectedVersion = "1.3.0";
|
||||
versionMock.mockResolvedValueOnce(
|
||||
composeVersionResponse(expectedVersion),
|
||||
);
|
||||
setPlatform("win32");
|
||||
|
||||
// Act & Assert
|
||||
await expect(installCompose(expectedVersion, null)).rejects.toThrow(
|
||||
`Unsupported platform: win32`,
|
||||
);
|
||||
// Act & Assert
|
||||
await expect(installCompose(expectedVersion, null)).rejects.toThrow(
|
||||
`Unsupported platform: win32`,
|
||||
);
|
||||
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should install when version check fails", async () => {
|
||||
// Arrange: first call to version() doesn't find
|
||||
versionMock.mockRejectedValueOnce(new Error("version not installed"));
|
||||
it("should install when version check fails", async () => {
|
||||
// Arrange: first call to version() doesn't find
|
||||
versionMock.mockRejectedValueOnce(new Error("version not installed"));
|
||||
|
||||
const installedVersion = "2.0.0";
|
||||
const installedVersion = "2.0.0";
|
||||
|
||||
// After installation, version() returns the new version
|
||||
versionMock.mockResolvedValueOnce(
|
||||
composeVersionResponse(installedVersion),
|
||||
);
|
||||
setPlatform("linux");
|
||||
// After installation, version() returns the new version
|
||||
versionMock.mockResolvedValueOnce(
|
||||
composeVersionResponse(installedVersion),
|
||||
);
|
||||
setPlatform("linux");
|
||||
|
||||
// Act
|
||||
const result = await installCompose(installedVersion, "token");
|
||||
// Act
|
||||
const result = await installCompose(installedVersion, "token");
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(installedVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
installedVersion,
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe(installedVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
installedVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it("should install latest version when missing or unspecified", async () => {
|
||||
// Arrange: first call to version() doesn't find
|
||||
versionMock.mockRejectedValueOnce(new Error("version check failed"));
|
||||
// second call finds newly installed version
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("v1.4.0"));
|
||||
it("should install latest version when missing or unspecified", async () => {
|
||||
// Arrange: first call to version() doesn't find
|
||||
versionMock.mockRejectedValueOnce(new Error("version check failed"));
|
||||
// second call finds newly installed version
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("v1.4.0"));
|
||||
|
||||
const latestVersion = "v1.4.0";
|
||||
mockLatestRelease(latestVersion);
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse(latestVersion));
|
||||
setPlatform("linux");
|
||||
const latestVersion = "v1.4.0";
|
||||
mockLatestRelease(latestVersion);
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse(latestVersion));
|
||||
setPlatform("linux");
|
||||
|
||||
// Act
|
||||
const result = await installCompose("latest", "token");
|
||||
// Act
|
||||
const result = await installCompose("latest", "token");
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(latestVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
latestVersion,
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe(latestVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
latestVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw if Compose is missing and no GitHub token is provided", async () => {
|
||||
// Arrange: first call to version() doesn't find
|
||||
versionMock.mockRejectedValueOnce(new Error("version check failed"));
|
||||
setPlatform("linux");
|
||||
it("should throw if Compose is missing and no GitHub token is provided", async () => {
|
||||
// Arrange: first call to version() doesn't find
|
||||
versionMock.mockRejectedValueOnce(new Error("version check failed"));
|
||||
setPlatform("linux");
|
||||
|
||||
await expect(installCompose("latest", null)).rejects.toThrow(
|
||||
"GitHub token is required to install the latest version",
|
||||
);
|
||||
});
|
||||
await expect(installCompose("latest", null)).rejects.toThrow(
|
||||
"GitHub token is required to install the latest version",
|
||||
);
|
||||
});
|
||||
|
||||
it("should not install when the version is already installed and no version is specified", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue(composeVersionResponse("1.2.3"));
|
||||
it("should not install when the version is already installed and no version is specified", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue(composeVersionResponse("1.2.3"));
|
||||
|
||||
// Act
|
||||
const result = await installCompose("", null);
|
||||
// Act
|
||||
const result = await installCompose("", null);
|
||||
|
||||
// Assert
|
||||
expect(result).toBe("1.2.3");
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
// Assert
|
||||
expect(result).toBe("1.2.3");
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw when installed version does not match target", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
it("should throw when installed version does not match target", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
|
||||
const targetVersion = "v1.4.0";
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.3.0"));
|
||||
setPlatform("linux");
|
||||
const targetVersion = "v1.4.0";
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.3.0"));
|
||||
setPlatform("linux");
|
||||
|
||||
// Act & Assert
|
||||
await expect(installCompose(targetVersion, "token")).rejects.toThrow(
|
||||
`Failed to install Docker Compose version "${targetVersion}", installed version is "1.3.0"`,
|
||||
);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
targetVersion,
|
||||
);
|
||||
});
|
||||
// Act & Assert
|
||||
await expect(installCompose(targetVersion, "token")).rejects.toThrow(
|
||||
`Failed to install Docker Compose version "${targetVersion}", installed version is "1.3.0"`,
|
||||
);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
targetVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw with unknown installed version when post-install version check fails", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
it("should throw with unknown installed version when post-install version check fails", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce(composeVersionResponse("1.2.3"));
|
||||
|
||||
const targetVersion = "v1.4.0";
|
||||
versionMock.mockRejectedValueOnce(
|
||||
new Error("version check failed after install"),
|
||||
);
|
||||
setPlatform("linux");
|
||||
const targetVersion = "v1.4.0";
|
||||
versionMock.mockRejectedValueOnce(
|
||||
new Error("version check failed after install"),
|
||||
);
|
||||
setPlatform("linux");
|
||||
|
||||
// Act & Assert
|
||||
await expect(installCompose(targetVersion, "token")).rejects.toThrow(
|
||||
`Failed to install Docker Compose version "${targetVersion}", installed version is "unknown"`,
|
||||
);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
targetVersion,
|
||||
);
|
||||
});
|
||||
});
|
||||
// Act & Assert
|
||||
await expect(installCompose(targetVersion, "token")).rejects.toThrow(
|
||||
`Failed to install Docker Compose version "${targetVersion}", installed version is "unknown"`,
|
||||
);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(
|
||||
targetVersion,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -4,105 +4,105 @@ import { COMPOSE_VERSION_LATEST, type Inputs } from "./input.service.js";
|
||||
import type { ManualInstallerAdapter } from "./installer-adapter/manual-installer-adapter.js";
|
||||
|
||||
export type InstallInputs = {
|
||||
composeVersion: Inputs["composeVersion"];
|
||||
cwd: Inputs["cwd"];
|
||||
githubToken: Inputs["githubToken"];
|
||||
composeVersion: Inputs["composeVersion"];
|
||||
cwd: Inputs["cwd"];
|
||||
githubToken: Inputs["githubToken"];
|
||||
};
|
||||
|
||||
export type VersionInputs = {
|
||||
cwd: Inputs["cwd"];
|
||||
cwd: Inputs["cwd"];
|
||||
};
|
||||
|
||||
export class DockerComposeInstallerService {
|
||||
constructor(
|
||||
private readonly manualInstallerAdapter: ManualInstallerAdapter,
|
||||
) {}
|
||||
constructor(
|
||||
private readonly manualInstallerAdapter: ManualInstallerAdapter,
|
||||
) {}
|
||||
|
||||
async install({
|
||||
composeVersion,
|
||||
cwd,
|
||||
githubToken,
|
||||
}: InstallInputs): Promise<string> {
|
||||
const currentVersion = await this.version({ cwd });
|
||||
async install({
|
||||
composeVersion,
|
||||
cwd,
|
||||
githubToken,
|
||||
}: InstallInputs): Promise<string> {
|
||||
const currentVersion = await this.version({ cwd });
|
||||
|
||||
const normalizedCurrentVersion = currentVersion
|
||||
? this.normalizeVersion(currentVersion)
|
||||
: null;
|
||||
const normalizedRequestedVersion = composeVersion
|
||||
? this.normalizeVersion(composeVersion)
|
||||
: null;
|
||||
const normalizedCurrentVersion = currentVersion
|
||||
? this.normalizeVersion(currentVersion)
|
||||
: null;
|
||||
const normalizedRequestedVersion = composeVersion
|
||||
? this.normalizeVersion(composeVersion)
|
||||
: null;
|
||||
|
||||
const needsInstall =
|
||||
!currentVersion ||
|
||||
(composeVersion &&
|
||||
normalizedRequestedVersion !== normalizedCurrentVersion);
|
||||
if (!needsInstall) {
|
||||
return currentVersion;
|
||||
}
|
||||
const needsInstall =
|
||||
!currentVersion ||
|
||||
(composeVersion &&
|
||||
normalizedRequestedVersion !== normalizedCurrentVersion);
|
||||
if (!needsInstall) {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
let targetVersion = composeVersion || COMPOSE_VERSION_LATEST;
|
||||
let targetVersion = composeVersion || COMPOSE_VERSION_LATEST;
|
||||
|
||||
if (targetVersion === COMPOSE_VERSION_LATEST) {
|
||||
if (!githubToken) {
|
||||
throw new Error(
|
||||
"GitHub token is required to install the latest version",
|
||||
);
|
||||
}
|
||||
targetVersion = await this.getLatestVersion(githubToken);
|
||||
}
|
||||
if (targetVersion === COMPOSE_VERSION_LATEST) {
|
||||
if (!githubToken) {
|
||||
throw new Error(
|
||||
"GitHub token is required to install the latest version",
|
||||
);
|
||||
}
|
||||
targetVersion = await this.getLatestVersion(githubToken);
|
||||
}
|
||||
|
||||
await this.installVersion(targetVersion);
|
||||
await this.installVersion(targetVersion);
|
||||
|
||||
const installedVersion = await this.version({ cwd });
|
||||
const installedVersion = await this.version({ cwd });
|
||||
|
||||
if (
|
||||
!installedVersion ||
|
||||
this.normalizeVersion(installedVersion) !==
|
||||
this.normalizeVersion(targetVersion)
|
||||
) {
|
||||
throw new Error(
|
||||
`Failed to install Docker Compose version "${targetVersion}", installed version is "${installedVersion ?? "unknown"}"`,
|
||||
);
|
||||
}
|
||||
if (
|
||||
!installedVersion ||
|
||||
this.normalizeVersion(installedVersion) !==
|
||||
this.normalizeVersion(targetVersion)
|
||||
) {
|
||||
throw new Error(
|
||||
`Failed to install Docker Compose version "${targetVersion}", installed version is "${installedVersion ?? "unknown"}"`,
|
||||
);
|
||||
}
|
||||
|
||||
return installedVersion;
|
||||
}
|
||||
return installedVersion;
|
||||
}
|
||||
|
||||
private async version({ cwd }: VersionInputs): Promise<string | null> {
|
||||
try {
|
||||
const result = await version({
|
||||
cwd,
|
||||
});
|
||||
return result.data.version;
|
||||
} catch {
|
||||
// If version check fails (e.g., Docker Compose not installed), return null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private async version({ cwd }: VersionInputs): Promise<string | null> {
|
||||
try {
|
||||
const result = await version({
|
||||
cwd,
|
||||
});
|
||||
return result.data.version;
|
||||
} catch {
|
||||
// If version check fails (e.g., Docker Compose not installed), return null
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private async getLatestVersion(githubToken: string): Promise<string> {
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
private async getLatestVersion(githubToken: string): Promise<string> {
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
|
||||
const response = await octokit.rest.repos.getLatestRelease({
|
||||
owner: "docker",
|
||||
repo: "compose",
|
||||
});
|
||||
const response = await octokit.rest.repos.getLatestRelease({
|
||||
owner: "docker",
|
||||
repo: "compose",
|
||||
});
|
||||
|
||||
return response.data.tag_name;
|
||||
}
|
||||
return response.data.tag_name;
|
||||
}
|
||||
|
||||
private normalizeVersion(version: string): string {
|
||||
return version.replace(/^v/i, "");
|
||||
}
|
||||
private normalizeVersion(version: string): string {
|
||||
return version.replace(/^v/i, "");
|
||||
}
|
||||
|
||||
private async installVersion(version: string): Promise<void> {
|
||||
switch (process.platform) {
|
||||
case "linux":
|
||||
case "darwin":
|
||||
await this.manualInstallerAdapter.install(version);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported platform: ${process.platform}`);
|
||||
}
|
||||
}
|
||||
private async installVersion(version: string): Promise<void> {
|
||||
switch (process.platform) {
|
||||
case "linux":
|
||||
case "darwin":
|
||||
await this.manualInstallerAdapter.install(version);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported platform: ${process.platform}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,391 +1,391 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import type {
|
||||
IDockerComposeLogOptions,
|
||||
IDockerComposeOptions,
|
||||
IDockerComposeResult,
|
||||
IDockerComposeLogOptions,
|
||||
IDockerComposeOptions,
|
||||
IDockerComposeResult,
|
||||
} from "docker-compose";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock docker-compose before importing the module under test
|
||||
const upAllMock =
|
||||
vi.fn<(options: IDockerComposeOptions) => Promise<IDockerComposeResult>>();
|
||||
vi.fn<(options: IDockerComposeOptions) => Promise<IDockerComposeResult>>();
|
||||
const upManyMock =
|
||||
vi.fn<
|
||||
(
|
||||
services: string[],
|
||||
options: IDockerComposeOptions,
|
||||
) => Promise<IDockerComposeResult>
|
||||
>();
|
||||
vi.fn<
|
||||
(
|
||||
services: string[],
|
||||
options: IDockerComposeOptions,
|
||||
) => Promise<IDockerComposeResult>
|
||||
>();
|
||||
const downMock =
|
||||
vi.fn<(options: IDockerComposeOptions) => Promise<IDockerComposeResult>>();
|
||||
vi.fn<(options: IDockerComposeOptions) => Promise<IDockerComposeResult>>();
|
||||
const logsMock =
|
||||
vi.fn<
|
||||
(
|
||||
services: string[],
|
||||
options: IDockerComposeLogOptions,
|
||||
) => Promise<IDockerComposeResult>
|
||||
>();
|
||||
vi.fn<
|
||||
(
|
||||
services: string[],
|
||||
options: IDockerComposeLogOptions,
|
||||
) => Promise<IDockerComposeResult>
|
||||
>();
|
||||
|
||||
vi.doMock("docker-compose", () => ({
|
||||
upAll: upAllMock,
|
||||
upMany: upManyMock,
|
||||
down: downMock,
|
||||
logs: logsMock,
|
||||
upAll: upAllMock,
|
||||
upMany: upManyMock,
|
||||
down: downMock,
|
||||
logs: logsMock,
|
||||
}));
|
||||
|
||||
// Dynamic import after mock setup
|
||||
const { DockerComposeService } = await import("./docker-compose.service.js");
|
||||
|
||||
describe("DockerComposeService", () => {
|
||||
let service: InstanceType<typeof DockerComposeService>;
|
||||
let service: InstanceType<typeof DockerComposeService>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
service = new DockerComposeService();
|
||||
});
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
service = new DockerComposeService();
|
||||
});
|
||||
|
||||
describe("up", () => {
|
||||
it("should call up with correct options", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
describe("up", () => {
|
||||
it("should call up with correct options", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
upAllMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
upAllMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
|
||||
await service.up(upInputs);
|
||||
await service.up(upInputs);
|
||||
|
||||
expect(upAllMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
expect(upAllMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
|
||||
// Ensure callback is calling the service logger
|
||||
const callback = (upAllMock.mock.calls[0][0] as IDockerComposeOptions)
|
||||
?.callback;
|
||||
expect(callback).toBeDefined();
|
||||
// Ensure callback is calling the service logger
|
||||
const callback = (upAllMock.mock.calls[0][0] as IDockerComposeOptions)
|
||||
?.callback;
|
||||
expect(callback).toBeDefined();
|
||||
|
||||
const message = "test log output";
|
||||
const message = "test log output";
|
||||
|
||||
if (callback) {
|
||||
callback(Buffer.from(message));
|
||||
}
|
||||
if (callback) {
|
||||
callback(Buffer.from(message));
|
||||
}
|
||||
|
||||
expect(upInputs.serviceLogger).toHaveBeenCalledWith("test log output");
|
||||
});
|
||||
expect(upInputs.serviceLogger).toHaveBeenCalledWith("test log output");
|
||||
});
|
||||
|
||||
it("should call up with specific docker flags", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: ["--context", "dev"],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should call up with specific docker flags", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: ["--context", "dev"],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
upAllMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
upAllMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
|
||||
await service.up(upInputs);
|
||||
await service.up(upInputs);
|
||||
|
||||
expect(upAllMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: ["--context", "dev"],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
expect(upAllMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: ["--context", "dev"],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
it("should call up with specific services", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: ["--build"],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should call up with specific services", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: ["--build"],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
upManyMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
upManyMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
|
||||
await service.up(upInputs);
|
||||
await service.up(upInputs);
|
||||
|
||||
expect(upManyMock).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
commandOptions: ["--build"],
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
expect(upManyMock).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
commandOptions: ["--build"],
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw formatted error when upAll fails with docker-compose result", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should throw formatted error when upAll fails with docker-compose result", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: "Error: unable to pull image\nfailed to resolve reference",
|
||||
out: "",
|
||||
};
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: "Error: unable to pull image\nfailed to resolve reference",
|
||||
out: "",
|
||||
};
|
||||
|
||||
upAllMock.mockRejectedValue(dockerComposeError);
|
||||
upAllMock.mockRejectedValue(dockerComposeError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"unable to pull image",
|
||||
);
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"unable to pull image",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw formatted error when upMany fails with docker-compose result", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should throw formatted error when upMany fails with docker-compose result", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: "Service 'web' failed to start",
|
||||
out: "Starting web...",
|
||||
};
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: "Service 'web' failed to start",
|
||||
out: "Starting web...",
|
||||
};
|
||||
|
||||
upManyMock.mockRejectedValue(dockerComposeError);
|
||||
upManyMock.mockRejectedValue(dockerComposeError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Service 'web' failed to start",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.toThrow("Starting web...");
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Service 'web' failed to start",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.toThrow("Starting web...");
|
||||
});
|
||||
|
||||
it("should pass through docker-compose result without exit code", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should pass through docker-compose result without exit code", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const dockerComposeError = {
|
||||
exitCode: null,
|
||||
err: "Some error without exit code",
|
||||
out: "",
|
||||
};
|
||||
const dockerComposeError = {
|
||||
exitCode: null,
|
||||
err: "Some error without exit code",
|
||||
out: "",
|
||||
};
|
||||
|
||||
upAllMock.mockRejectedValue(dockerComposeError);
|
||||
upAllMock.mockRejectedValue(dockerComposeError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Some error without exit code",
|
||||
);
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Some error without exit code",
|
||||
);
|
||||
});
|
||||
|
||||
it("should format docker-compose result when streams are undefined", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should format docker-compose result when streams are undefined", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: undefined,
|
||||
out: undefined,
|
||||
};
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: undefined,
|
||||
out: undefined,
|
||||
};
|
||||
|
||||
upAllMock.mockRejectedValue(dockerComposeError);
|
||||
upAllMock.mockRejectedValue(dockerComposeError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.not.toThrow("Error output:");
|
||||
await expect(service.up(upInputs)).rejects.not.toThrow(
|
||||
"Standard output:",
|
||||
);
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.up(upInputs)).rejects.not.toThrow("Error output:");
|
||||
await expect(service.up(upInputs)).rejects.not.toThrow(
|
||||
"Standard output:",
|
||||
);
|
||||
});
|
||||
|
||||
it("should pass through standard Error objects", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should pass through standard Error objects", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const standardError = new Error("Standard error message");
|
||||
upAllMock.mockRejectedValue(standardError);
|
||||
const standardError = new Error("Standard error message");
|
||||
upAllMock.mockRejectedValue(standardError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Standard error message",
|
||||
);
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
"Standard error message",
|
||||
);
|
||||
});
|
||||
|
||||
it("should pass through error strings", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should pass through error strings", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const unknownError = "Some unknown error";
|
||||
upAllMock.mockRejectedValue(unknownError);
|
||||
const unknownError = "Some unknown error";
|
||||
upAllMock.mockRejectedValue(unknownError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow("Some unknown error");
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow("Some unknown error");
|
||||
});
|
||||
|
||||
it("should handle unknown error types gracefully", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should handle unknown error types gracefully", async () => {
|
||||
const upInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
upFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const unknownError = { unexpected: "error format" };
|
||||
upAllMock.mockRejectedValue(unknownError);
|
||||
const unknownError = { unexpected: "error format" };
|
||||
upAllMock.mockRejectedValue(unknownError);
|
||||
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
JSON.stringify(unknownError),
|
||||
);
|
||||
});
|
||||
});
|
||||
await expect(service.up(upInputs)).rejects.toThrow(
|
||||
JSON.stringify(unknownError),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("down", () => {
|
||||
it("should call down with correct options", async () => {
|
||||
const downInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
downFlags: ["--volumes", "--remove-orphans"],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
describe("down", () => {
|
||||
it("should call down with correct options", async () => {
|
||||
const downInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
downFlags: ["--volumes", "--remove-orphans"],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
downMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
downMock.mockResolvedValue({ exitCode: 0, err: "", out: "" });
|
||||
|
||||
await service.down(downInputs);
|
||||
await service.down(downInputs);
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: ["--volumes", "--remove-orphans"],
|
||||
config: [],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
commandOptions: ["--volumes", "--remove-orphans"],
|
||||
config: [],
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
cwd: "/current/working/dir",
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw formatted error when down fails with docker-compose result", async () => {
|
||||
const downInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
downFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
it("should throw formatted error when down fails with docker-compose result", async () => {
|
||||
const downInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: [] as string[],
|
||||
composeFlags: [] as string[],
|
||||
downFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: vi.fn(),
|
||||
};
|
||||
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: "Error stopping containers",
|
||||
out: "",
|
||||
};
|
||||
const dockerComposeError = {
|
||||
exitCode: 1,
|
||||
err: "Error stopping containers",
|
||||
out: "",
|
||||
};
|
||||
|
||||
downMock.mockRejectedValue(dockerComposeError);
|
||||
downMock.mockRejectedValue(dockerComposeError);
|
||||
|
||||
await expect(service.down(downInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.down(downInputs)).rejects.toThrow(
|
||||
"Error stopping containers",
|
||||
);
|
||||
});
|
||||
});
|
||||
await expect(service.down(downInputs)).rejects.toThrow(
|
||||
"Docker Compose command failed with exit code 1",
|
||||
);
|
||||
await expect(service.down(downInputs)).rejects.toThrow(
|
||||
"Error stopping containers",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("logs", () => {
|
||||
it("should call logs with correct options", async () => {
|
||||
const debugMock = vi.fn();
|
||||
const logsInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: debugMock,
|
||||
};
|
||||
describe("logs", () => {
|
||||
it("should call logs with correct options", async () => {
|
||||
const debugMock = vi.fn();
|
||||
const logsInputs = {
|
||||
dockerFlags: [] as string[],
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [] as string[],
|
||||
cwd: "/current/working/dir",
|
||||
serviceLogger: debugMock,
|
||||
};
|
||||
|
||||
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
|
||||
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
|
||||
|
||||
await service.logs(logsInputs);
|
||||
await service.logs(logsInputs);
|
||||
|
||||
expect(logsMock).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
follow: false,
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(logsMock).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
cwd: "/current/working/dir",
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: [],
|
||||
},
|
||||
follow: false,
|
||||
callback: expect.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,153 +1,153 @@
|
||||
import {
|
||||
down,
|
||||
type IDockerComposeLogOptions,
|
||||
type IDockerComposeOptions,
|
||||
type IDockerComposeResult,
|
||||
logs,
|
||||
upAll,
|
||||
upMany,
|
||||
down,
|
||||
type IDockerComposeLogOptions,
|
||||
type IDockerComposeOptions,
|
||||
type IDockerComposeResult,
|
||||
logs,
|
||||
upAll,
|
||||
upMany,
|
||||
} from "docker-compose";
|
||||
import type { Inputs } from "./input.service.js";
|
||||
|
||||
type OptionsInputs = {
|
||||
dockerFlags: Inputs["dockerFlags"];
|
||||
composeFiles: Inputs["composeFiles"];
|
||||
composeFlags: Inputs["composeFlags"];
|
||||
cwd: Inputs["cwd"];
|
||||
serviceLogger: (message: string) => void;
|
||||
dockerFlags: Inputs["dockerFlags"];
|
||||
composeFiles: Inputs["composeFiles"];
|
||||
composeFlags: Inputs["composeFlags"];
|
||||
cwd: Inputs["cwd"];
|
||||
serviceLogger: (message: string) => void;
|
||||
};
|
||||
|
||||
export type UpInputs = OptionsInputs & {
|
||||
upFlags: Inputs["upFlags"];
|
||||
services: Inputs["services"];
|
||||
upFlags: Inputs["upFlags"];
|
||||
services: Inputs["services"];
|
||||
};
|
||||
export type DownInputs = OptionsInputs & { downFlags: Inputs["downFlags"] };
|
||||
export type LogsInputs = OptionsInputs & { services: Inputs["services"] };
|
||||
|
||||
export class DockerComposeService {
|
||||
async up({ upFlags, services, ...optionsInputs }: UpInputs): Promise<void> {
|
||||
const options: IDockerComposeOptions = {
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: upFlags,
|
||||
};
|
||||
async up({ upFlags, services, ...optionsInputs }: UpInputs): Promise<void> {
|
||||
const options: IDockerComposeOptions = {
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: upFlags,
|
||||
};
|
||||
|
||||
try {
|
||||
if (services.length > 0) {
|
||||
await upMany(services, options);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (services.length > 0) {
|
||||
await upMany(services, options);
|
||||
return;
|
||||
}
|
||||
|
||||
await upAll(options);
|
||||
} catch (error) {
|
||||
throw this.formatDockerComposeError(error);
|
||||
}
|
||||
}
|
||||
await upAll(options);
|
||||
} catch (error) {
|
||||
throw this.formatDockerComposeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
async down({ downFlags, ...optionsInputs }: DownInputs): Promise<void> {
|
||||
const options: IDockerComposeOptions = {
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: downFlags,
|
||||
};
|
||||
async down({ downFlags, ...optionsInputs }: DownInputs): Promise<void> {
|
||||
const options: IDockerComposeOptions = {
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: downFlags,
|
||||
};
|
||||
|
||||
try {
|
||||
await down(options);
|
||||
} catch (error) {
|
||||
throw this.formatDockerComposeError(error);
|
||||
}
|
||||
}
|
||||
try {
|
||||
await down(options);
|
||||
} catch (error) {
|
||||
throw this.formatDockerComposeError(error);
|
||||
}
|
||||
}
|
||||
|
||||
async logs({ services, ...optionsInputs }: LogsInputs): Promise<{
|
||||
error: string;
|
||||
output: string;
|
||||
}> {
|
||||
const options: IDockerComposeLogOptions = {
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
follow: false,
|
||||
};
|
||||
async logs({ services, ...optionsInputs }: LogsInputs): Promise<{
|
||||
error: string;
|
||||
output: string;
|
||||
}> {
|
||||
const options: IDockerComposeLogOptions = {
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
follow: false,
|
||||
};
|
||||
|
||||
const { err, out } = await logs(services, options);
|
||||
const { err, out } = await logs(services, options);
|
||||
|
||||
return {
|
||||
error: err,
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
return {
|
||||
error: err,
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
|
||||
private getCommonOptions({
|
||||
dockerFlags,
|
||||
composeFiles,
|
||||
composeFlags,
|
||||
cwd,
|
||||
serviceLogger,
|
||||
}: OptionsInputs): IDockerComposeOptions {
|
||||
return {
|
||||
config: composeFiles,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => serviceLogger(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
private getCommonOptions({
|
||||
dockerFlags,
|
||||
composeFiles,
|
||||
composeFlags,
|
||||
cwd,
|
||||
serviceLogger,
|
||||
}: OptionsInputs): IDockerComposeOptions {
|
||||
return {
|
||||
config: composeFiles,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
callback: (chunk) => serviceLogger(chunk.toString()),
|
||||
executable: {
|
||||
executablePath: "docker",
|
||||
options: dockerFlags,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats docker-compose errors into proper Error objects with readable messages
|
||||
*/
|
||||
private formatDockerComposeError(error: unknown): Error {
|
||||
// If it's already an Error, return it
|
||||
if (error instanceof Error) {
|
||||
return error;
|
||||
}
|
||||
/**
|
||||
* Formats docker-compose errors into proper Error objects with readable messages
|
||||
*/
|
||||
private formatDockerComposeError(error: unknown): Error {
|
||||
// If it's already an Error, return it
|
||||
if (error instanceof Error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
// Handle docker-compose result objects
|
||||
if (this.isDockerComposeResult(error)) {
|
||||
const parts: string[] = [];
|
||||
// Handle docker-compose result objects
|
||||
if (this.isDockerComposeResult(error)) {
|
||||
const parts: string[] = [];
|
||||
|
||||
// Add exit code information
|
||||
if (error.exitCode !== null) {
|
||||
parts.push(
|
||||
`Docker Compose command failed with exit code ${error.exitCode}`,
|
||||
);
|
||||
} else {
|
||||
parts.push("Docker Compose command failed");
|
||||
}
|
||||
// Add exit code information
|
||||
if (error.exitCode !== null) {
|
||||
parts.push(
|
||||
`Docker Compose command failed with exit code ${error.exitCode}`,
|
||||
);
|
||||
} else {
|
||||
parts.push("Docker Compose command failed");
|
||||
}
|
||||
|
||||
// Add error stream output if available
|
||||
if (error.err?.trim()) {
|
||||
parts.push("\nError output:");
|
||||
parts.push(error.err.trim());
|
||||
}
|
||||
// Add error stream output if available
|
||||
if (error.err?.trim()) {
|
||||
parts.push("\nError output:");
|
||||
parts.push(error.err.trim());
|
||||
}
|
||||
|
||||
// Add standard output if available and different from error output
|
||||
if (error.out?.trim() && error.out !== error.err) {
|
||||
parts.push("\nStandard output:");
|
||||
parts.push(error.out.trim());
|
||||
}
|
||||
// Add standard output if available and different from error output
|
||||
if (error.out?.trim() && error.out !== error.err) {
|
||||
parts.push("\nStandard output:");
|
||||
parts.push(error.out.trim());
|
||||
}
|
||||
|
||||
return new Error(parts.join("\n"));
|
||||
}
|
||||
return new Error(parts.join("\n"));
|
||||
}
|
||||
|
||||
// Handle string errors
|
||||
if (typeof error === "string") {
|
||||
return new Error(error);
|
||||
}
|
||||
// Handle string errors
|
||||
if (typeof error === "string") {
|
||||
return new Error(error);
|
||||
}
|
||||
|
||||
// Fallback for unknown error types
|
||||
return new Error(JSON.stringify(error));
|
||||
}
|
||||
// Fallback for unknown error types
|
||||
return new Error(JSON.stringify(error));
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if an object is a docker-compose result
|
||||
*/
|
||||
private isDockerComposeResult(error: unknown): error is IDockerComposeResult {
|
||||
return (
|
||||
typeof error === "object" &&
|
||||
error !== null &&
|
||||
"exitCode" in error &&
|
||||
"err" in error &&
|
||||
"out" in error
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Type guard to check if an object is a docker-compose result
|
||||
*/
|
||||
private isDockerComposeResult(error: unknown): error is IDockerComposeResult {
|
||||
return (
|
||||
typeof error === "object" &&
|
||||
error !== null &&
|
||||
"exitCode" in error &&
|
||||
"err" in error &&
|
||||
"out" in error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +1,25 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock @actions/core before importing the module under test
|
||||
const getInputMock =
|
||||
vi.fn<(name: string, options?: { required?: boolean }) => string>();
|
||||
vi.fn<(name: string, options?: { required?: boolean }) => string>();
|
||||
const getMultilineInputMock =
|
||||
vi.fn<(name: string, options?: { required?: boolean }) => string[]>();
|
||||
vi.fn<(name: string, options?: { required?: boolean }) => string[]>();
|
||||
|
||||
vi.doMock("@actions/core", () => ({
|
||||
getInput: getInputMock,
|
||||
getMultilineInput: getMultilineInputMock,
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
getInput: getInputMock,
|
||||
getMultilineInput: getMultilineInputMock,
|
||||
debug: vi.fn(),
|
||||
info: vi.fn(),
|
||||
warning: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock node:fs
|
||||
const existsSyncMock = vi.fn<(path: string) => boolean>();
|
||||
|
||||
vi.doMock("node:fs", () => ({
|
||||
existsSync: existsSyncMock,
|
||||
default: { existsSync: existsSyncMock },
|
||||
existsSync: existsSyncMock,
|
||||
default: { existsSync: existsSyncMock },
|
||||
}));
|
||||
|
||||
// Dynamic imports after mock setup
|
||||
@ -27,373 +27,373 @@ const { InputService, InputNames } = await import("./input.service.js");
|
||||
const { LogLevel } = await import("./logger.service.js");
|
||||
|
||||
describe("InputService", () => {
|
||||
let service: InstanceType<typeof InputService>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
service = new InputService();
|
||||
});
|
||||
|
||||
describe("getInputs", () => {
|
||||
describe("docker-flags", () => {
|
||||
it("should return given docker-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.DockerFlags:
|
||||
return "docker-flag1 docker-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.dockerFlags).toEqual(["docker-flag1", "docker-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no docker-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.dockerFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("composeFiles", () => {
|
||||
it("should return given composeFiles input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1", "file2"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual(["file1", "file2"]);
|
||||
});
|
||||
|
||||
it("should ignore empty compose file entries", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return [" ", "file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual(["file1"]);
|
||||
});
|
||||
|
||||
it("should accept compose file when it exists at the original path", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["./compose.yml"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "/current/working/directory";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockImplementation((file) => file === "./compose.yml");
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual(["./compose.yml"]);
|
||||
});
|
||||
|
||||
it("should accept OCI compose files without checking the file system", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["oci://docker.io/hoverkraft/compose-app:latest"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "/current/working/directory";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual([
|
||||
"oci://docker.io/hoverkraft/compose-app:latest",
|
||||
]);
|
||||
expect(existsSyncMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throws an error when a compose file does not exist", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1", "file2"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "/current/working/directory";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockImplementation(
|
||||
(file) => file === "/current/working/directory/file1",
|
||||
);
|
||||
|
||||
expect(() => service.getInputs()).toThrow(
|
||||
'Compose file not found in "/current/working/directory/file2", "file2"',
|
||||
);
|
||||
});
|
||||
|
||||
it("should throws an error when no composeFiles input", () => {
|
||||
getMultilineInputMock.mockReturnValue([]);
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
expect(() => service.getInputs()).toThrow("No compose files found");
|
||||
});
|
||||
});
|
||||
|
||||
describe("services", () => {
|
||||
it("should return given services input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Services:
|
||||
return ["service1", "service2"];
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.services).toEqual(["service1", "service2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("compose-flags", () => {
|
||||
it("should return given compose-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFlags:
|
||||
return "compose-flag1 compose-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFlags).toEqual(["compose-flag1", "compose-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no compose-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("up-flags", () => {
|
||||
it("should return given up-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.UpFlags:
|
||||
return "up-flag1 up-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.upFlags).toEqual(["up-flag1", "up-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no up-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.upFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("down-flags", () => {
|
||||
it("should return given down-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.DownFlags:
|
||||
return "down-flag1 down-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.downFlags).toEqual(["down-flag1", "down-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no down-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.downFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("cwd", () => {
|
||||
it("should return given cwd input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "cwd";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.cwd).toEqual("cwd");
|
||||
});
|
||||
});
|
||||
|
||||
describe("compose-version", () => {
|
||||
it("should return given compose-version input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeVersion:
|
||||
return "compose-version";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeVersion).toEqual("compose-version");
|
||||
});
|
||||
});
|
||||
|
||||
describe("services-log-level", () => {
|
||||
it("should return given services-log-level input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ServiceLogLevel:
|
||||
return "info";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
expect(inputs.serviceLogLevel).toEqual(LogLevel.Info);
|
||||
});
|
||||
|
||||
it("should return default services-log-level input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ServiceLogLevel:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
expect(inputs.serviceLogLevel).toEqual(LogLevel.Debug);
|
||||
});
|
||||
|
||||
it("should throw an error when services-log-level input is invalid", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ServiceLogLevel:
|
||||
return "invalid-log-level";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
expect(() => service.getInputs()).toThrow(
|
||||
'Invalid service log level "invalid-log-level". Valid values are: debug, info',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
let service: InstanceType<typeof InputService>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
service = new InputService();
|
||||
});
|
||||
|
||||
describe("getInputs", () => {
|
||||
describe("docker-flags", () => {
|
||||
it("should return given docker-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.DockerFlags:
|
||||
return "docker-flag1 docker-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.dockerFlags).toEqual(["docker-flag1", "docker-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no docker-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.dockerFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("composeFiles", () => {
|
||||
it("should return given composeFiles input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1", "file2"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual(["file1", "file2"]);
|
||||
});
|
||||
|
||||
it("should ignore empty compose file entries", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return [" ", "file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual(["file1"]);
|
||||
});
|
||||
|
||||
it("should accept compose file when it exists at the original path", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["./compose.yml"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "/current/working/directory";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockImplementation((file) => file === "./compose.yml");
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual(["./compose.yml"]);
|
||||
});
|
||||
|
||||
it("should accept OCI compose files without checking the file system", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["oci://docker.io/hoverkraft/compose-app:latest"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "/current/working/directory";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFiles).toEqual([
|
||||
"oci://docker.io/hoverkraft/compose-app:latest",
|
||||
]);
|
||||
expect(existsSyncMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throws an error when a compose file does not exist", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1", "file2"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "/current/working/directory";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockImplementation(
|
||||
(file) => file === "/current/working/directory/file1",
|
||||
);
|
||||
|
||||
expect(() => service.getInputs()).toThrow(
|
||||
'Compose file not found in "/current/working/directory/file2", "file2"',
|
||||
);
|
||||
});
|
||||
|
||||
it("should throws an error when no composeFiles input", () => {
|
||||
getMultilineInputMock.mockReturnValue([]);
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
expect(() => service.getInputs()).toThrow("No compose files found");
|
||||
});
|
||||
});
|
||||
|
||||
describe("services", () => {
|
||||
it("should return given services input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Services:
|
||||
return ["service1", "service2"];
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
getInputMock.mockReturnValue("");
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.services).toEqual(["service1", "service2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("compose-flags", () => {
|
||||
it("should return given compose-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFlags:
|
||||
return "compose-flag1 compose-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFlags).toEqual(["compose-flag1", "compose-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no compose-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("up-flags", () => {
|
||||
it("should return given up-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.UpFlags:
|
||||
return "up-flag1 up-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.upFlags).toEqual(["up-flag1", "up-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no up-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.upFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("down-flags", () => {
|
||||
it("should return given down-flags input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.DownFlags:
|
||||
return "down-flag1 down-flag2";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.downFlags).toEqual(["down-flag1", "down-flag2"]);
|
||||
});
|
||||
|
||||
it("should return empty array when no down-flags input", () => {
|
||||
getInputMock.mockReturnValue("");
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.downFlags).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("cwd", () => {
|
||||
it("should return given cwd input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.Cwd:
|
||||
return "cwd";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.cwd).toEqual("cwd");
|
||||
});
|
||||
});
|
||||
|
||||
describe("compose-version", () => {
|
||||
it("should return given compose-version input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeVersion:
|
||||
return "compose-version";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
|
||||
expect(inputs.composeVersion).toEqual("compose-version");
|
||||
});
|
||||
});
|
||||
|
||||
describe("services-log-level", () => {
|
||||
it("should return given services-log-level input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ServiceLogLevel:
|
||||
return "info";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
expect(inputs.serviceLogLevel).toEqual(LogLevel.Info);
|
||||
});
|
||||
|
||||
it("should return default services-log-level input", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ServiceLogLevel:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
const inputs = service.getInputs();
|
||||
expect(inputs.serviceLogLevel).toEqual(LogLevel.Debug);
|
||||
});
|
||||
|
||||
it("should throw an error when services-log-level input is invalid", () => {
|
||||
getInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ServiceLogLevel:
|
||||
return "invalid-log-level";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
existsSyncMock.mockReturnValue(true);
|
||||
|
||||
expect(() => service.getInputs()).toThrow(
|
||||
'Invalid service log level "invalid-log-level". Valid values are: debug, info',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,147 +1,147 @@
|
||||
import { getInput, getMultilineInput } from "@actions/core";
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { getInput, getMultilineInput } from "@actions/core";
|
||||
import { LogLevel } from "./logger.service.js";
|
||||
|
||||
export type Inputs = {
|
||||
dockerFlags: string[];
|
||||
composeFiles: string[];
|
||||
services: string[];
|
||||
composeFlags: string[];
|
||||
upFlags: string[];
|
||||
downFlags: string[];
|
||||
cwd: string;
|
||||
composeVersion: string | null;
|
||||
githubToken: string | null;
|
||||
serviceLogLevel: LogLevel;
|
||||
dockerFlags: string[];
|
||||
composeFiles: string[];
|
||||
services: string[];
|
||||
composeFlags: string[];
|
||||
upFlags: string[];
|
||||
downFlags: string[];
|
||||
cwd: string;
|
||||
composeVersion: string | null;
|
||||
githubToken: string | null;
|
||||
serviceLogLevel: LogLevel;
|
||||
};
|
||||
|
||||
export enum InputNames {
|
||||
DockerFlags = "docker-flags",
|
||||
ComposeFile = "compose-file",
|
||||
Services = "services",
|
||||
ComposeFlags = "compose-flags",
|
||||
UpFlags = "up-flags",
|
||||
DownFlags = "down-flags",
|
||||
Cwd = "cwd",
|
||||
ComposeVersion = "compose-version",
|
||||
GithubToken = "github-token",
|
||||
ServiceLogLevel = "services-log-level",
|
||||
DockerFlags = "docker-flags",
|
||||
ComposeFile = "compose-file",
|
||||
Services = "services",
|
||||
ComposeFlags = "compose-flags",
|
||||
UpFlags = "up-flags",
|
||||
DownFlags = "down-flags",
|
||||
Cwd = "cwd",
|
||||
ComposeVersion = "compose-version",
|
||||
GithubToken = "github-token",
|
||||
ServiceLogLevel = "services-log-level",
|
||||
}
|
||||
|
||||
export const COMPOSE_VERSION_LATEST = "latest";
|
||||
|
||||
export class InputService {
|
||||
getInputs(): Inputs {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
upFlags: this.getUpFlags(),
|
||||
downFlags: this.getDownFlags(),
|
||||
cwd: this.getCwd(),
|
||||
composeVersion: this.getComposeVersion(),
|
||||
githubToken: this.getGithubToken(),
|
||||
serviceLogLevel: this.getServiceLogLevel(),
|
||||
};
|
||||
}
|
||||
getInputs(): Inputs {
|
||||
return {
|
||||
dockerFlags: this.getDockerFlags(),
|
||||
composeFiles: this.getComposeFiles(),
|
||||
services: this.getServices(),
|
||||
composeFlags: this.getComposeFlags(),
|
||||
upFlags: this.getUpFlags(),
|
||||
downFlags: this.getDownFlags(),
|
||||
cwd: this.getCwd(),
|
||||
composeVersion: this.getComposeVersion(),
|
||||
githubToken: this.getGithubToken(),
|
||||
serviceLogLevel: this.getServiceLogLevel(),
|
||||
};
|
||||
}
|
||||
|
||||
private getDockerFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.DockerFlags));
|
||||
}
|
||||
private getDockerFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.DockerFlags));
|
||||
}
|
||||
|
||||
private getComposeFiles(): string[] {
|
||||
const cwd = this.getCwd();
|
||||
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter(
|
||||
(composeFile: string) => {
|
||||
const trimmedComposeFile = composeFile.trim();
|
||||
private getComposeFiles(): string[] {
|
||||
const cwd = this.getCwd();
|
||||
const composeFiles = getMultilineInput(InputNames.ComposeFile).filter(
|
||||
(composeFile: string) => {
|
||||
const trimmedComposeFile = composeFile.trim();
|
||||
|
||||
if (!trimmedComposeFile.length) {
|
||||
return false;
|
||||
}
|
||||
if (!trimmedComposeFile.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trimmedComposeFile.startsWith("oci://")) {
|
||||
return true;
|
||||
}
|
||||
if (trimmedComposeFile.startsWith("oci://")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const possiblePaths = [join(cwd, composeFile), composeFile];
|
||||
const possiblePaths = [join(cwd, composeFile), composeFile];
|
||||
|
||||
for (const path of possiblePaths) {
|
||||
if (existsSync(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (const path of possiblePaths) {
|
||||
if (existsSync(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Compose file not found in "${possiblePaths.join('", "')}"`,
|
||||
);
|
||||
},
|
||||
);
|
||||
throw new Error(
|
||||
`Compose file not found in "${possiblePaths.join('", "')}"`,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (!composeFiles.length) {
|
||||
throw new Error("No compose files found");
|
||||
}
|
||||
if (!composeFiles.length) {
|
||||
throw new Error("No compose files found");
|
||||
}
|
||||
|
||||
return composeFiles;
|
||||
}
|
||||
return composeFiles;
|
||||
}
|
||||
|
||||
private getServices(): string[] {
|
||||
return getMultilineInput(InputNames.Services, { required: false });
|
||||
}
|
||||
private getServices(): string[] {
|
||||
return getMultilineInput(InputNames.Services, { required: false });
|
||||
}
|
||||
|
||||
private getComposeFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.ComposeFlags));
|
||||
}
|
||||
private getComposeFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.ComposeFlags));
|
||||
}
|
||||
|
||||
private getUpFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.UpFlags));
|
||||
}
|
||||
private getUpFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.UpFlags));
|
||||
}
|
||||
|
||||
private getDownFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.DownFlags));
|
||||
}
|
||||
private getDownFlags(): string[] {
|
||||
return this.parseFlags(getInput(InputNames.DownFlags));
|
||||
}
|
||||
|
||||
private parseFlags(flags: string | null): string[] {
|
||||
if (!flags) {
|
||||
return [];
|
||||
}
|
||||
private parseFlags(flags: string | null): string[] {
|
||||
if (!flags) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return flags.trim().split(" ");
|
||||
}
|
||||
return flags.trim().split(" ");
|
||||
}
|
||||
|
||||
private getCwd(): string {
|
||||
return getInput(InputNames.Cwd);
|
||||
}
|
||||
private getCwd(): string {
|
||||
return getInput(InputNames.Cwd);
|
||||
}
|
||||
|
||||
private getComposeVersion(): string | null {
|
||||
return (
|
||||
getInput(InputNames.ComposeVersion, {
|
||||
required: false,
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
private getComposeVersion(): string | null {
|
||||
return (
|
||||
getInput(InputNames.ComposeVersion, {
|
||||
required: false,
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
|
||||
private getGithubToken(): string | null {
|
||||
return (
|
||||
getInput(InputNames.GithubToken, {
|
||||
required: false,
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
private getGithubToken(): string | null {
|
||||
return (
|
||||
getInput(InputNames.GithubToken, {
|
||||
required: false,
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
|
||||
private getServiceLogLevel(): LogLevel {
|
||||
const configuredLevel = getInput(InputNames.ServiceLogLevel, {
|
||||
required: false,
|
||||
});
|
||||
if (
|
||||
configuredLevel &&
|
||||
!Object.values(LogLevel).includes(configuredLevel as LogLevel)
|
||||
) {
|
||||
throw new Error(
|
||||
`Invalid service log level "${configuredLevel}". Valid values are: ${Object.values(LogLevel).join(", ")}`,
|
||||
);
|
||||
}
|
||||
return (configuredLevel as LogLevel) || LogLevel.Debug;
|
||||
}
|
||||
private getServiceLogLevel(): LogLevel {
|
||||
const configuredLevel = getInput(InputNames.ServiceLogLevel, {
|
||||
required: false,
|
||||
});
|
||||
if (
|
||||
configuredLevel &&
|
||||
!Object.values(LogLevel).includes(configuredLevel as LogLevel)
|
||||
) {
|
||||
throw new Error(
|
||||
`Invalid service log level "${configuredLevel}". Valid values are: ${Object.values(LogLevel).join(", ")}`,
|
||||
);
|
||||
}
|
||||
return (configuredLevel as LogLevel) || LogLevel.Debug;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
export interface DockerComposeInstallerAdapter {
|
||||
install(version: string): Promise<void>;
|
||||
install(version: string): Promise<void>;
|
||||
}
|
||||
|
||||
@ -1,221 +1,221 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import type { ExecOptions } from "@actions/exec";
|
||||
import type { OutgoingHttpHeaders } from "node:http";
|
||||
import type { ExecOptions } from "@actions/exec";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Mock @actions/exec
|
||||
const execMock =
|
||||
vi.fn<
|
||||
(command: string, args?: string[], options?: ExecOptions) => Promise<number>
|
||||
>();
|
||||
vi.fn<
|
||||
(command: string, args?: string[], options?: ExecOptions) => Promise<number>
|
||||
>();
|
||||
|
||||
vi.doMock("@actions/exec", () => ({
|
||||
exec: execMock,
|
||||
exec: execMock,
|
||||
}));
|
||||
|
||||
// Mock @actions/io
|
||||
const mkdirPMock = vi.fn<(fsPath: string) => Promise<void>>();
|
||||
|
||||
vi.doMock("@actions/io", () => ({
|
||||
mkdirP: mkdirPMock,
|
||||
mkdirP: mkdirPMock,
|
||||
}));
|
||||
|
||||
// Mock @actions/tool-cache
|
||||
const cacheFileMock =
|
||||
vi.fn<
|
||||
(
|
||||
sourceFile: string,
|
||||
targetFile: string,
|
||||
tool: string,
|
||||
version: string,
|
||||
arch?: string,
|
||||
) => Promise<string>
|
||||
>();
|
||||
vi.fn<
|
||||
(
|
||||
sourceFile: string,
|
||||
targetFile: string,
|
||||
tool: string,
|
||||
version: string,
|
||||
arch?: string,
|
||||
) => Promise<string>
|
||||
>();
|
||||
const downloadToolMock =
|
||||
vi.fn<
|
||||
(
|
||||
url: string,
|
||||
dest?: string,
|
||||
auth?: string,
|
||||
headers?: OutgoingHttpHeaders,
|
||||
) => Promise<string>
|
||||
>();
|
||||
vi.fn<
|
||||
(
|
||||
url: string,
|
||||
dest?: string,
|
||||
auth?: string,
|
||||
headers?: OutgoingHttpHeaders,
|
||||
) => Promise<string>
|
||||
>();
|
||||
|
||||
vi.doMock("@actions/tool-cache", () => ({
|
||||
cacheFile: cacheFileMock,
|
||||
downloadTool: downloadToolMock,
|
||||
cacheFile: cacheFileMock,
|
||||
downloadTool: downloadToolMock,
|
||||
}));
|
||||
|
||||
// Dynamic import after mock setup
|
||||
const { ManualInstallerAdapter } = await import(
|
||||
"./manual-installer-adapter.js"
|
||||
"./manual-installer-adapter.js"
|
||||
);
|
||||
|
||||
const originalHome = process.env.HOME;
|
||||
const originalDockerConfig = process.env.DOCKER_CONFIG;
|
||||
|
||||
describe("ManualInstallerAdapter", () => {
|
||||
let adapter: InstanceType<typeof ManualInstallerAdapter>;
|
||||
let adapter: InstanceType<typeof ManualInstallerAdapter>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
if (originalHome === undefined) {
|
||||
delete process.env.HOME;
|
||||
} else {
|
||||
process.env.HOME = originalHome;
|
||||
}
|
||||
if (originalDockerConfig === undefined) {
|
||||
delete process.env.DOCKER_CONFIG;
|
||||
} else {
|
||||
process.env.DOCKER_CONFIG = originalDockerConfig;
|
||||
}
|
||||
adapter = new ManualInstallerAdapter();
|
||||
});
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
if (originalHome === undefined) {
|
||||
delete process.env.HOME;
|
||||
} else {
|
||||
process.env.HOME = originalHome;
|
||||
}
|
||||
if (originalDockerConfig === undefined) {
|
||||
delete process.env.DOCKER_CONFIG;
|
||||
} else {
|
||||
process.env.DOCKER_CONFIG = originalDockerConfig;
|
||||
}
|
||||
adapter = new ManualInstallerAdapter();
|
||||
});
|
||||
|
||||
describe("install", () => {
|
||||
it("should install docker compose correctly", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
describe("install", () => {
|
||||
it("should install docker compose correctly", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
process.env.HOME = "/home/test";
|
||||
process.env.HOME = "/home/test";
|
||||
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
|
||||
// Assert
|
||||
expect(mkdirPMock).toHaveBeenCalledWith("docker-compose");
|
||||
expect(execMock).toHaveBeenNthCalledWith(1, "uname -s", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
expect(execMock).toHaveBeenNthCalledWith(2, "uname -m", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
// Assert
|
||||
expect(mkdirPMock).toHaveBeenCalledWith("docker-compose");
|
||||
expect(execMock).toHaveBeenNthCalledWith(1, "uname -s", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
expect(execMock).toHaveBeenNthCalledWith(2, "uname -m", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-Linux-x86_64",
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
);
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-Linux-x86_64",
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
);
|
||||
|
||||
expect(cacheFileMock).toHaveBeenCalledWith(
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
"docker-compose",
|
||||
"docker-compose",
|
||||
version,
|
||||
);
|
||||
});
|
||||
expect(cacheFileMock).toHaveBeenCalledWith(
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
"docker-compose",
|
||||
"docker-compose",
|
||||
version,
|
||||
);
|
||||
});
|
||||
|
||||
it("should use DOCKER_CONFIG when set", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
it("should use DOCKER_CONFIG when set", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
process.env.DOCKER_CONFIG = "/custom/docker";
|
||||
process.env.DOCKER_CONFIG = "/custom/docker";
|
||||
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
|
||||
// Assert
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-Linux-x86_64",
|
||||
"/custom/docker/cli-plugins/docker-compose",
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-Linux-x86_64",
|
||||
"/custom/docker/cli-plugins/docker-compose",
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle version without 'v' prefix", async () => {
|
||||
// Arrange
|
||||
const version = "2.29.0";
|
||||
it("should handle version without 'v' prefix", async () => {
|
||||
// Arrange
|
||||
const version = "2.29.0";
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
process.env.HOME = "/home/test";
|
||||
process.env.HOME = "/home/test";
|
||||
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
|
||||
// Assert
|
||||
expect(mkdirPMock).toHaveBeenCalledWith("docker-compose");
|
||||
expect(execMock).toHaveBeenNthCalledWith(1, "uname -s", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
expect(execMock).toHaveBeenNthCalledWith(2, "uname -m", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
// Assert
|
||||
expect(mkdirPMock).toHaveBeenCalledWith("docker-compose");
|
||||
expect(execMock).toHaveBeenNthCalledWith(1, "uname -s", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
expect(execMock).toHaveBeenNthCalledWith(2, "uname -m", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-Linux-x86_64",
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
);
|
||||
});
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-Linux-x86_64",
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
);
|
||||
});
|
||||
|
||||
it("should not add 'v' prefix for 1.x versions", async () => {
|
||||
// Arrange
|
||||
const version = "1.29.0";
|
||||
it("should not add 'v' prefix for 1.x versions", async () => {
|
||||
// Arrange
|
||||
const version = "1.29.0";
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("Linux\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
execMock.mockImplementationOnce(async (_command, _args, options) => {
|
||||
options?.listeners?.stdout?.(Buffer.from("x86_64\n"));
|
||||
return 0;
|
||||
});
|
||||
|
||||
delete process.env.DOCKER_CONFIG;
|
||||
process.env.HOME = "/home/test";
|
||||
delete process.env.DOCKER_CONFIG;
|
||||
process.env.HOME = "/home/test";
|
||||
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
// Act
|
||||
await adapter.install(version);
|
||||
|
||||
// Assert
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/1.29.0/docker-compose-Linux-x86_64",
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
);
|
||||
});
|
||||
// Assert
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/1.29.0/docker-compose-Linux-x86_64",
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw an error if a command fails", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
it("should throw an error if a command fails", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
|
||||
// Uname -s
|
||||
execMock.mockResolvedValueOnce(1);
|
||||
// Uname -s
|
||||
execMock.mockResolvedValueOnce(1);
|
||||
|
||||
// Act
|
||||
await expect(adapter.install(version)).rejects.toThrow(
|
||||
"Failed to run command: uname -s",
|
||||
);
|
||||
// Act
|
||||
await expect(adapter.install(version)).rejects.toThrow(
|
||||
"Failed to run command: uname -s",
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(execMock).toHaveBeenNthCalledWith(1, "uname -s", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
});
|
||||
});
|
||||
// Assert
|
||||
expect(execMock).toHaveBeenNthCalledWith(1, "uname -s", [], {
|
||||
listeners: { stdout: expect.any(Function) },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,69 +1,69 @@
|
||||
import { basename } from "node:path";
|
||||
import { exec } from "@actions/exec";
|
||||
import { mkdirP } from "@actions/io";
|
||||
import { basename } from "node:path";
|
||||
import { cacheFile, downloadTool } from "@actions/tool-cache";
|
||||
import type { DockerComposeInstallerAdapter } from "./docker-compose-installer-adapter.js";
|
||||
|
||||
export class ManualInstallerAdapter implements DockerComposeInstallerAdapter {
|
||||
async install(version: string): Promise<void> {
|
||||
const dockerComposePluginPath = await this.getDockerComposePluginPath();
|
||||
async install(version: string): Promise<void> {
|
||||
const dockerComposePluginPath = await this.getDockerComposePluginPath();
|
||||
|
||||
// Create the directory if it doesn't exist
|
||||
await mkdirP(basename(dockerComposePluginPath));
|
||||
// Create the directory if it doesn't exist
|
||||
await mkdirP(basename(dockerComposePluginPath));
|
||||
|
||||
await this.downloadFile(version, dockerComposePluginPath);
|
||||
await exec(`chmod +x ${dockerComposePluginPath}`);
|
||||
await cacheFile(
|
||||
dockerComposePluginPath,
|
||||
"docker-compose",
|
||||
"docker-compose",
|
||||
version,
|
||||
);
|
||||
}
|
||||
await this.downloadFile(version, dockerComposePluginPath);
|
||||
await exec(`chmod +x ${dockerComposePluginPath}`);
|
||||
await cacheFile(
|
||||
dockerComposePluginPath,
|
||||
"docker-compose",
|
||||
"docker-compose",
|
||||
version,
|
||||
);
|
||||
}
|
||||
|
||||
private async getDockerComposePluginPath(): Promise<string> {
|
||||
const dockerConfig =
|
||||
process.env.DOCKER_CONFIG || `${process.env.HOME}/.docker`;
|
||||
private async getDockerComposePluginPath(): Promise<string> {
|
||||
const dockerConfig =
|
||||
process.env.DOCKER_CONFIG || `${process.env.HOME}/.docker`;
|
||||
|
||||
const dockerComposePluginPath = `${dockerConfig}/cli-plugins/docker-compose`;
|
||||
return dockerComposePluginPath;
|
||||
}
|
||||
const dockerComposePluginPath = `${dockerConfig}/cli-plugins/docker-compose`;
|
||||
return dockerComposePluginPath;
|
||||
}
|
||||
|
||||
private async downloadFile(
|
||||
version: string,
|
||||
installerPath: string,
|
||||
): Promise<void> {
|
||||
if (!version.startsWith("v") && parseInt(version.split(".")[0], 10) >= 2) {
|
||||
version = `v${version}`;
|
||||
}
|
||||
private async downloadFile(
|
||||
version: string,
|
||||
installerPath: string,
|
||||
): Promise<void> {
|
||||
if (!version.startsWith("v") && parseInt(version.split(".")[0], 10) >= 2) {
|
||||
version = `v${version}`;
|
||||
}
|
||||
|
||||
const system = await this.getSystem();
|
||||
const hardware = await this.getHardware();
|
||||
const system = await this.getSystem();
|
||||
const hardware = await this.getHardware();
|
||||
|
||||
const url = `https://github.com/docker/compose/releases/download/${version}/docker-compose-${system}-${hardware}`;
|
||||
await downloadTool(url, installerPath);
|
||||
}
|
||||
const url = `https://github.com/docker/compose/releases/download/${version}/docker-compose-${system}-${hardware}`;
|
||||
await downloadTool(url, installerPath);
|
||||
}
|
||||
|
||||
private async getSystem(): Promise<string> {
|
||||
return this.runCommand("uname -s");
|
||||
}
|
||||
private async getSystem(): Promise<string> {
|
||||
return this.runCommand("uname -s");
|
||||
}
|
||||
|
||||
private async getHardware(): Promise<string> {
|
||||
return this.runCommand("uname -m");
|
||||
}
|
||||
private async getHardware(): Promise<string> {
|
||||
return this.runCommand("uname -m");
|
||||
}
|
||||
|
||||
private async runCommand(command: string): Promise<string> {
|
||||
let output = "";
|
||||
const result = await exec(command, [], {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString();
|
||||
},
|
||||
},
|
||||
});
|
||||
if (result !== 0) {
|
||||
throw new Error(`Failed to run command: ${command}`);
|
||||
}
|
||||
return output.trim();
|
||||
}
|
||||
private async runCommand(command: string): Promise<string> {
|
||||
let output = "";
|
||||
const result = await exec(command, [], {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString();
|
||||
},
|
||||
},
|
||||
});
|
||||
if (result !== 0) {
|
||||
throw new Error(`Failed to run command: ${command}`);
|
||||
}
|
||||
return output.trim();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Import types directly from the module
|
||||
import type { LogLevel as LogLevelType } from "./logger.service.js";
|
||||
@ -9,60 +9,60 @@ const infoMock = vi.fn();
|
||||
const debugMock = vi.fn();
|
||||
|
||||
vi.doMock("@actions/core", () => ({
|
||||
warning: warningMock,
|
||||
info: infoMock,
|
||||
debug: debugMock,
|
||||
warning: warningMock,
|
||||
info: infoMock,
|
||||
debug: debugMock,
|
||||
}));
|
||||
|
||||
// Dynamic import after mock setup
|
||||
const { LoggerService, LogLevel } = await import("./logger.service.js");
|
||||
|
||||
describe("LoggerService", () => {
|
||||
let loggerService: InstanceType<typeof LoggerService>;
|
||||
let loggerService: InstanceType<typeof LoggerService>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
loggerService = new LoggerService();
|
||||
});
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
loggerService = new LoggerService();
|
||||
});
|
||||
|
||||
describe("warn", () => {
|
||||
it("should call warning with the correct message", () => {
|
||||
const message = "This is a warning message";
|
||||
loggerService.warn(message);
|
||||
expect(warningMock).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
describe("warn", () => {
|
||||
it("should call warning with the correct message", () => {
|
||||
const message = "This is a warning message";
|
||||
loggerService.warn(message);
|
||||
expect(warningMock).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
|
||||
describe("info", () => {
|
||||
it("should call info with the correct message", () => {
|
||||
const message = "This is an info message";
|
||||
loggerService.info(message);
|
||||
expect(infoMock).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
describe("info", () => {
|
||||
it("should call info with the correct message", () => {
|
||||
const message = "This is an info message";
|
||||
loggerService.info(message);
|
||||
expect(infoMock).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
|
||||
describe("debug", () => {
|
||||
it("should call debug with the correct message", () => {
|
||||
const message = "This is a debug message";
|
||||
loggerService.debug(message);
|
||||
expect(debugMock).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
describe("debug", () => {
|
||||
it("should call debug with the correct message", () => {
|
||||
const message = "This is a debug message";
|
||||
loggerService.debug(message);
|
||||
expect(debugMock).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getServiceLogger", () => {
|
||||
it("should return the correct logger function for debug level", () => {
|
||||
const logger = loggerService.getServiceLogger(LogLevel.Debug);
|
||||
expect(logger).toBe(loggerService.debug);
|
||||
});
|
||||
describe("getServiceLogger", () => {
|
||||
it("should return the correct logger function for debug level", () => {
|
||||
const logger = loggerService.getServiceLogger(LogLevel.Debug);
|
||||
expect(logger).toBe(loggerService.debug);
|
||||
});
|
||||
|
||||
it("should return the correct logger function for info level", () => {
|
||||
const logger = loggerService.getServiceLogger(LogLevel.Info);
|
||||
expect(logger).toBe(loggerService.info);
|
||||
});
|
||||
it("should return the correct logger function for info level", () => {
|
||||
const logger = loggerService.getServiceLogger(LogLevel.Info);
|
||||
expect(logger).toBe(loggerService.info);
|
||||
});
|
||||
|
||||
it("should default to info level if an unknown level is provided", () => {
|
||||
const logger = loggerService.getServiceLogger("unknown" as LogLevelType);
|
||||
expect(logger).toBe(loggerService.info);
|
||||
});
|
||||
});
|
||||
it("should default to info level if an unknown level is provided", () => {
|
||||
const logger = loggerService.getServiceLogger("unknown" as LogLevelType);
|
||||
expect(logger).toBe(loggerService.info);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,31 +1,31 @@
|
||||
import { debug, info, warning } from "@actions/core";
|
||||
|
||||
export class LoggerService {
|
||||
warn(message: string): void {
|
||||
warning(message);
|
||||
}
|
||||
warn(message: string): void {
|
||||
warning(message);
|
||||
}
|
||||
|
||||
info(message: string): void {
|
||||
info(message);
|
||||
}
|
||||
info(message: string): void {
|
||||
info(message);
|
||||
}
|
||||
|
||||
debug(message: string) {
|
||||
debug(message);
|
||||
}
|
||||
debug(message: string) {
|
||||
debug(message);
|
||||
}
|
||||
|
||||
getServiceLogger(level: LogLevel): (message: string) => void {
|
||||
switch (level) {
|
||||
case LogLevel.Debug:
|
||||
return this.debug;
|
||||
case LogLevel.Info:
|
||||
return this.info;
|
||||
default:
|
||||
return this.info;
|
||||
}
|
||||
}
|
||||
getServiceLogger(level: LogLevel): (message: string) => void {
|
||||
switch (level) {
|
||||
case LogLevel.Debug:
|
||||
return this.debug;
|
||||
case LogLevel.Info:
|
||||
return this.info;
|
||||
default:
|
||||
return this.info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export enum LogLevel {
|
||||
Debug = "debug",
|
||||
Info = "info",
|
||||
Debug = "debug",
|
||||
Info = "info",
|
||||
}
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "ES2024",
|
||||
"module": "NodeNext",
|
||||
"rootDir": "./src",
|
||||
"moduleResolution": "NodeNext",
|
||||
"baseUrl": "./",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"newLine": "lf",
|
||||
"noEmit": true
|
||||
},
|
||||
"exclude": ["./dist", "./node_modules", "./src/**/*.test.ts", "./coverage"],
|
||||
"include": ["./src/**/*"]
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"target": "ES2024",
|
||||
"module": "NodeNext",
|
||||
"rootDir": "./src",
|
||||
"moduleResolution": "NodeNext",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"newLine": "lf",
|
||||
"noEmit": true
|
||||
},
|
||||
"exclude": ["./dist", "./node_modules", "./src/**/*.test.ts", "./coverage"],
|
||||
"include": ["./src/**/*"]
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
include: ["src/**/*.{ts,tsx,js,jsx}"],
|
||||
provider: "v8",
|
||||
},
|
||||
environment: "node",
|
||||
globals: true,
|
||||
},
|
||||
test: {
|
||||
coverage: {
|
||||
include: ["src/**/*.{ts,tsx,js,jsx}"],
|
||||
provider: "v8",
|
||||
},
|
||||
environment: "node",
|
||||
globals: true,
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user