├── .eslintignore ├── .eslintrc.json ├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ ├── inclusive-language-check.yml │ └── release.yml ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── .wokeignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DEVELOPMENT.md ├── LICENSE ├── NOTICE ├── README.md ├── SECURITY.md ├── action.yml ├── dist └── index.js ├── jest.config.js ├── package-lock.json ├── package.json ├── run-workflows.sh ├── src ├── carvel_releases_service.ts ├── inputs.ts └── main.ts ├── test ├── e2e │ ├── verify_installed.js │ ├── verify_not_installed.js │ ├── verify_output.js │ └── ytt-example │ │ ├── config.yml │ │ └── values.yml ├── fixtures │ ├── matchers.ts │ └── test_octokit.ts └── unit │ ├── carvel_releases_service.test.ts │ ├── inputs.test.ts │ └── installer.test.ts └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | lib/ 3 | node_modules/ -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2020": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:@typescript-eslint/recommended" 9 | ], 10 | "parser": "@typescript-eslint/parser", 11 | "parserOptions": { 12 | "ecmaVersion": 11, 13 | "sourceType": "module" 14 | }, 15 | "plugins": [ 16 | "@typescript-eslint" 17 | ], 18 | "rules": { 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Enable version updates for npm 4 | - package-ecosystem: 'npm' 5 | # Look for `package.json` and `lock` files in the `root` directory 6 | directory: '/' 7 | # Check the npm registry for updates every day (weekdays) 8 | schedule: 9 | interval: 'monthly' 10 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - develop 8 | - 'releases/*' 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v1 15 | - run: npm ci 16 | - run: npm run all 17 | - name: check build up to date 18 | run: git diff --exit-code --stat HEAD 19 | 20 | test-e2e-all: 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | os: [ubuntu-latest, macos-latest, windows-latest] 25 | runs-on: "${{ matrix.os }}" 26 | steps: 27 | - uses: actions/checkout@v1 28 | - uses: ./ 29 | with: 30 | token: ${{ secrets.GITHUB_TOKEN }} 31 | - run: npm ci 32 | - name: check all apps installed 33 | if: matrix.os != 'windows-latest' 34 | run: npm run verify:installed ytt kbld kapp kwt imgpkg vendir kctrl 35 | - name: check all apps installed (windows) 36 | if: matrix.os == 'windows-latest' 37 | run: npm run verify:installed ytt kbld kapp imgpkg vendir kctrl 38 | - name: check apps are usable 39 | run: | 40 | npm run verify:output "ytt -f ./test/e2e/ytt-example" "greeting: Hello, World" 41 | 42 | test-e2e-specific-apps: 43 | runs-on: ubuntu-latest 44 | steps: 45 | - uses: actions/checkout@v1 46 | - uses: ./ 47 | with: 48 | only: ytt, kbld 49 | token: ${{ secrets.GITHUB_TOKEN }} 50 | - run: npm ci 51 | - name: check specific apps are installs 52 | run: | 53 | npm run verify:installed ytt kbld 54 | npm run verify:not:installed kapp kwt imgpkg vendir kctrl 55 | 56 | test-e2e-exclude-apps: 57 | runs-on: ubuntu-latest 58 | steps: 59 | - uses: actions/checkout@v1 60 | - uses: ./ 61 | with: 62 | exclude: kwt, vendir 63 | token: ${{ secrets.GITHUB_TOKEN }} 64 | - run: npm ci 65 | - name: check specific apps are installed 66 | run: | 67 | npm run verify:installed ytt kbld kapp imgpkg kctrl 68 | npm run verify:not:installed kwt vendir 69 | 70 | test-e2e-specific-version: 71 | runs-on: ubuntu-latest 72 | steps: 73 | - uses: actions/checkout@v1 74 | - uses: ./ 75 | with: 76 | only: ytt 77 | ytt: v0.43.4 78 | token: ${{ secrets.GITHUB_TOKEN }} 79 | - run: npm ci 80 | - name: check specific version is installed 81 | run: npm run verify:output "ytt version" "ytt version 0.43.4" 82 | 83 | test-e2e-no-token: 84 | runs-on: ubuntu-latest 85 | steps: 86 | - uses: actions/checkout@v1 87 | - uses: ./ 88 | with: 89 | only: ytt 90 | - run: npm ci 91 | - name: verify app installed without a token 92 | run: npm run verify:installed ytt 93 | -------------------------------------------------------------------------------- /.github/workflows/inclusive-language-check.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Check inclusive language 3 | 4 | on: 5 | pull_request: 6 | types: ['opened', 'reopened', 'synchronize'] 7 | 8 | jobs: 9 | check-inclusive-language: 10 | uses: carvel-dev/release-scripts/.github/workflows/inclusive-language-check.yml@main 11 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | env: 8 | THIS_RELEASE: ${{ github.event.release.tag_name }} 9 | 10 | jobs: 11 | 12 | # This job updates the major version tag (e.g. "v1") to the published release commit IFF: 13 | # 14 | # 1. The release name is in semver format. 15 | # 2. The release is the "latest" (according to semver), not a patch for an old release. 16 | # 17 | # If these criteria are met, then it will update the major version tag to the release commit. 18 | update_tag: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | 23 | - name: get latest release 24 | env: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | run: | 27 | LATEST_RELEASE=$(hub release | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -r | head -n 1) 28 | echo "latest release: $LATEST_RELEASE" 29 | echo "LATEST_RELEASE=$LATEST_RELEASE" >> $GITHUB_ENV 30 | - name: update major tag 31 | if: env.THIS_RELEASE == env.LATEST_RELEASE 32 | run: | 33 | MAJOR_TAG=$(echo $THIS_RELEASE | grep -Eo '^v[0-9]+') 34 | echo "this release ($THIS_RELEASE) is the latest, updating major tag $MAJOR_TAG" 35 | 36 | git config --global user.email "john_brunton@live.co.uk" 37 | git config --global user.name "John Brunton" 38 | git tag -fa $MAJOR_TAG -m "Update $MAJOR_TAG tag for release $THIS_RELEASE" 39 | git push origin $MAJOR_TAG --force 40 | 41 | - name: skip update 42 | if: env.THIS_RELEASE != env.LATEST_RELEASE 43 | run: echo "this release ($THIS_RELEASE) is not the latest ($LATEST_RELEASE) (perhaps a patch, or not in semver format?), skipping major tag update" 44 | 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependency directory 2 | node_modules 3 | 4 | # Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | lerna-debug.log* 12 | 13 | # Diagnostic reports (https://nodejs.org/api/report.html) 14 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 15 | 16 | # Runtime data 17 | pids 18 | *.pid 19 | *.seed 20 | *.pid.lock 21 | 22 | # Directory for instrumented libs generated by jscoverage/JSCover 23 | lib-cov 24 | 25 | # Coverage directory used by tools like istanbul 26 | coverage 27 | *.lcov 28 | 29 | # nyc test coverage 30 | .nyc_output 31 | 32 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 33 | .grunt 34 | 35 | # Bower dependency directory (https://bower.io/) 36 | bower_components 37 | 38 | # node-waf configuration 39 | .lock-wscript 40 | 41 | # Compiled binary addons (https://nodejs.org/api/addons.html) 42 | build/Release 43 | 44 | # Dependency directories 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Optional REPL history 60 | .node_repl_history 61 | 62 | # Output of 'npm pack' 63 | *.tgz 64 | 65 | # Yarn Integrity file 66 | .yarn-integrity 67 | 68 | # dotenv environment variables file 69 | .env 70 | .env.test 71 | 72 | # parcel-bundler cache (https://parceljs.org/) 73 | .cache 74 | 75 | # next.js build output 76 | .next 77 | 78 | # nuxt.js build output 79 | .nuxt 80 | 81 | # vuepress build output 82 | .vuepress/dist 83 | 84 | # Serverless directories 85 | .serverless/ 86 | 87 | # FuseBox cache 88 | .fusebox/ 89 | 90 | # DynamoDB Local files 91 | .dynamodb/ 92 | 93 | # OS metadata 94 | .DS_Store 95 | Thumbs.db 96 | 97 | # Ignore built ts files 98 | tests/runner/* 99 | lib/**/* 100 | 101 | .idea -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | lib/ 3 | node_modules/ -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": false, 6 | "singleQuote": true, 7 | "trailingComma": "none", 8 | "bracketSpacing": false, 9 | "arrowParens": "avoid", 10 | "parser": "typescript" 11 | } -------------------------------------------------------------------------------- /.wokeignore: -------------------------------------------------------------------------------- 1 | # out of our control 2 | dist/ 3 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | https://carvel.dev/shared/docs/latest/code-of-conduct/ 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | https://carvel.dev/shared/docs/latest/contributing/ 2 | -------------------------------------------------------------------------------- /DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | ## Build and test 4 | 5 | Run unit tests: 6 | 7 | jest 8 | 9 | Build all (format, build, pack, test): 10 | 11 | npm run all 12 | 13 | ## Running a workflow locally 14 | 15 | If you want to run the e2e tests locally to try out the action, install [act](https://github.com/nektos/act). 16 | 17 | You can then run all workflows like this: 18 | 19 | ./run-workflows.sh 20 | 21 | Typically, if you just want to try out the action, it's sufficient to run a single e2e test like this: 22 | 23 | npm run build && npm run pack && act -j test-e2e-specific-apps 24 | 25 | This will execute the test-e2e-specific-apps job, which runs the action configured to install a couple of apps (ytt and kbld). 26 | 27 | Note: remember to run `build` and `pack` first, as the workflow will act upon the `dist/index.js` file. 28 | 29 | ## Submitting PRs 30 | 31 | Before submitting a PR, you need to: 32 | 33 | 1. Format your code. 34 | 2. Update `dist/index.js`. 35 | 36 | You can do this with `npm run all`. 37 | 38 | If you forget, the `check build up to date` build step will fail. 39 | 40 | ## Releasing 41 | 42 | 1. Publish a release to the Marketplace with a semver name, e.g. `v1.2.3`. (Note: the `v` prefix is important, as are the minor and patch versions. `1.2.3` and `v1.2` aren't valid if you want the automated workflow in #2 to do its thing.) 43 | 2. If this is the latest release per semver naming then the [release workflow](https://github.com/carvel-dev/setup-action/actions?query=workflow%3Arelease) will automatically update the major tag for the release (e.g. if you release v1.2.3 it will update the `v1` tag to point to the same commit as `v1.2.3`). 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | carvel-setup-action 2 | 3 | Copyright (c) 2019-Present Pivotal Software, Inc. All Rights Reserved. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # carvel-setup-action 2 | 3 | [![Build Status](https://github.com/carvel-dev/setup-action/workflows/build/badge.svg?branch=develop)](https://github.com/carvel-dev/setup-action/actions?query=branch%3Adevelop+workflow%3Abuild) 4 | [![Release Status](https://github.com/carvel-dev/setup-action/workflows/release/badge.svg)](https://github.com/carvel-dev/setup-action/actions?query=workflow%3Arelease) 5 | 6 | A [Github Action](https://github.com/features/actions) to install [Carvel apps](https://carvel.dev/) (ytt, kbld, kapp, kwt, imgpkg, vendir and kctrl). 7 | 8 | - Slack: [#carvel in Kubernetes slack](https://slack.kubernetes.io) 9 | 10 | ## Usage 11 | 12 | By default, installs latest versions of `ytt`, `kbld`, `kapp`, `kwt`, `imgpkg`, `vendir` and `kctrl`: 13 | 14 | ```yaml 15 | steps: 16 | - uses: carvel-dev/setup-action@v2 17 | - run: | 18 | ytt version 19 | kbld version 20 | ``` 21 | 22 | `carvel-setup-action` uses the GitHub API to find information about latest releases. To avoid [rate limits](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting) it is recommended you pass a [token](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token): 23 | 24 | ```yaml 25 | steps: 26 | - uses: carvel-dev/setup-action@v2 27 | with: 28 | token: ${{ secrets.GITHUB_TOKEN }} 29 | - run: | 30 | ytt version 31 | kbld version 32 | ``` 33 | 34 | To install only specific apps: 35 | 36 | ```yaml 37 | steps: 38 | - uses: carvel-dev/setup-action@v2 39 | with: 40 | only: ytt, kbld 41 | - run: | 42 | ytt version 43 | kbld version 44 | ``` 45 | 46 | To exclude specific apps: 47 | 48 | ```yaml 49 | steps: 50 | - uses: carvel-dev/setup-action@v2 51 | with: 52 | exclude: kwt, vendir 53 | - run: | 54 | ytt version 55 | kbld version 56 | ``` 57 | 58 | To use a specific version of an app: 59 | 60 | ```yaml 61 | steps: 62 | - uses: carvel-dev/setup-action@v2 63 | with: 64 | only: ytt, kbld 65 | kbld: v0.28.0 66 | - run: | 67 | ytt version 68 | kbld version 69 | ``` 70 | 71 | ## Node version support 72 | 73 | Version `v2` requires a Node 20 runner. If you're using older self-hosted runners, you can still use `v1` for Node 16 support. 74 | 75 | ## Development 76 | 77 | See [DEVELOPMENT](https://github.com/carvel-dev/setup-action/blob/develop/DEVELOPMENT.md). 78 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | https://carvel.dev/shared/docs/latest/security-policy/ 2 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: carvel-setup-action 2 | description: Install Carvel apps (ytt, kbld, kapp, kwt, imgpkg and vendir) 3 | author: The Carvel Authors 4 | branding: 5 | color: 'green' 6 | icon: 'play' 7 | inputs: 8 | token: 9 | description: Github token to use to avoid rate limits 10 | required: false 11 | default: "" 12 | only: 13 | description: List apps to download if you don't need all 14 | required: false 15 | default: "" 16 | exclude: 17 | description: List apps to exclude if you want most but not all 18 | required: false 19 | default: "" 20 | ytt: 21 | description: ytt version 22 | required: false 23 | default: latest 24 | kbld: 25 | description: kbld version 26 | required: false 27 | default: latest 28 | kapp: 29 | description: kapp version 30 | required: false 31 | default: latest 32 | kwt: 33 | description: kwt version 34 | required: false 35 | default: latest 36 | imgpkg: 37 | description: imgpkg version 38 | required: false 39 | default: latest 40 | vendir: 41 | description: vendir version 42 | required: false 43 | default: latest 44 | kctrl: 45 | description: kctrl version 46 | required: false 47 | default: latest 48 | runs: 49 | using: 'node20' 50 | main: 'dist/index.js' 51 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | clearMocks: true, 3 | moduleFileExtensions: ['js', 'ts'], 4 | testEnvironment: 'node', 5 | testMatch: ['**/*.test.ts', 'test/fixtures/*.ts'], 6 | testRunner: 'jest-circus/runner', 7 | transform: { 8 | '^.+\\.ts$': 'ts-jest' 9 | }, 10 | verbose: true 11 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "carvel-setup-action", 3 | "private": true, 4 | "description": "A Github Action to install Carvel apps (such as ytt, kbld, kapp, etc.)", 5 | "main": "lib/main.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "format": "prettier --write **/*.ts", 9 | "format-check": "prettier --check **/*.ts", 10 | "lint": "eslint src/**/*.ts", 11 | "pack": "ncc build", 12 | "test": "jest", 13 | "all": "npm run build && npm run format && npm run lint && npm run pack && npm test", 14 | "verify:installed": "node test/e2e/verify_installed.js", 15 | "verify:not:installed": "node test/e2e/verify_not_installed.js", 16 | "verify:version": "node test/e2e/verify_version.js", 17 | "verify:output": "node test/e2e/verify_output.js" 18 | }, 19 | "dependencies": { 20 | "@actions/core": "^1.9.1", 21 | "@actions/github": "^5.0.1", 22 | "@jbrunton/gha-installer": "^0.5.7" 23 | }, 24 | "devDependencies": { 25 | "@types/jest": "^27.4.1", 26 | "@types/node": "^18.11.18", 27 | "@typescript-eslint/eslint-plugin": "^5.62.0", 28 | "@typescript-eslint/parser": "^5.39.0", 29 | "@vercel/ncc": "^0.38.0", 30 | "eslint": "^8.50.0", 31 | "eslint-plugin-github": "^4.4.1", 32 | "eslint-plugin-jest": "^27.2.1", 33 | "jest": "^27.5.1", 34 | "jest-circus": "^27.5.1", 35 | "jest-mock-extended": "^3.0.1", 36 | "js-yaml": "^4.1.0", 37 | "prettier": "^3.3.2", 38 | "shelljs": "^0.8.5", 39 | "ts-jest": "^27.1.4", 40 | "typescript": "^4.8.4" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /run-workflows.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Build and run the test pipeline with act: https://github.com/nektos/act 6 | # If you run into rate limits, make sure you set a valid GITHUB_TOKEN environment variable. 7 | npm run build && npm run pack && act -s GITHUB_TOKEN 8 | -------------------------------------------------------------------------------- /src/carvel_releases_service.ts: -------------------------------------------------------------------------------- 1 | import { 2 | GitHubReleasesService, 3 | Octokit, 4 | AppInfo, 5 | ReposListReleasesParameters, 6 | DownloadInfo, 7 | GitHubDownloadMeta 8 | } from '@jbrunton/gha-installer' 9 | import { 10 | ActionsCore, 11 | Environment, 12 | FileSystem 13 | } from '@jbrunton/gha-installer/lib/interfaces' 14 | import * as crypto from 'crypto' 15 | import * as path from 'path' 16 | import * as fs from 'fs' 17 | import * as core from '@actions/core' 18 | 19 | export class CarvelReleasesService extends GitHubReleasesService { 20 | private _fs: FileSystem 21 | 22 | constructor( 23 | core: ActionsCore, 24 | env: Environment, 25 | fs: FileSystem, 26 | octokit: Octokit 27 | ) { 28 | super(core, env, octokit, {repo: getRepo, assetName: getAssetName}) 29 | this._fs = fs 30 | } 31 | 32 | onFileDownloaded( 33 | path: string, 34 | info: DownloadInfo, 35 | core: ActionsCore 36 | ): void { 37 | this.verifyChecksum(path, info, core) 38 | } 39 | 40 | private verifyChecksum( 41 | downloadPath: string, 42 | info: DownloadInfo, 43 | core: ActionsCore 44 | ) { 45 | const digest = this.computeDigest(downloadPath) 46 | const assetName = path.basename(info.url) 47 | const expectedChecksum = `${digest} ./${assetName}` 48 | const releaseNotes = info.meta.release.body 49 | if (releaseNotes && releaseNotes.includes(expectedChecksum)) { 50 | core.info(`✅ Verified checksum: "${expectedChecksum}"`) 51 | } else { 52 | throw new Error( 53 | `Unable to verify checksum for ${assetName}. Expected to find "${expectedChecksum}" in release notes.` 54 | ) 55 | } 56 | } 57 | 58 | private computeDigest(downloadPath: string): string { 59 | const data = this._fs.readFileSync(downloadPath) 60 | const digest = crypto.createHash('sha256').update(data).digest('hex') 61 | return digest 62 | } 63 | 64 | static create(octokit: Octokit): CarvelReleasesService { 65 | return new CarvelReleasesService(core, process, fs, octokit) 66 | } 67 | } 68 | 69 | export function getRepo(app: AppInfo): ReposListReleasesParameters { 70 | return { 71 | owner: 'carvel-dev', 72 | repo: getRepoName(app) 73 | } 74 | } 75 | 76 | function getRepoName(app: AppInfo): string { 77 | if (app.name === 'kctrl') { 78 | return 'kapp-controller' 79 | } 80 | return `${app.name}` 81 | } 82 | 83 | export function getAssetName(platform: string, app: AppInfo): string { 84 | return `${app.name}-${getAssetSuffix(platform)}` 85 | } 86 | 87 | function getAssetSuffix(platform: string): string { 88 | switch (platform) { 89 | case 'win32': 90 | return 'windows-amd64.exe' 91 | case 'darwin': 92 | return 'darwin-amd64' 93 | default: 94 | return 'linux-amd64' 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/inputs.ts: -------------------------------------------------------------------------------- 1 | import {ActionsCore, Environment} from '@jbrunton/gha-installer/lib/interfaces' 2 | import {AppInfo} from '@jbrunton/gha-installer' 3 | 4 | export const carvelApps = [ 5 | 'ytt', 6 | 'kbld', 7 | 'kapp', 8 | 'kwt', 9 | 'imgpkg', 10 | 'vendir', 11 | 'kctrl' 12 | ] 13 | 14 | export class Inputs { 15 | private _apps?: AppInfo[] 16 | private _core: ActionsCore 17 | private _env: Environment 18 | 19 | constructor(core: ActionsCore, env: Environment) { 20 | this._core = core 21 | this._env = env 22 | } 23 | 24 | public getAppsToDownload(): AppInfo[] { 25 | const apps = this.includeAppsList() 26 | 27 | if (apps.length == 0) { 28 | // if no options specified, download all 29 | apps.push(...this.getAllApps()) 30 | } 31 | 32 | this._apps = apps.map((appName: string) => { 33 | if (!carvelApps.includes(appName)) { 34 | throw Error(`Unknown app: ${appName}`) 35 | } 36 | return {name: appName, version: this._core.getInput(appName)} 37 | }) 38 | 39 | return this._apps 40 | } 41 | 42 | private getAllApps(): string[] { 43 | if (this._env.platform == 'win32') { 44 | // kwt isn't available for Windows 45 | return carvelApps.filter(app => app != 'kwt') 46 | } 47 | return carvelApps 48 | } 49 | 50 | private includeAppsList(): string[] { 51 | const apps = this.parseAppList('only') 52 | 53 | if (apps.length == 0) { 54 | // if no `only` option specified, include all by default 55 | apps.push(...this.getAllApps()) 56 | } 57 | 58 | const excludeApps = this.parseAppList('exclude') 59 | 60 | return apps.filter(appName => !excludeApps.includes(appName)) 61 | } 62 | 63 | private parseAppList(input: string): string[] { 64 | return this._core 65 | .getInput(input) 66 | .split(',') 67 | .map((appName: string) => appName.trim()) 68 | .filter((appName: string) => appName != '') 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import * as core from '@actions/core' 2 | import * as github from '@actions/github' 3 | import {GitHub} from '@actions/github/lib/utils' 4 | import {Inputs} from './inputs' 5 | import {Installer, Octokit} from '@jbrunton/gha-installer' 6 | import {CarvelReleasesService} from './carvel_releases_service' 7 | 8 | async function run(): Promise { 9 | const octokit = createOctokit() 10 | const releasesService = CarvelReleasesService.create(octokit) 11 | const installer = Installer.create(releasesService) 12 | 13 | try { 14 | console.time('download apps') 15 | const apps = new Inputs(core, process).getAppsToDownload() 16 | await installer.installAll(apps) 17 | console.timeEnd('download apps') 18 | } catch (error) { 19 | if (error instanceof Error) { 20 | core.setFailed(error.message) 21 | } else { 22 | core.setFailed('Unexpected error occurred') 23 | } 24 | } 25 | } 26 | 27 | function createOctokit(): Octokit { 28 | const token = core.getInput('token') 29 | if (token) { 30 | return github.getOctokit(token) 31 | } else { 32 | core.warning( 33 | 'No token set, you may experience rate limiting. Set "token: ${{ secrets.GITHUB_TOKEN }}" if you have problems.' 34 | ) 35 | return new GitHub() 36 | } 37 | } 38 | 39 | run() 40 | -------------------------------------------------------------------------------- /test/e2e/verify_installed.js: -------------------------------------------------------------------------------- 1 | const shell = require('shelljs') 2 | 3 | const apps = process.argv.slice(2) 4 | if (apps.length < 1) { 5 | console.log('❌ Error: specify apps to check') 6 | process.exit(1) 7 | } 8 | 9 | for (app of apps) { 10 | if (shell.which(app)) { 11 | console.log(`✅ Verified ${app} is installed`) 12 | } else { 13 | console.log(`❌ Failure: ${app} is not installed`) 14 | process.exit(1) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/e2e/verify_not_installed.js: -------------------------------------------------------------------------------- 1 | const shell = require('shelljs') 2 | 3 | const apps = process.argv.slice(2) 4 | if (apps.length < 1) { 5 | console.log('❌ Error: specify apps to check') 6 | process.exit(1) 7 | } 8 | 9 | for (app of apps) { 10 | if (!shell.which(app)) { 11 | console.log(`✅ Verified ${app} is not installed`) 12 | } else { 13 | console.log(`❌ Failure: expected ${app} to not be installed.`) 14 | process.exit(1) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/e2e/verify_output.js: -------------------------------------------------------------------------------- 1 | const shell = require('shelljs') 2 | 3 | if (process.argv.length != 4) { 4 | console.log ('❌ Error: command and expected output must be given') 5 | process.exit(1) 6 | } 7 | 8 | const command = process.argv[2] 9 | const expectedOutput = process.argv[3] 10 | 11 | const output = shell.exec(command, { silent: true }).stdout.trim() 12 | if (output == expectedOutput) { 13 | console.log(`✅ Verified output from "${command}" was "${output}"`) 14 | } else { 15 | console.log(`❌ Failure: expected output from "${command}" to be "${expectedOutput}", was "${output}"`) 16 | process.exit(1) 17 | } 18 | -------------------------------------------------------------------------------- /test/e2e/ytt-example/config.yml: -------------------------------------------------------------------------------- 1 | #@ load("@ytt:data", "data") 2 | greeting: #@ "Hello, {audience}".format(audience = data.values.audience) 3 | -------------------------------------------------------------------------------- /test/e2e/ytt-example/values.yml: -------------------------------------------------------------------------------- 1 | #@data/values 2 | --- 3 | audience: "World" 4 | -------------------------------------------------------------------------------- /test/fixtures/matchers.ts: -------------------------------------------------------------------------------- 1 | import { Matcher } from 'jest-mock-extended'; 2 | import { equals } from 'expect/build/jasmineUtils'; 3 | 4 | export const isEqual = (expectedValue?: T) => 5 | new Matcher((actualValue?: T) => { 6 | return equals(actualValue, expectedValue); 7 | }, "isEqual()"); 8 | -------------------------------------------------------------------------------- /test/fixtures/test_octokit.ts: -------------------------------------------------------------------------------- 1 | import { mockDeep, DeepMockProxy } from 'jest-mock-extended'; 2 | import { isEqual } from './matchers' 3 | import { ReposListReleasesParameters } from '@jbrunton/gha-installer'; 4 | import { ReposListReleasesItem, Octokit, OctokitResponse, ReposListReleasesResponseData } from '@jbrunton/gha-installer/lib/octokit'; 5 | 6 | interface TestMethods { 7 | stubListReleasesResponse(params: ReposListReleasesParameters, releases: Array): void 8 | } 9 | 10 | export type TestOctokit = DeepMockProxy & TestMethods 11 | 12 | export function createTestOctokit(): TestOctokit { 13 | const octokit: any = mockDeep() 14 | octokit.stubListReleasesResponse = stubListReleasesResponse 15 | return octokit as TestOctokit 16 | } 17 | 18 | function stubListReleasesResponse(this: TestOctokit, params: ReposListReleasesParameters, releases: Array) { 19 | const response = { data: releases } as OctokitResponse 20 | this.rest.repos.listReleases 21 | .calledWith(isEqual(params)) 22 | .mockReturnValue(Promise.resolve(response as any)) 23 | } 24 | -------------------------------------------------------------------------------- /test/unit/carvel_releases_service.test.ts: -------------------------------------------------------------------------------- 1 | import { AppInfo } from "@jbrunton/gha-installer"; 2 | import { getAssetName, getRepo } from "../../src/carvel_releases_service"; 3 | 4 | describe('CarvelReleasesService', () => { 5 | const kbldInfo: AppInfo = { 6 | name: "kbld", 7 | version: "latest" 8 | }; 9 | 10 | const kctrlInfo: AppInfo = { 11 | name: "kctrl", 12 | version: "latest" 13 | }; 14 | 15 | describe('getRepo', () => { 16 | it("returns the name of the repo for the app", () => { 17 | expect(getRepo(kbldInfo)).toEqual({ 18 | owner: "carvel-dev", 19 | repo: "kbld" 20 | }) 21 | // kctrl is a special case 22 | expect(getRepo(kctrlInfo)).toEqual({ 23 | owner: "carvel-dev", 24 | repo: "kapp-controller" 25 | }) 26 | }) 27 | }) 28 | 29 | describe('getAssetName', () => { 30 | it("returns the asset name for the given platform", () => { 31 | expect(getAssetName("darwin", kbldInfo)).toEqual("kbld-darwin-amd64") 32 | expect(getAssetName("win32", kbldInfo)).toEqual("kbld-windows-amd64.exe") 33 | expect(getAssetName("linux", kbldInfo)).toEqual("kbld-linux-amd64") 34 | }) 35 | }) 36 | }); 37 | -------------------------------------------------------------------------------- /test/unit/inputs.test.ts: -------------------------------------------------------------------------------- 1 | import { Inputs, carvelApps } from '../../src/inputs' 2 | import { mock } from 'jest-mock-extended'; 3 | import { ActionsCore } from '@jbrunton/gha-installer/lib/interfaces'; 4 | 5 | describe('Inputs', () => { 6 | function createInputs(platform: string, inputs: {[key: string]: string} = {}): Inputs { 7 | const core = mock() 8 | core.getInput.calledWith('only').mockReturnValue(inputs.only || '') 9 | core.getInput.calledWith('exclude').mockReturnValue(inputs.exclude || '') 10 | for (let appName of carvelApps) { 11 | core.getInput.calledWith(appName).mockReturnValue(inputs[appName] || 'latest') 12 | } 13 | return new Inputs(core, { platform: platform }) 14 | } 15 | 16 | describe('getAppsToDownload()', () => { 17 | test('defaults to all', () => { 18 | const inputs = createInputs("linux") 19 | 20 | const apps = inputs.getAppsToDownload() 21 | 22 | expect(apps).toEqual([ 23 | { name: "ytt", "version": "latest" }, 24 | { name: "kbld", "version": "latest" }, 25 | { name: "kapp", "version": "latest" }, 26 | { name: "kwt", "version": "latest" }, 27 | { name: "imgpkg", "version": "latest" }, 28 | { name: "vendir", "version": "latest" }, 29 | { name: "kctrl", "version": "latest" } 30 | ]) 31 | }) 32 | 33 | test('excludes kwt for windows', () => { 34 | const inputs = createInputs("win32") 35 | 36 | const apps = inputs.getAppsToDownload() 37 | 38 | expect(apps).toEqual([ 39 | { name: "ytt", "version": "latest" }, 40 | { name: "kbld", "version": "latest" }, 41 | { name: "kapp", "version": "latest" }, 42 | { name: "imgpkg", "version": "latest" }, 43 | { name: "vendir", "version": "latest" }, 44 | { name: "kctrl", "version": "latest" }, 45 | ]) 46 | }) 47 | 48 | test('allows version overrides', () => { 49 | const inputs = createInputs("linux", { ytt: "0.28.0" }) 50 | 51 | const apps = inputs.getAppsToDownload() 52 | 53 | expect(apps).toEqual([ 54 | { name: "ytt", "version": "0.28.0" }, 55 | { name: "kbld", "version": "latest" }, 56 | { name: "kapp", "version": "latest" }, 57 | { name: "kwt", "version": "latest" }, 58 | { name: "imgpkg", "version": "latest" }, 59 | { name: "vendir", "version": "latest" }, 60 | { name: "kctrl", "version": "latest" } 61 | ]) 62 | }) 63 | 64 | test('limits apps to "only" list', () => { 65 | const inputs = createInputs("linux", { only: "ytt, kbld" }) 66 | 67 | const apps = inputs.getAppsToDownload() 68 | 69 | expect(apps).toEqual([ 70 | { name: "ytt", "version": "latest" }, 71 | { name: "kbld", "version": "latest" } 72 | ]) 73 | }) 74 | 75 | test('allows for app list override', () => { 76 | const inputs = createInputs("linux", { only: "ytt, kbld", ytt: "0.28.0" }) 77 | 78 | const apps = inputs.getAppsToDownload() 79 | 80 | expect(apps).toEqual([ 81 | { name: "ytt", "version": "0.28.0" }, 82 | { name: "kbld", "version": "latest" } 83 | ]) 84 | }) 85 | 86 | test('excludes apps from "exclude" list', () => { 87 | const inputs = createInputs("linux", { exclude: "ytt, kwt", kapp: "0.34.0" }) 88 | 89 | const apps = inputs.getAppsToDownload() 90 | 91 | expect(apps).toEqual([ 92 | { name: "kbld", "version": "latest" }, 93 | { name: "kapp", "version": "0.34.0" }, 94 | { name: "imgpkg", "version": "latest" }, 95 | { name: "vendir", "version": "latest" }, 96 | { name: "kctrl", "version": "latest" } 97 | ]) 98 | }) 99 | 100 | test('validates app names', () => { 101 | const inputs = createInputs("linux", { only: "ytt, kbl" }) 102 | expect(() => inputs.getAppsToDownload()).toThrowError("Unknown app: kbl") 103 | }) 104 | }) 105 | }) 106 | -------------------------------------------------------------------------------- /test/unit/installer.test.ts: -------------------------------------------------------------------------------- 1 | import { mock, MockProxy } from 'jest-mock-extended' 2 | import { Installer, DownloadService, GitHubDownloadMeta } from '@jbrunton/gha-installer' 3 | import { ActionsCore, ActionsToolCache, FileSystem } from '@jbrunton/gha-installer/lib/interfaces' 4 | import { ReposListReleasesItem } from '@jbrunton/gha-installer/lib/octokit' 5 | import { CarvelReleasesService } from '../../src/carvel_releases_service' 6 | import { TestOctokit, createTestOctokit } from '../fixtures/test_octokit' 7 | 8 | const assetNames = { 9 | linux: "ytt-linux-amd64", 10 | win32: "ytt-windows-amd64.exe" 11 | } 12 | const downloadUrls = { 13 | linux: "https://example.com/carvel-dev/ytt/releases/download/0.28.0/ytt-linux-amd64", 14 | win32: "https://example.com/carvel-dev/ytt/releases/download/0.28.0/ytt-windows-amd64.exe" 15 | } 16 | const downloadPaths = { 17 | linux: "/downloads/ytt-linux-amd64", 18 | win32: "/downloads/ytt-windows-amd64.exe" 19 | } 20 | const binPaths = { 21 | linux: "/bin/ytt", 22 | win32: "/bin/ytt.exe" 23 | } 24 | const expectedContent = "foo bar baz" 25 | const expectedChecksums = { 26 | linux: '"dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7 ./ytt-linux-amd64"', 27 | win32: '"dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7 ./ytt-windows-amd64.exe"' 28 | } 29 | 30 | describe('Installer', () => { 31 | let octokit: TestOctokit 32 | let core: MockProxy 33 | let cache: MockProxy 34 | let fs: MockProxy 35 | 36 | beforeEach(() => { 37 | core = mock() 38 | cache = mock() 39 | fs = mock() 40 | octokit = createTestOctokit() 41 | octokit.stubListReleasesResponse({ owner: 'carvel-dev', repo: 'ytt' }, [ 42 | releaseJsonFor('ytt', '0.10.1'), // a more recent security patch 43 | releaseJsonFor('ytt', '0.28.0'), // the latest version by semver number 44 | releaseJsonFor('ytt', '0.27.0') 45 | ]) 46 | }) 47 | 48 | function stubCacheMiss(platform: 'linux' | 'win32') { 49 | const binName = platform == 'win32' ? 'ytt.exe' : 'ytt' 50 | // stub the download itself 51 | cache.downloadTool 52 | .calledWith(downloadUrls[platform]) 53 | .mockReturnValue(Promise.resolve(downloadPaths[platform])) 54 | // stub caching the downloaded file 55 | cache.cacheFile 56 | .calledWith(downloadPaths[platform], binName, binName, "0.28.0") 57 | .mockReturnValue(Promise.resolve(binPaths[platform])) 58 | } 59 | 60 | function stubFile(path: string, content: string) { 61 | fs.readFileSync.calledWith(path).mockReturnValue(Buffer.from(content, "utf8")) 62 | } 63 | 64 | function releaseJsonFor(app: string, version: string): ReposListReleasesItem { 65 | return { 66 | tag_name: version, 67 | assets: [{ 68 | browser_download_url: `https://example.com/carvel-dev/${app}/releases/download/${version}/${app}-linux-amd64`, 69 | name: `${app}-linux-amd64` 70 | }, { 71 | browser_download_url: `https://example.com/carvel-dev/${app}/releases/download/${version}/${app}-windows-amd64.exe`, 72 | name: `${app}-windows-amd64.exe` 73 | }], 74 | body: `* some cool new features\n${expectedChecksums.linux}\n${expectedChecksums.win32}` 75 | } as ReposListReleasesItem 76 | } 77 | 78 | function createInstaller(platform: "win32" | "linux"): Installer { 79 | const env = { platform: platform } 80 | const releasesService = new CarvelReleasesService(core, env, fs, octokit) 81 | const installer = new Installer(core, cache, fs, env, releasesService) 82 | return installer 83 | } 84 | 85 | test("it installs a new app on nix systems", async () => { 86 | const installer = createInstaller('linux') 87 | stubCacheMiss('linux') 88 | stubFile(downloadPaths.linux, expectedContent) 89 | 90 | await installer.installApp({ name: 'ytt', version: 'latest' }) 91 | 92 | expect(core.info).toHaveBeenCalledWith("Downloading ytt 0.28.0 from https://example.com/carvel-dev/ytt/releases/download/0.28.0/ytt-linux-amd64") 93 | expect(core.info).toHaveBeenCalledWith(`✅ Verified checksum: "dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7 ./ytt-linux-amd64"`) 94 | expect(fs.chmodSync).toHaveBeenCalledWith(downloadPaths.linux, "755") 95 | expect(core.addPath).toHaveBeenCalledWith(binPaths.linux) 96 | }) 97 | 98 | test('it installs a new app on windows', async () => { 99 | const installer = createInstaller('win32') 100 | stubCacheMiss('win32') 101 | stubFile(downloadPaths.win32, expectedContent) 102 | 103 | await installer.installApp({ name: 'ytt', version: '0.28.0' }) 104 | 105 | expect(core.info).toHaveBeenCalledWith("Downloading ytt 0.28.0 from https://example.com/carvel-dev/ytt/releases/download/0.28.0/ytt-windows-amd64.exe") 106 | expect(core.info).toHaveBeenCalledWith(`✅ Verified checksum: "dbd318c1c462aee872f41109a4dfd3048871a03dedd0fe0e757ced57dad6f2d7 ./ytt-windows-amd64.exe"`) 107 | expect(fs.chmodSync).toHaveBeenCalledWith(downloadPaths.win32, "755") 108 | expect(core.addPath).toHaveBeenCalledWith(binPaths.win32) 109 | }) 110 | 111 | test("it adds a cached app to the path on nix systems", async () => { 112 | const installer = createInstaller('linux') 113 | cache.find.calledWith("ytt", "0.28.0").mockReturnValue(binPaths.linux) 114 | 115 | await installer.installApp({ name: 'ytt', version: '0.28.0' }) 116 | 117 | expect(core.info).toHaveBeenCalledWith("ytt 0.28.0 already in tool cache") 118 | expect(cache.downloadTool).not.toHaveBeenCalled() 119 | expect(core.addPath).toHaveBeenCalledWith(binPaths.linux) 120 | }) 121 | 122 | test("it adds a cached app to the path on windows", async () => { 123 | const installer = createInstaller('win32') 124 | cache.find.calledWith("ytt.exe", "0.28.0").mockReturnValue(binPaths.win32) 125 | 126 | await installer.installApp({ name: 'ytt', version: 'latest' }) 127 | 128 | expect(core.info).toHaveBeenCalledWith("ytt 0.28.0 already in tool cache") 129 | expect(cache.downloadTool).not.toHaveBeenCalled() 130 | expect(core.addPath).toHaveBeenCalledWith(binPaths.win32) 131 | }) 132 | 133 | test('it verifies the checksums on nix systems', async () => { 134 | const installer = createInstaller('linux') 135 | stubCacheMiss('linux') 136 | stubFile(downloadPaths.linux, "unexpected content") 137 | 138 | const result = installer.installApp({ name: 'ytt', version: 'latest' }) 139 | 140 | await expect(result).rejects.toThrowError('Unable to verify checksum for ytt-linux-amd64. Expected to find "70f71fa558520b944152eea2ec934c63374c630302a981eab010e0da97bc2f24 ./ytt-linux-amd64" in release notes.') 141 | }) 142 | 143 | test('it verifies the checksums on windows', async () => { 144 | const installer = createInstaller('win32') 145 | stubCacheMiss('win32') 146 | stubFile(downloadPaths.win32, "unexpected content") 147 | 148 | const result = installer.installApp({ name: 'ytt', version: 'latest' }) 149 | 150 | await expect(result).rejects.toThrowError('Unable to verify checksum for ytt-windows-amd64.exe. Expected to find "70f71fa558520b944152eea2ec934c63374c630302a981eab010e0da97bc2f24 ./ytt-windows-amd64.exe" in release notes.') 151 | }) 152 | }) 153 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ 4 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 5 | "outDir": "./lib", /* Redirect output structure to the directory. */ 6 | "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 7 | "strict": true, /* Enable all strict type-checking options. */ 8 | "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 9 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 10 | }, 11 | "exclude": ["node_modules", "test"] 12 | } 13 | --------------------------------------------------------------------------------