mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-01-10 06:33:06 +08:00
feat: support compose version
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
This commit is contained in:
parent
e7df5df997
commit
cf721e686a
77
.github/workflows/__check-action.yml
vendored
77
.github/workflows/__check-action.yml
vendored
@ -177,3 +177,80 @@ jobs:
|
||||
run: |
|
||||
EXIT_CODE=$(docker compose -f ./test/docker-compose-fail.yml ps service-a --all --format json | jq ".ExitCode")
|
||||
[ "$EXIT_CODE" == "1" ] || (echo "Service service-a did not exit with code 1" && exit 1)
|
||||
|
||||
test-action-with-compose-version:
|
||||
runs-on: ubuntu-latest
|
||||
name: Test with compose version
|
||||
env:
|
||||
DOCKER_COMPOSE_VERSION: "2.29.0"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: "Arrange: ensure original docker compose version is not the expected one"
|
||||
run: |
|
||||
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
|
||||
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
|
||||
|
||||
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" == "$DOCKER_COMPOSE_VERSION" ]; then
|
||||
echo "Docker compose version is already in $DOCKER_COMPOSE_VERSION version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Act
|
||||
uses: ./
|
||||
with:
|
||||
compose-file: "./test/docker-compose.yml"
|
||||
compose-version: "2.29.0"
|
||||
|
||||
- name: "Assert: compose version is used"
|
||||
run: |
|
||||
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
|
||||
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
|
||||
|
||||
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" != "$DOCKER_COMPOSE_VERSION" ]; then
|
||||
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
test-action-with-compose-version-latest:
|
||||
runs-on: ubuntu-latest
|
||||
name: Test with compose version latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: "Arrange: retrieve latest version of docker compose"
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const dockerComposeVersion = (await github.rest.repos.getLatestRelease({
|
||||
owner: "docker",
|
||||
repo: "compose",
|
||||
})).data.tag_name.replace("v", "");
|
||||
|
||||
core.exportVariable('DOCKER_COMPOSE_VERSION', dockerComposeVersion);
|
||||
|
||||
- name: "Arrange: ensure original docker compose version is not the expected one"
|
||||
run: |
|
||||
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
|
||||
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
|
||||
|
||||
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" == "$DOCKER_COMPOSE_VERSION" ]; then
|
||||
echo "Docker compose version is already in $DOCKER_COMPOSE_VERSION version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Act
|
||||
uses: ./
|
||||
with:
|
||||
compose-file: "./test/docker-compose.yml"
|
||||
compose-version: "latest"
|
||||
|
||||
- name: "Assert: compose version is used"
|
||||
run: |
|
||||
CURRENT_DOCKER_COMPOSE_VERSION=$(docker compose version --short)
|
||||
echo "Current docker compose version: $CURRENT_DOCKER_COMPOSE_VERSION"
|
||||
|
||||
if [ "$CURRENT_DOCKER_COMPOSE_VERSION" != "$DOCKER_COMPOSE_VERSION" ]; then
|
||||
echo "Docker compose version is not in $DOCKER_COMPOSE_VERSION version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
11
action.yml
11
action.yml
@ -29,6 +29,17 @@ inputs:
|
||||
description: "Current working directory"
|
||||
required: false
|
||||
default: ${{ github.workspace }}
|
||||
compose-version:
|
||||
description: |
|
||||
Compose version to use.
|
||||
If null (default), it will use the current installed version.
|
||||
If "latest", it will install the latest version.
|
||||
required: false
|
||||
github-token:
|
||||
description: The GitHub token used to create an authenticated client (to fetch the latest version of docker-compose).
|
||||
default: ${{ github.token }}
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: node20
|
||||
main: dist/index.js
|
||||
|
||||
8372
dist/index.js
generated
vendored
8372
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
512
dist/licenses.txt
generated
vendored
512
dist/licenses.txt
generated
vendored
@ -10,6 +10,30 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
|
||||
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
|
||||
@ -35,6 +59,30 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
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.
|
||||
|
||||
@fastify/busboy
|
||||
MIT
|
||||
Copyright Brian White. All rights reserved.
|
||||
@ -57,6 +105,402 @@ 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.
|
||||
|
||||
|
||||
deprecation
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Gregor Martynus 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.
|
||||
|
||||
|
||||
docker-compose
|
||||
MIT
|
||||
MIT License
|
||||
@ -82,6 +526,44 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
once
|
||||
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.
|
||||
|
||||
|
||||
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)
|
||||
@ -132,6 +614,17 @@ 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, 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.
|
||||
|
||||
|
||||
uuid
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
@ -145,6 +638,25 @@ The above copyright notice and this permission notice shall be included in all c
|
||||
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.
|
||||
|
||||
|
||||
wrappy
|
||||
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.
|
||||
|
||||
|
||||
yaml
|
||||
ISC
|
||||
Copyright Eemeli Aro <eemeli@gmail.com>
|
||||
|
||||
87
dist/post.js
generated
vendored
87
dist/post.js
generated
vendored
@ -25607,7 +25607,7 @@ exports["default"] = _default;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4813:
|
||||
/***/ 7080:
|
||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
@ -25622,14 +25622,29 @@ const docker_compose_service_1 = __nccwpck_require__(1390);
|
||||
* The run function for the action.
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
async function run(callback) {
|
||||
async function run() {
|
||||
try {
|
||||
const loggerService = new logger_service_1.LoggerService();
|
||||
const inputService = new input_service_1.InputService();
|
||||
const dockerComposeService = new docker_compose_service_1.DockerComposeService();
|
||||
const inputs = inputService.getInputs();
|
||||
loggerService.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||
await callback(inputs, loggerService, dockerComposeService);
|
||||
const { error, output } = await dockerComposeService.logs({
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
services: inputs.services,
|
||||
});
|
||||
if (error) {
|
||||
loggerService.debug("docker compose error:\n" + error);
|
||||
}
|
||||
loggerService.debug("docker compose logs:\n" + output);
|
||||
await dockerComposeService.down({
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
});
|
||||
loggerService.info("docker compose is down");
|
||||
}
|
||||
catch (error) {
|
||||
(0, core_1.setFailed)(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
@ -25649,45 +25664,41 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.DockerComposeService = void 0;
|
||||
const docker_compose_1 = __nccwpck_require__(3162);
|
||||
class DockerComposeService {
|
||||
async up(inputs) {
|
||||
async up({ upFlags, services, ...optionsInputs }) {
|
||||
const options = {
|
||||
...this.getCommonOptions(inputs),
|
||||
commandOptions: inputs.upFlags,
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: upFlags,
|
||||
};
|
||||
if (inputs.services.length > 0) {
|
||||
await (0, docker_compose_1.upMany)(inputs.services, options);
|
||||
if (services.length > 0) {
|
||||
await (0, docker_compose_1.upMany)(services, options);
|
||||
return;
|
||||
}
|
||||
await (0, docker_compose_1.upAll)(options);
|
||||
}
|
||||
async down(inputs) {
|
||||
async down({ downFlags, ...optionsInputs }) {
|
||||
const options = {
|
||||
...this.getCommonOptions(inputs),
|
||||
commandOptions: inputs.downFlags,
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: downFlags,
|
||||
};
|
||||
await (0, docker_compose_1.down)(options);
|
||||
}
|
||||
async logs(inputs) {
|
||||
async logs({ services, ...optionsInputs }) {
|
||||
const options = {
|
||||
...this.getCommonOptions(inputs),
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
follow: false,
|
||||
};
|
||||
const { err, out } = await (0, docker_compose_1.logs)(inputs.services, options);
|
||||
const { err, out } = await (0, docker_compose_1.logs)(services, options);
|
||||
return {
|
||||
error: err,
|
||||
output: out,
|
||||
};
|
||||
}
|
||||
async version(inputs) {
|
||||
const result = await (0, docker_compose_1.version)(this.getCommonOptions(inputs));
|
||||
return result.data.version;
|
||||
}
|
||||
getCommonOptions(inputs) {
|
||||
getCommonOptions({ composeFiles, composeFlags, cwd, }) {
|
||||
return {
|
||||
config: inputs.composeFiles,
|
||||
config: composeFiles,
|
||||
log: true,
|
||||
composeOptions: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -25702,7 +25713,7 @@ exports.DockerComposeService = DockerComposeService;
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.InputService = exports.InputNames = void 0;
|
||||
exports.InputService = exports.COMPOSE_VERSION_LATEST = exports.InputNames = void 0;
|
||||
const core_1 = __nccwpck_require__(7484);
|
||||
const fs_1 = __nccwpck_require__(9896);
|
||||
const path_1 = __nccwpck_require__(6928);
|
||||
@ -25714,7 +25725,10 @@ var InputNames;
|
||||
InputNames["UpFlags"] = "up-flags";
|
||||
InputNames["DownFlags"] = "down-flags";
|
||||
InputNames["Cwd"] = "cwd";
|
||||
InputNames["ComposeVersion"] = "compose-version";
|
||||
InputNames["GithubToken"] = "github-token";
|
||||
})(InputNames || (exports.InputNames = InputNames = {}));
|
||||
exports.COMPOSE_VERSION_LATEST = "latest";
|
||||
class InputService {
|
||||
getInputs() {
|
||||
return {
|
||||
@ -25724,6 +25738,8 @@ class InputService {
|
||||
upFlags: this.getUpFlags(),
|
||||
downFlags: this.getDownFlags(),
|
||||
cwd: this.getCwd(),
|
||||
composeVersion: this.getComposeVersion(),
|
||||
githubToken: this.getGithubToken(),
|
||||
};
|
||||
}
|
||||
getComposeFiles() {
|
||||
@ -25766,6 +25782,16 @@ class InputService {
|
||||
getCwd() {
|
||||
return (0, core_1.getInput)(InputNames.Cwd);
|
||||
}
|
||||
getComposeVersion() {
|
||||
return ((0, core_1.getInput)(InputNames.ComposeVersion, {
|
||||
required: false,
|
||||
}) || null);
|
||||
}
|
||||
getGithubToken() {
|
||||
return ((0, core_1.getInput)(InputNames.GithubToken, {
|
||||
required: false,
|
||||
}) || null);
|
||||
}
|
||||
}
|
||||
exports.InputService = InputService;
|
||||
|
||||
@ -36183,18 +36209,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
/**
|
||||
* The entrypoint for the post action.
|
||||
*/
|
||||
const runner_1 = __nccwpck_require__(4813);
|
||||
const callback = async (inputs, loggerService, dockerComposeService) => {
|
||||
const { error, output } = await dockerComposeService.logs(inputs);
|
||||
if (error) {
|
||||
loggerService.debug("docker-compose error:\n" + error);
|
||||
}
|
||||
loggerService.debug("docker-compose logs:\n" + output);
|
||||
await dockerComposeService.down(inputs);
|
||||
loggerService.info("docker-compose is down");
|
||||
};
|
||||
const post_runner_1 = __nccwpck_require__(7080);
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
(0, runner_1.run)(callback);
|
||||
(0, post_runner_1.run)();
|
||||
|
||||
})();
|
||||
|
||||
|
||||
251
package-lock.json
generated
251
package-lock.json
generated
@ -11,6 +11,8 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@octokit/action": "^7.0.0",
|
||||
"@ts-dev-tools/core": "^1.6.2",
|
||||
"docker-compose": "^1.1.0"
|
||||
},
|
||||
@ -40,6 +42,15 @@
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/exec": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
|
||||
"integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/io": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/github": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.0.tgz",
|
||||
@ -60,6 +71,45 @@
|
||||
"undici": "^5.25.4"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/io": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz",
|
||||
"integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@actions/tool-cache": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-2.0.1.tgz",
|
||||
"integrity": "sha512-iPU+mNwrbA8jodY8eyo/0S/QqCKDajiR8OxWTnSk/SnYg0sj8Hp4QcUEVC1YFpHWXtrfbQrE13Jz4k4HXJQKcA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"@actions/io": "^1.1.1",
|
||||
"semver": "^6.1.0",
|
||||
"uuid": "^3.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/tool-cache/node_modules/semver": {
|
||||
"version": "6.3.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz",
|
||||
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==",
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/tool-cache/node_modules/uuid": {
|
||||
"version": "3.4.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
|
||||
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
|
||||
"deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"uuid": "bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
|
||||
@ -1523,6 +1573,207 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/action/-/action-7.0.0.tgz",
|
||||
"integrity": "sha512-YVstbUS7vbW0frVGAGtYpSqjbgCwQW1OO0WS+sc/fx0RnW0PP4kPgMCmkgkLAm51WyYTWOOQRA1HuaGTSFgyfQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/auth-action": "^5.1.1",
|
||||
"@octokit/core": "^6.1.2",
|
||||
"@octokit/plugin-paginate-rest": "^11.1.1",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^13.0.1",
|
||||
"@octokit/types": "^13.0.0",
|
||||
"undici": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/auth-token": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.1.tgz",
|
||||
"integrity": "sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/core": {
|
||||
"version": "6.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.2.tgz",
|
||||
"integrity": "sha512-hEb7Ma4cGJGEUNOAVmyfdB/3WirWMg5hDuNFVejGEDFqupeOysLc2sG6HJxY2etBp5YQu5Wtxwi020jS9xlUwg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/auth-token": "^5.0.0",
|
||||
"@octokit/graphql": "^8.0.0",
|
||||
"@octokit/request": "^9.0.0",
|
||||
"@octokit/request-error": "^6.0.1",
|
||||
"@octokit/types": "^13.0.0",
|
||||
"before-after-hook": "^3.0.2",
|
||||
"universal-user-agent": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/endpoint": {
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-10.1.1.tgz",
|
||||
"integrity": "sha512-JYjh5rMOwXMJyUpj028cu0Gbp7qe/ihxfJMLc8VZBMMqSwLgOxDI1911gV4Enl1QSavAQNJcwmwBF9M0VvLh6Q==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^13.0.0",
|
||||
"universal-user-agent": "^7.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/graphql": {
|
||||
"version": "8.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-8.1.1.tgz",
|
||||
"integrity": "sha512-ukiRmuHTi6ebQx/HFRCXKbDlOh/7xEV6QUXaE7MJEKGNAncGI/STSbOkl12qVXZrfZdpXctx5O9X1AIaebiDBg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/request": "^9.0.0",
|
||||
"@octokit/types": "^13.0.0",
|
||||
"universal-user-agent": "^7.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/openapi-types": {
|
||||
"version": "22.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-22.2.0.tgz",
|
||||
"integrity": "sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/plugin-paginate-rest": {
|
||||
"version": "11.3.5",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-11.3.5.tgz",
|
||||
"integrity": "sha512-cgwIRtKrpwhLoBi0CUNuY83DPGRMaWVjqVI/bGKsLJ4PzyWZNaEmhHroI2xlrVXkk6nFv0IsZpOp+ZWSWUS2AQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^13.6.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@octokit/core": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/plugin-rest-endpoint-methods": {
|
||||
"version": "13.2.6",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-13.2.6.tgz",
|
||||
"integrity": "sha512-wMsdyHMjSfKjGINkdGKki06VEkgdEldIGstIEyGX0wbYHGByOwN/KiM+hAAlUwAtPkP3gvXtVQA9L3ITdV2tVw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^13.6.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@octokit/core": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/request": {
|
||||
"version": "9.1.3",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-9.1.3.tgz",
|
||||
"integrity": "sha512-V+TFhu5fdF3K58rs1pGUJIDH5RZLbZm5BI+MNF+6o/ssFNT4vWlCh/tVpF3NxGtP15HUxTTMUbsG5llAuU2CZA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/endpoint": "^10.0.0",
|
||||
"@octokit/request-error": "^6.0.1",
|
||||
"@octokit/types": "^13.1.0",
|
||||
"universal-user-agent": "^7.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/request-error": {
|
||||
"version": "6.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-6.1.5.tgz",
|
||||
"integrity": "sha512-IlBTfGX8Yn/oFPMwSfvugfncK2EwRLjzbrpifNaMY8o/HTEAFqCA1FZxjD9cWvSKBHgrIhc4CSBIzMxiLsbzFQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/types": "^13.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/@octokit/types": {
|
||||
"version": "13.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.6.1.tgz",
|
||||
"integrity": "sha512-PHZE9Z+kWXb23Ndik8MKPirBPziOc0D2/3KH1P+6jK5nGWe96kadZuE4jev2/Jq7FvIfTlT2Ltg8Fv2x1v0a5g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/openapi-types": "^22.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/before-after-hook": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-3.0.2.tgz",
|
||||
"integrity": "sha512-Nik3Sc0ncrMK4UUdXQmAnRtzmNQTAAXmXIopizwZ1W1t8QmfJj+zL4OA2I7XPTPW5z5TDqv4hRo/JzouDJnX3A==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/undici": {
|
||||
"version": "6.20.1",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.20.1.tgz",
|
||||
"integrity": "sha512-AjQF1QsmqfJys+LXfGTNum+qw4S88CojRInG/6t31W/1fk6G59s92bnAvGz5Cmur+kQv2SURXEvvudLmbrE8QA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18.17"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/action/node_modules/universal-user-agent": {
|
||||
"version": "7.0.2",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-7.0.2.tgz",
|
||||
"integrity": "sha512-0JCqzSKnStlRRQfCdowvqy3cy0Dvtlb8xecj/H8JFZuCze4rwjPZQOgvFvn0Ws/usCHQFGpyr+pB9adaGwXn4Q==",
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/@octokit/auth-action": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-5.1.1.tgz",
|
||||
"integrity": "sha512-JE2gbAZcwwVuww88YY7oB97P6eVAPgKZk2US9Uyz+ZUw5ubeRkZqog7G/gUEAjayIFt8s0UX3qNntP1agVcB0g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/auth-token": "^5.0.0",
|
||||
"@octokit/types": "^13.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/auth-action/node_modules/@octokit/auth-token": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-5.1.1.tgz",
|
||||
"integrity": "sha512-rh3G3wDO8J9wSjfI436JUKzHIxq8NaiL0tVeB2aXmG6p/9859aUOAjA9pmSPNGGZxfwmaJ9ozOJImuNVJdpvbA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 18"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/auth-action/node_modules/@octokit/openapi-types": {
|
||||
"version": "22.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-22.2.0.tgz",
|
||||
"integrity": "sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@octokit/auth-action/node_modules/@octokit/types": {
|
||||
"version": "13.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.6.1.tgz",
|
||||
"integrity": "sha512-PHZE9Z+kWXb23Ndik8MKPirBPziOc0D2/3KH1P+6jK5nGWe96kadZuE4jev2/Jq7FvIfTlT2Ltg8Fv2x1v0a5g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/openapi-types": "^22.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@octokit/auth-token": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz",
|
||||
|
||||
@ -74,6 +74,8 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"@octokit/action": "^7.0.0",
|
||||
"@ts-dev-tools/core": "^1.6.2",
|
||||
"docker-compose": "^1.1.0"
|
||||
},
|
||||
|
||||
144
src/index-runner.test.ts
Normal file
144
src/index-runner.test.ts
Normal file
@ -0,0 +1,144 @@
|
||||
import * as core from "@actions/core";
|
||||
import { InputService } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
||||
import * as indexRunner from "./index-runner";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
|
||||
// Mock the external libraries and services used by the action
|
||||
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
|
||||
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
|
||||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
||||
let installMock: jest.SpiedFunction<typeof DockerComposeInstallerService.prototype.install>;
|
||||
let upMock: jest.SpiedFunction<typeof DockerComposeService.prototype.up>;
|
||||
|
||||
describe("run", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
infoMock = jest.spyOn(LoggerService.prototype, "info").mockImplementation();
|
||||
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation();
|
||||
setFailedMock = jest.spyOn(core, "setFailed").mockImplementation();
|
||||
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
|
||||
installMock = jest.spyOn(DockerComposeInstallerService.prototype, "install");
|
||||
upMock = jest.spyOn(DockerComposeService.prototype, "up");
|
||||
});
|
||||
|
||||
it("should install docker compose with specified version", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: "1.29.2",
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
installMock.mockResolvedValue("1.29.2");
|
||||
|
||||
upMock.mockResolvedValue();
|
||||
|
||||
// Act
|
||||
await indexRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(infoMock).toHaveBeenCalledWith("Setting up docker compose version 1.29.2");
|
||||
|
||||
expect(debugMock).toHaveBeenCalledWith(
|
||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":"1.29.2","githubToken":null}'
|
||||
);
|
||||
|
||||
expect(installMock).toHaveBeenCalledWith({
|
||||
composeVersion: "1.29.2",
|
||||
cwd: "/current/working/dir",
|
||||
githubToken: null,
|
||||
});
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: [],
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should bring up docker compose services", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await indexRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
upFlags: [],
|
||||
services: ["web"],
|
||||
});
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should handle errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Test error");
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await indexRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: Test error");
|
||||
});
|
||||
|
||||
it("should handle unknown errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = "Test error";
|
||||
upMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await indexRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith('"Test error"');
|
||||
});
|
||||
});
|
||||
49
src/index-runner.ts
Normal file
49
src/index-runner.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { setFailed } from "@actions/core";
|
||||
import { InputService } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
||||
import { ManualInstallerAdapter } from "./services/installer-adapter/manual-installer-adapter";
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
const inputs = inputService.getInputs();
|
||||
loggerService.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
loggerService.info(`docker compose version: ${installedVersion}`);
|
||||
|
||||
loggerService.info("Bringing up docker compose service(s)");
|
||||
await dockerComposeService.up({
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
upFlags: inputs.upFlags,
|
||||
services: inputs.services,
|
||||
});
|
||||
loggerService.info("docker compose service(s) are up");
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
@ -2,12 +2,13 @@ import * as core from "@actions/core";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
import { InputService } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import { DockerComposeInstallerService } from "./services/docker-compose-installer.service";
|
||||
|
||||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
||||
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
|
||||
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
|
||||
let versionMock: jest.SpiedFunction<typeof DockerComposeService.prototype.version>;
|
||||
let installMock: jest.SpiedFunction<typeof DockerComposeInstallerService.prototype.install>;
|
||||
let upMock: jest.SpiedFunction<typeof DockerComposeService.prototype.up>;
|
||||
|
||||
describe("index", () => {
|
||||
@ -18,7 +19,7 @@ describe("index", () => {
|
||||
infoMock = jest.spyOn(LoggerService.prototype, "info").mockImplementation();
|
||||
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation();
|
||||
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
|
||||
versionMock = jest.spyOn(DockerComposeService.prototype, "version");
|
||||
installMock = jest.spyOn(DockerComposeInstallerService.prototype, "install");
|
||||
upMock = jest.spyOn(DockerComposeService.prototype, "up");
|
||||
});
|
||||
|
||||
@ -30,33 +31,38 @@ describe("index", () => {
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
versionMock.mockResolvedValueOnce("1.2.3");
|
||||
installMock.mockResolvedValue("1.2.3");
|
||||
upMock.mockResolvedValueOnce();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
await require("../src/index");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(1, "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: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}'
|
||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir","composeVersion":null,"githubToken":null}'
|
||||
);
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(3, "Bringing up docker compose service(s)");
|
||||
|
||||
expect(upMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
});
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
expect(infoMock).toHaveBeenNthCalledWith(2, "docker-compose is up");
|
||||
|
||||
expect(infoMock).toHaveBeenNthCalledWith(4, "docker compose service(s) are up");
|
||||
});
|
||||
});
|
||||
|
||||
19
src/index.ts
19
src/index.ts
@ -1,22 +1,7 @@
|
||||
/**
|
||||
* The entrypoint for the action.
|
||||
*/
|
||||
import { RunCallback, run } from "./runner";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
import { Inputs } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
|
||||
const callback: RunCallback = async (
|
||||
inputs: Inputs,
|
||||
loggerService: LoggerService,
|
||||
dockerComposeService: DockerComposeService
|
||||
) => {
|
||||
const composeVersion = await dockerComposeService.version(inputs);
|
||||
loggerService.info(`docker-compose version: ${composeVersion}`);
|
||||
|
||||
await dockerComposeService.up(inputs);
|
||||
loggerService.info("docker-compose is up");
|
||||
};
|
||||
import { run } from "./index-runner";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
run(callback);
|
||||
run();
|
||||
|
||||
171
src/post-runner.test.ts
Normal file
171
src/post-runner.test.ts
Normal file
@ -0,0 +1,171 @@
|
||||
import * as core from "@actions/core";
|
||||
import { InputService } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import * as postRunner from "./post-runner";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
|
||||
// Mock the external libraries and services used by the action
|
||||
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
|
||||
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
|
||||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
||||
let downMock: jest.SpiedFunction<typeof DockerComposeService.prototype.down>;
|
||||
let logsMock: jest.SpiedFunction<typeof DockerComposeService.prototype.logs>;
|
||||
|
||||
describe("run", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
infoMock = jest.spyOn(LoggerService.prototype, "info").mockImplementation();
|
||||
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation();
|
||||
setFailedMock = jest.spyOn(core, "setFailed").mockImplementation();
|
||||
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
|
||||
downMock = jest.spyOn(DockerComposeService.prototype, "down");
|
||||
logsMock = jest.spyOn(DockerComposeService.prototype, "logs");
|
||||
});
|
||||
|
||||
it("should bring down docker compose service(s) and log output", async () => {
|
||||
// Arrange
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
logsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||
|
||||
downMock.mockResolvedValue();
|
||||
|
||||
// Act
|
||||
await postRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
});
|
||||
|
||||
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(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
logsMock.mockResolvedValue({
|
||||
error: "test logs error",
|
||||
output: "test logs output",
|
||||
});
|
||||
|
||||
downMock.mockResolvedValue();
|
||||
|
||||
// Act
|
||||
await postRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
});
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
composeFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
});
|
||||
|
||||
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");
|
||||
});
|
||||
|
||||
// Act
|
||||
await postRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: An error occurred");
|
||||
});
|
||||
|
||||
it("should handle errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = new Error("Test error");
|
||||
downMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await postRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith("Error: Test error");
|
||||
});
|
||||
|
||||
it("should handle unknown errors and call setFailed", async () => {
|
||||
// Arrange
|
||||
const error = "Test error";
|
||||
downMock.mockRejectedValue(error);
|
||||
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["web"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
// Act
|
||||
await postRunner.run();
|
||||
|
||||
// Assert
|
||||
expect(setFailedMock).toHaveBeenCalledWith('"Test error"');
|
||||
});
|
||||
});
|
||||
42
src/post-runner.ts
Normal file
42
src/post-runner.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { setFailed } from "@actions/core";
|
||||
import { InputService } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
const inputs = inputService.getInputs();
|
||||
|
||||
const { error, output } = await dockerComposeService.logs({
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
services: inputs.services,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
loggerService.debug("docker compose error:\n" + error);
|
||||
}
|
||||
|
||||
loggerService.debug("docker compose logs:\n" + output);
|
||||
|
||||
await dockerComposeService.down({
|
||||
composeFiles: inputs.composeFiles,
|
||||
composeFlags: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
downFlags: inputs.downFlags,
|
||||
});
|
||||
|
||||
loggerService.info("docker compose is down");
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
@ -7,8 +7,8 @@ let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
||||
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
|
||||
let infoMock: jest.SpiedFunction<typeof LoggerService.prototype.info>;
|
||||
let downMock: jest.SpiedFunction<typeof DockerComposeService.prototype.down>;
|
||||
let logsMock: jest.SpiedFunction<typeof DockerComposeService.prototype.logs>;
|
||||
let downMock: jest.SpiedFunction<typeof DockerComposeService.prototype.down>;
|
||||
|
||||
describe("post", () => {
|
||||
beforeEach(() => {
|
||||
@ -18,8 +18,8 @@ describe("post", () => {
|
||||
infoMock = jest.spyOn(LoggerService.prototype, "info").mockImplementation();
|
||||
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation();
|
||||
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
|
||||
downMock = jest.spyOn(DockerComposeService.prototype, "down");
|
||||
logsMock = jest.spyOn(DockerComposeService.prototype, "logs");
|
||||
downMock = jest.spyOn(DockerComposeService.prototype, "down");
|
||||
});
|
||||
|
||||
it("calls run when imported", async () => {
|
||||
@ -30,42 +30,34 @@ describe("post", () => {
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
composeVersion: null,
|
||||
githubToken: null,
|
||||
}));
|
||||
|
||||
logsMock.mockResolvedValueOnce({ error: "", output: "log" });
|
||||
logsMock.mockResolvedValue({ error: "", output: "test logs" });
|
||||
downMock.mockResolvedValueOnce();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
await require("../src/post");
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
// Verify that all of the functions were called correctly
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}'
|
||||
);
|
||||
|
||||
expect(logsMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
services: [],
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenNthCalledWith(2, "docker-compose logs:\nlog");
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
downFlags: [],
|
||||
});
|
||||
|
||||
expect(debugMock).toHaveBeenNthCalledWith(1, "docker compose logs:\ntest logs");
|
||||
expect(infoMock).toHaveBeenNthCalledWith(1, "docker compose is down");
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
expect(infoMock).toHaveBeenCalledWith("docker-compose is down");
|
||||
});
|
||||
});
|
||||
|
||||
25
src/post.ts
25
src/post.ts
@ -1,28 +1,7 @@
|
||||
/**
|
||||
* The entrypoint for the post action.
|
||||
*/
|
||||
import { RunCallback, run } from "./runner";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
import { Inputs } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
|
||||
const callback: RunCallback = async (
|
||||
inputs: Inputs,
|
||||
loggerService: LoggerService,
|
||||
dockerComposeService: DockerComposeService
|
||||
) => {
|
||||
const { error, output } = await dockerComposeService.logs(inputs);
|
||||
|
||||
if (error) {
|
||||
loggerService.debug("docker-compose error:\n" + error);
|
||||
}
|
||||
|
||||
loggerService.debug("docker-compose logs:\n" + output);
|
||||
|
||||
await dockerComposeService.down(inputs);
|
||||
|
||||
loggerService.info("docker-compose is down");
|
||||
};
|
||||
import { run } from "./post-runner";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
run(callback);
|
||||
run();
|
||||
|
||||
@ -1,89 +0,0 @@
|
||||
/**
|
||||
* Unit tests for the action's main functionality, src/main.ts
|
||||
*
|
||||
* These should be run as if the action was called from a workflow.
|
||||
* Specifically, the inputs listed in `action.yml` should be set as environment
|
||||
* variables following the pattern `INPUT_<INPUT_NAME>`.
|
||||
*/
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
import { InputService } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import * as runner from "./runner";
|
||||
|
||||
// Mock the action's main function
|
||||
const runMock = jest.spyOn(runner, "run");
|
||||
|
||||
// Mock the external libraries and services used by the action
|
||||
let debugMock: jest.SpiedFunction<typeof LoggerService.prototype.debug>;
|
||||
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>;
|
||||
let getInputsMock: jest.SpiedFunction<typeof InputService.prototype.getInputs>;
|
||||
describe("run", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
debugMock = jest.spyOn(LoggerService.prototype, "debug").mockImplementation();
|
||||
setFailedMock = jest.spyOn(core, "setFailed").mockImplementation();
|
||||
getInputsMock = jest.spyOn(InputService.prototype, "getInputs");
|
||||
});
|
||||
|
||||
it("should call given callback when inputs are valid", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
}));
|
||||
|
||||
const callbackMock = jest.fn();
|
||||
callbackMock.mockResolvedValueOnce(null);
|
||||
|
||||
await runner.run(callbackMock);
|
||||
expect(runMock).toHaveReturned();
|
||||
|
||||
// Verify that all of the functions were called correctly
|
||||
expect(debugMock).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
'inputs: {"composeFiles":["docker-compose.yml"],"services":[],"composeFlags":[],"upFlags":[],"downFlags":[],"cwd":"/current/working/dir"}'
|
||||
);
|
||||
|
||||
expect(callbackMock).toHaveBeenCalledWith(
|
||||
{
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
},
|
||||
expect.any(LoggerService),
|
||||
expect.any(DockerComposeService)
|
||||
);
|
||||
|
||||
expect(setFailedMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets a failed status", async () => {
|
||||
getInputsMock.mockImplementation(() => ({
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
}));
|
||||
|
||||
const callbackMock = jest.fn();
|
||||
callbackMock.mockRejectedValueOnce(new Error("unkown error"));
|
||||
|
||||
await runner.run(callbackMock);
|
||||
expect(runMock).toHaveReturned();
|
||||
|
||||
// Verify that all of the functions were called correctly
|
||||
expect(callbackMock).toHaveBeenCalled();
|
||||
expect(setFailedMock).toHaveBeenNthCalledWith(1, "Error: unkown error");
|
||||
});
|
||||
});
|
||||
@ -1,29 +0,0 @@
|
||||
import { setFailed } from "@actions/core";
|
||||
import { InputService, Inputs } from "./services/input.service";
|
||||
import { LoggerService } from "./services/logger.service";
|
||||
import { DockerComposeService } from "./services/docker-compose.service";
|
||||
|
||||
export type RunCallback = (
|
||||
inputs: Inputs,
|
||||
loggerService: LoggerService,
|
||||
dockerComposeService: DockerComposeService
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* The run function for the action.
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
export async function run(callback: RunCallback): Promise<void> {
|
||||
try {
|
||||
const loggerService = new LoggerService();
|
||||
const inputService = new InputService();
|
||||
const dockerComposeService = new DockerComposeService();
|
||||
|
||||
const inputs = inputService.getInputs();
|
||||
loggerService.debug(`inputs: ${JSON.stringify(inputs)}`);
|
||||
|
||||
await callback(inputs, loggerService, dockerComposeService);
|
||||
} catch (error) {
|
||||
setFailed(`${error instanceof Error ? error : JSON.stringify(error)}`);
|
||||
}
|
||||
}
|
||||
210
src/services/docker-compose-installer.service.test.ts
Normal file
210
src/services/docker-compose-installer.service.test.ts
Normal file
@ -0,0 +1,210 @@
|
||||
import * as dockerCompose from "docker-compose";
|
||||
import { DockerComposeInstallerService } from "./docker-compose-installer.service";
|
||||
import { ManualInstallerAdapter } from "./installer-adapter/manual-installer-adapter";
|
||||
import { MockAgent, setGlobalDispatcher } from "undici";
|
||||
|
||||
jest.mock("docker-compose");
|
||||
|
||||
describe("DockerComposeInstallerService", () => {
|
||||
let mockAgent: MockAgent;
|
||||
let versionMock: jest.SpiedFunction<typeof dockerCompose.version>;
|
||||
let manualInstallerAdapterMock: jest.Mocked<ManualInstallerAdapter>;
|
||||
let service: DockerComposeInstallerService;
|
||||
|
||||
beforeEach(() => {
|
||||
mockAgent = new MockAgent();
|
||||
mockAgent.disableNetConnect();
|
||||
|
||||
versionMock = jest.spyOn(dockerCompose, "version").mockImplementation();
|
||||
|
||||
manualInstallerAdapterMock = {
|
||||
install: jest.fn(),
|
||||
} as unknown as jest.Mocked<ManualInstallerAdapter>;
|
||||
|
||||
service = new DockerComposeInstallerService(manualInstallerAdapterMock);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("install", () => {
|
||||
it("should not install anything when expected version is already installed", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValue({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: "1.2.3",
|
||||
},
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await service.install({
|
||||
composeVersion: "1.2.3",
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken: null,
|
||||
});
|
||||
|
||||
// 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({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: "1.2.3",
|
||||
},
|
||||
});
|
||||
|
||||
const expectedVersion = "1.3.0";
|
||||
versionMock.mockResolvedValueOnce({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: expectedVersion,
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: "linux",
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await service.install({
|
||||
composeVersion: expectedVersion,
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken: null,
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(result).toBe(expectedVersion);
|
||||
expect(manualInstallerAdapterMock.install).toHaveBeenCalledWith(expectedVersion);
|
||||
});
|
||||
|
||||
it("should install the latest version if requested", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: "1.2.3",
|
||||
},
|
||||
});
|
||||
|
||||
const latestVersion = "v1.4.0";
|
||||
|
||||
const mockClient = mockAgent.get("https://api.github.com");
|
||||
mockClient
|
||||
.intercept({
|
||||
path: "/repos/docker/compose/releases/latest",
|
||||
method: "GET",
|
||||
})
|
||||
.reply(
|
||||
200,
|
||||
{
|
||||
tag_name: latestVersion,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
setGlobalDispatcher(mockClient);
|
||||
|
||||
versionMock.mockResolvedValueOnce({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: latestVersion,
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: "linux",
|
||||
});
|
||||
Object.defineProperty(globalThis, "fetch", {
|
||||
value: jest.fn(),
|
||||
});
|
||||
|
||||
// Act
|
||||
const result = await service.install({
|
||||
composeVersion: "latest",
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken: "token",
|
||||
});
|
||||
|
||||
// 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({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: "1.2.3",
|
||||
},
|
||||
});
|
||||
|
||||
// Act & Assert
|
||||
await expect(
|
||||
service.install({
|
||||
composeVersion: "latest",
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken: null,
|
||||
})
|
||||
).rejects.toThrow("GitHub token is required to install the latest version");
|
||||
});
|
||||
|
||||
it("should throw an error on unsupported platforms", async () => {
|
||||
// Arrange
|
||||
versionMock.mockResolvedValueOnce({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: "1.2.3",
|
||||
},
|
||||
});
|
||||
|
||||
const expectedVersion = "1.3.0";
|
||||
versionMock.mockResolvedValueOnce({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: expectedVersion,
|
||||
},
|
||||
});
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: "win32",
|
||||
});
|
||||
|
||||
// Act & Assert
|
||||
await expect(
|
||||
service.install({
|
||||
composeVersion: expectedVersion,
|
||||
cwd: "/path/to/cwd",
|
||||
githubToken: null,
|
||||
})
|
||||
).rejects.toThrow(`Unsupported platform: win32`);
|
||||
|
||||
expect(manualInstallerAdapterMock.install).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
70
src/services/docker-compose-installer.service.ts
Normal file
70
src/services/docker-compose-installer.service.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import * as github from "@actions/github";
|
||||
import { version } from "docker-compose";
|
||||
import { COMPOSE_VERSION_LATEST, Inputs } from "./input.service";
|
||||
import { ManualInstallerAdapter } from "./installer-adapter/manual-installer-adapter";
|
||||
|
||||
export type InstallInputs = {
|
||||
composeVersion: Inputs["composeVersion"];
|
||||
cwd: Inputs["cwd"];
|
||||
githubToken: Inputs["githubToken"];
|
||||
};
|
||||
|
||||
export type VersionInputs = {
|
||||
cwd: Inputs["cwd"];
|
||||
};
|
||||
|
||||
export class DockerComposeInstallerService {
|
||||
constructor(private readonly manualInstallerAdapter: ManualInstallerAdapter) {}
|
||||
|
||||
async install({ composeVersion, cwd, githubToken }: InstallInputs): Promise<string> {
|
||||
const currentVersion = await this.version({ cwd });
|
||||
|
||||
if (!composeVersion) {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
if (currentVersion === composeVersion) {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
if (composeVersion === COMPOSE_VERSION_LATEST) {
|
||||
if (!githubToken) {
|
||||
throw new Error("GitHub token is required to install the latest version");
|
||||
}
|
||||
composeVersion = await this.getLatestVersion(githubToken);
|
||||
}
|
||||
|
||||
await this.installVersion(composeVersion);
|
||||
|
||||
return this.version({ cwd });
|
||||
}
|
||||
|
||||
private async version({ cwd }: VersionInputs): Promise<string> {
|
||||
const result = await version({
|
||||
cwd,
|
||||
});
|
||||
return result.data.version;
|
||||
}
|
||||
|
||||
private async getLatestVersion(githubToken: string): Promise<string> {
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
|
||||
const response = await octokit.rest.repos.getLatestRelease({
|
||||
owner: "docker",
|
||||
repo: "compose",
|
||||
});
|
||||
|
||||
return response.data.tag_name;
|
||||
}
|
||||
|
||||
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,6 +1,5 @@
|
||||
import * as dockerCompose from "docker-compose";
|
||||
import { DockerComposeService } from "./docker-compose.service";
|
||||
import { Inputs } from "./input.service";
|
||||
import { DockerComposeService, DownInputs, LogsInputs, UpInputs } from "./docker-compose.service";
|
||||
|
||||
jest.mock("docker-compose");
|
||||
|
||||
@ -10,7 +9,6 @@ describe("DockerComposeService", () => {
|
||||
let upManyMock: jest.SpiedFunction<typeof dockerCompose.upMany>;
|
||||
let downMock: jest.SpiedFunction<typeof dockerCompose.down>;
|
||||
let logsMock: jest.SpiedFunction<typeof dockerCompose.logs>;
|
||||
let versionMock: jest.SpiedFunction<typeof dockerCompose.version>;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new DockerComposeService();
|
||||
@ -18,7 +16,6 @@ describe("DockerComposeService", () => {
|
||||
upManyMock = jest.spyOn(dockerCompose, "upMany").mockImplementation();
|
||||
downMock = jest.spyOn(dockerCompose, "down").mockImplementation();
|
||||
logsMock = jest.spyOn(dockerCompose, "logs").mockImplementation();
|
||||
versionMock = jest.spyOn(dockerCompose, "version").mockImplementation();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@ -27,16 +24,15 @@ describe("DockerComposeService", () => {
|
||||
|
||||
describe("up", () => {
|
||||
it("should call up with correct options", async () => {
|
||||
const inputs: Inputs = {
|
||||
const upInputs: UpInputs = {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
};
|
||||
|
||||
await service.up(inputs);
|
||||
await service.up(upInputs);
|
||||
|
||||
expect(upAllMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
@ -48,16 +44,15 @@ describe("DockerComposeService", () => {
|
||||
});
|
||||
|
||||
it("should call up with specific services", async () => {
|
||||
const inputs: Inputs = {
|
||||
const upInputs: UpInputs = {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [],
|
||||
upFlags: ["--build"],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
};
|
||||
|
||||
await service.up(inputs);
|
||||
await service.up(upInputs);
|
||||
|
||||
expect(upManyMock).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
@ -71,16 +66,14 @@ describe("DockerComposeService", () => {
|
||||
|
||||
describe("down", () => {
|
||||
it("should call down with correct options", async () => {
|
||||
const inputs: Inputs = {
|
||||
const downInputs: DownInputs = {
|
||||
composeFiles: [],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: ["--volumes", "--remove-orphans"],
|
||||
cwd: "/current/working/dir",
|
||||
};
|
||||
|
||||
await service.down(inputs);
|
||||
await service.down(downInputs);
|
||||
|
||||
expect(downMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
@ -94,18 +87,16 @@ describe("DockerComposeService", () => {
|
||||
|
||||
describe("logs", () => {
|
||||
it("should call logs with correct options", async () => {
|
||||
const inputs: Inputs = {
|
||||
const logsInputs: LogsInputs = {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: ["helloworld2", "helloworld3"],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
};
|
||||
|
||||
logsMock.mockResolvedValue({ exitCode: 0, err: "", out: "logs" });
|
||||
|
||||
await service.logs(inputs);
|
||||
await service.logs(logsInputs);
|
||||
|
||||
expect(dockerCompose.logs).toHaveBeenCalledWith(["helloworld2", "helloworld3"], {
|
||||
composeOptions: [],
|
||||
@ -116,35 +107,4 @@ describe("DockerComposeService", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("version", () => {
|
||||
it("should call version with correct options", async () => {
|
||||
const inputs: Inputs = {
|
||||
composeFiles: ["docker-compose.yml"],
|
||||
services: [],
|
||||
composeFlags: [],
|
||||
upFlags: [],
|
||||
downFlags: [],
|
||||
cwd: "/current/working/dir",
|
||||
};
|
||||
|
||||
versionMock.mockResolvedValue({
|
||||
exitCode: 0,
|
||||
out: "",
|
||||
err: "",
|
||||
data: {
|
||||
version: "1.2.3",
|
||||
},
|
||||
});
|
||||
|
||||
await service.version(inputs);
|
||||
|
||||
expect(versionMock).toHaveBeenCalledWith({
|
||||
composeOptions: [],
|
||||
config: ["docker-compose.yml"],
|
||||
log: true,
|
||||
cwd: "/current/working/dir",
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,41 +5,53 @@ import {
|
||||
logs,
|
||||
upAll,
|
||||
upMany,
|
||||
version,
|
||||
} from "docker-compose";
|
||||
import { Inputs } from "./input.service";
|
||||
|
||||
type OptionsInputs = {
|
||||
composeFiles: Inputs["composeFiles"];
|
||||
composeFlags: Inputs["composeFlags"];
|
||||
cwd: Inputs["cwd"];
|
||||
};
|
||||
|
||||
export type UpInputs = OptionsInputs & { 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(inputs: Inputs): Promise<void> {
|
||||
async up({ upFlags, services, ...optionsInputs }: UpInputs): Promise<void> {
|
||||
const options: IDockerComposeOptions = {
|
||||
...this.getCommonOptions(inputs),
|
||||
commandOptions: inputs.upFlags,
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: upFlags,
|
||||
};
|
||||
|
||||
if (inputs.services.length > 0) {
|
||||
await upMany(inputs.services, options);
|
||||
if (services.length > 0) {
|
||||
await upMany(services, options);
|
||||
return;
|
||||
}
|
||||
|
||||
await upAll(options);
|
||||
}
|
||||
|
||||
async down(inputs: Inputs): Promise<void> {
|
||||
async down({ downFlags, ...optionsInputs }: DownInputs): Promise<void> {
|
||||
const options: IDockerComposeOptions = {
|
||||
...this.getCommonOptions(inputs),
|
||||
commandOptions: inputs.downFlags,
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
commandOptions: downFlags,
|
||||
};
|
||||
|
||||
await down(options);
|
||||
}
|
||||
|
||||
async logs(inputs: Inputs): Promise<{ error: string; output: string }> {
|
||||
async logs({ services, ...optionsInputs }: LogsInputs): Promise<{
|
||||
error: string;
|
||||
output: string;
|
||||
}> {
|
||||
const options: IDockerComposeLogOptions = {
|
||||
...this.getCommonOptions(inputs),
|
||||
...this.getCommonOptions(optionsInputs),
|
||||
follow: false,
|
||||
};
|
||||
|
||||
const { err, out } = await logs(inputs.services, options);
|
||||
const { err, out } = await logs(services, options);
|
||||
|
||||
return {
|
||||
error: err,
|
||||
@ -47,17 +59,16 @@ export class DockerComposeService {
|
||||
};
|
||||
}
|
||||
|
||||
async version(inputs: Inputs): Promise<string> {
|
||||
const result = await version(this.getCommonOptions(inputs));
|
||||
return result.data.version;
|
||||
}
|
||||
|
||||
private getCommonOptions(inputs: Inputs): IDockerComposeOptions {
|
||||
private getCommonOptions({
|
||||
composeFiles,
|
||||
composeFlags,
|
||||
cwd,
|
||||
}: OptionsInputs): IDockerComposeOptions {
|
||||
return {
|
||||
config: inputs.composeFiles,
|
||||
config: composeFiles,
|
||||
log: true,
|
||||
composeOptions: inputs.composeFlags,
|
||||
cwd: inputs.cwd,
|
||||
composeOptions: composeFlags,
|
||||
cwd: cwd,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,5 +271,31 @@ describe("InputService", () => {
|
||||
expect(inputs.cwd).toEqual("cwd");
|
||||
});
|
||||
});
|
||||
|
||||
describe("compose-version", () => {
|
||||
it("should return given compose-version input", () => {
|
||||
getMultilineInputMock.mockImplementation((inputName) => {
|
||||
switch (inputName) {
|
||||
case InputNames.ComposeFile:
|
||||
return ["file1"];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
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");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,6 +9,8 @@ export type Inputs = {
|
||||
upFlags: string[];
|
||||
downFlags: string[];
|
||||
cwd: string;
|
||||
composeVersion: string | null;
|
||||
githubToken: string | null;
|
||||
};
|
||||
|
||||
export enum InputNames {
|
||||
@ -18,8 +20,12 @@ export enum InputNames {
|
||||
UpFlags = "up-flags",
|
||||
DownFlags = "down-flags",
|
||||
Cwd = "cwd",
|
||||
ComposeVersion = "compose-version",
|
||||
GithubToken = "github-token",
|
||||
}
|
||||
|
||||
export const COMPOSE_VERSION_LATEST = "latest";
|
||||
|
||||
export class InputService {
|
||||
getInputs(): Inputs {
|
||||
return {
|
||||
@ -29,6 +35,8 @@ export class InputService {
|
||||
upFlags: this.getUpFlags(),
|
||||
downFlags: this.getDownFlags(),
|
||||
cwd: this.getCwd(),
|
||||
composeVersion: this.getComposeVersion(),
|
||||
githubToken: this.getGithubToken(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -84,4 +92,20 @@ export class InputService {
|
||||
private getCwd(): string {
|
||||
return getInput(InputNames.Cwd);
|
||||
}
|
||||
|
||||
private getComposeVersion(): string | null {
|
||||
return (
|
||||
getInput(InputNames.ComposeVersion, {
|
||||
required: false,
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
|
||||
private getGithubToken(): string | null {
|
||||
return (
|
||||
getInput(InputNames.GithubToken, {
|
||||
required: false,
|
||||
}) || null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
export interface DockerComposeInstallerAdapter {
|
||||
install(version: string): Promise<void>;
|
||||
}
|
||||
119
src/services/installer-adapter/manual-installer-adapter.test.ts
Normal file
119
src/services/installer-adapter/manual-installer-adapter.test.ts
Normal file
@ -0,0 +1,119 @@
|
||||
import { ManualInstallerAdapter } from "./manual-installer-adapter";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as io from "@actions/io";
|
||||
import * as toolCache from "@actions/tool-cache";
|
||||
|
||||
jest.mock("@actions/exec");
|
||||
jest.mock("@actions/io");
|
||||
jest.mock("@actions/tool-cache");
|
||||
|
||||
describe("ManualInstallerAdapter", () => {
|
||||
let mkdirPMock: jest.SpiedFunction<typeof io.mkdirP>;
|
||||
let execMock: jest.SpiedFunction<typeof exec.exec>;
|
||||
let cacheFileMock: jest.SpiedFunction<typeof toolCache.cacheFile>;
|
||||
let downloadToolMock: jest.SpiedFunction<typeof toolCache.downloadTool>;
|
||||
|
||||
let adapter: ManualInstallerAdapter;
|
||||
|
||||
beforeEach(() => {
|
||||
mkdirPMock = jest.spyOn(io, "mkdirP").mockImplementation();
|
||||
execMock = jest.spyOn(exec, "exec").mockImplementation();
|
||||
cacheFileMock = jest.spyOn(toolCache, "cacheFile").mockImplementation();
|
||||
downloadToolMock = jest.spyOn(toolCache, "downloadTool").mockImplementation();
|
||||
|
||||
adapter = new ManualInstallerAdapter();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("install", () => {
|
||||
it("should install docker compose correctly", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
|
||||
// Uname -s
|
||||
execMock.mockResolvedValueOnce(0);
|
||||
|
||||
// Uname -m
|
||||
execMock.mockResolvedValueOnce(0);
|
||||
|
||||
Object.defineProperty(process.env, "HOME", {
|
||||
value: "/home/test",
|
||||
});
|
||||
|
||||
// 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) },
|
||||
});
|
||||
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose--",
|
||||
"/home/test/.docker/cli-plugins/docker-compose"
|
||||
);
|
||||
|
||||
expect(cacheFileMock).toHaveBeenCalledWith(
|
||||
"/home/test/.docker/cli-plugins/docker-compose",
|
||||
"docker-compose",
|
||||
"docker-compose",
|
||||
version
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle version without 'v' prefix", async () => {
|
||||
// Arrange
|
||||
const version = "2.29.0";
|
||||
|
||||
// Uname -s
|
||||
execMock.mockResolvedValueOnce(0);
|
||||
|
||||
// Uname -m
|
||||
execMock.mockResolvedValueOnce(0);
|
||||
|
||||
Object.defineProperty(process.env, "HOME", {
|
||||
value: "/home/test",
|
||||
});
|
||||
|
||||
// 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) },
|
||||
});
|
||||
|
||||
expect(downloadToolMock).toHaveBeenCalledWith(
|
||||
"https://github.com/docker/compose/releases/download/v2.29.0/docker-compose--",
|
||||
"/home/test/.docker/cli-plugins/docker-compose"
|
||||
);
|
||||
});
|
||||
|
||||
it("should throw an error if a command fails", async () => {
|
||||
// Arrange
|
||||
const version = "v2.29.0";
|
||||
|
||||
// Uname -s
|
||||
execMock.mockResolvedValueOnce(1);
|
||||
|
||||
// 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) },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
60
src/services/installer-adapter/manual-installer-adapter.ts
Normal file
60
src/services/installer-adapter/manual-installer-adapter.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { exec } from "@actions/exec";
|
||||
import { mkdirP } from "@actions/io";
|
||||
import { basename } from "path";
|
||||
import { cacheFile, downloadTool } from "@actions/tool-cache";
|
||||
import { DockerComposeInstallerAdapter } from "./docker-compose-installer-adapter";
|
||||
|
||||
export class ManualInstallerAdapter implements DockerComposeInstallerAdapter {
|
||||
async install(version: string): Promise<void> {
|
||||
const dockerComposePluginPath = await this.getDockerComposePluginPath();
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
private async getDockerComposePluginPath(): Promise<string> {
|
||||
const dockerConfig = process.env.DOCKER_CONFIG || `${process.env.HOME}/.docker`;
|
||||
|
||||
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}`;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private async getSystem(): Promise<string> {
|
||||
return this.runCommand("uname -s");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
46
src/services/logger.service.test.ts
Normal file
46
src/services/logger.service.test.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { LoggerService } from "./logger.service";
|
||||
import { debug, info, warning } from "@actions/core";
|
||||
|
||||
jest.mock("@actions/core", () => ({
|
||||
warning: jest.fn(),
|
||||
info: jest.fn(),
|
||||
debug: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("LoggerService", () => {
|
||||
let loggerService: LoggerService;
|
||||
|
||||
beforeEach(() => {
|
||||
loggerService = new LoggerService();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("warn", () => {
|
||||
it("should call warning with the correct message", () => {
|
||||
const message = "This is a warning message";
|
||||
loggerService.warn(message);
|
||||
expect(warning).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
|
||||
describe("info", () => {
|
||||
it("should call info with the correct message", () => {
|
||||
const message = "This is an info message";
|
||||
|
||||
loggerService.info(message);
|
||||
expect(info).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
|
||||
describe("debug", () => {
|
||||
it("should call debug with the correct message", () => {
|
||||
const message = "This is a debug message";
|
||||
|
||||
loggerService.debug(message);
|
||||
expect(debug).toHaveBeenCalledWith(message);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user