Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ed17e8ff6 | ||
|
|
4e7c8bb981 | ||
|
|
c6e917eb5e | ||
|
|
7446d29d60 | ||
|
|
22ac3ce88d | ||
|
|
8a18fa720b | ||
|
|
11bbbb9207 | ||
|
|
574fbc2143 | ||
|
|
b284f0ba18 | ||
|
|
558e44eea4 | ||
|
|
29d331ef6a | ||
|
|
28eb8b8850 | ||
|
|
692ba3e286 | ||
|
|
c368992ffb | ||
|
|
880d48e290 | ||
|
|
1b27c62a93 | ||
|
|
25403f865e | ||
|
|
f6e83f6681 | ||
|
|
b88fbf4ad6 | ||
|
|
fe5edd2387 | ||
|
|
50d08134cc | ||
|
|
1c88fc9f2b | ||
|
|
16b4bea4f4 | ||
|
|
34de7de05e | ||
|
|
f326ba7d79 |
16
.github/workflows/test.yaml
vendored
Normal file
16
.github/workflows/test.yaml
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
name: Kubectl Action
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup tale/kubectl-action
|
||||
uses: tale/kubectl-action@v1
|
||||
with:
|
||||
base64-kube-config: ${{ secrets.KUBE_CONFIG }}
|
||||
- name: Test the output of `kubectl cluster-info`
|
||||
run: kubectl cluster-info
|
||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules/
|
||||
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
}
|
||||
}
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 Aarnav Tale
|
||||
|
||||
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.
|
||||
@@ -1,8 +1,11 @@
|
||||
# kubectl-action
|
||||
|
||||
GitHub Action to manage a K8s (Kubernetes) cluster using kubectl.
|
||||
|
||||
# Usage
|
||||
## Usage
|
||||
|
||||
To use this action, add the following step to your GitHub Action workflow:
|
||||
|
||||
```yaml
|
||||
- uses: tale/kubectl-action@v1
|
||||
with:
|
||||
@@ -11,7 +14,8 @@ To use this action, add the following step to your GitHub Action workflow:
|
||||
|
||||
Keep in mind that the action expects a base64 encoded string of your Kubernetes configuration. The simplest way to do that is to run `cat $HOME/.kube/config | base64` and save that output as an action secret.
|
||||
|
||||
It's also possible to specify the version of the [kubectl](https://kubernetes.io/docs/reference/kubectl/) CLI to use. The current default release used by this action is `v1.23.0`.
|
||||
It's also possible to specify the version of the [kubectl](https://kubernetes.io/docs/reference/kubectl/) CLI to use. The current default release used by this action is the latest version.
|
||||
|
||||
```yaml
|
||||
- uses: tale/kubectl-action@v1
|
||||
with:
|
||||
@@ -20,6 +24,7 @@ It's also possible to specify the version of the [kubectl](https://kubernetes.io
|
||||
```
|
||||
|
||||
Once you've completed this setup, you have direct access to the `kubectl` binary and command in the rest of your actions. Here's a full example to give you some inspiration:
|
||||
|
||||
```yaml
|
||||
name: Kubectl Action
|
||||
|
||||
|
||||
15
action.yaml
15
action.yaml
@@ -8,18 +8,11 @@ inputs:
|
||||
kubectl-version:
|
||||
description: Version of the kubectl CLI to use
|
||||
required: false
|
||||
default: v1.23.0
|
||||
default: latest
|
||||
base64-kube-config:
|
||||
description: A base64 encoded reference to your authorization file (~/.kube/config)
|
||||
required: true
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Configure kubectl CLI
|
||||
run: setup-kubectl.sh
|
||||
shell: bash
|
||||
- name: Authorize kubectl to the cluster
|
||||
run: login-kubectl.sh
|
||||
shell: bash
|
||||
env:
|
||||
BASE64_KUBE_CONFIG: ${{ inputs.base64-kube-config }}
|
||||
using: node16
|
||||
main: dist/index.js
|
||||
post: dist/index.js
|
||||
|
||||
4
dist/index.js
vendored
Normal file
4
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/index.js.map
vendored
Normal file
1
dist/index.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
142
dist/licenses.txt
vendored
Normal file
142
dist/licenses.txt
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
@actions/core
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/http-client
|
||||
MIT
|
||||
Actions Http Client for Node.js
|
||||
|
||||
Copyright (c) GitHub, Inc.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
busboy
|
||||
MIT
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
streamsearch
|
||||
MIT
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
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.
|
||||
|
||||
tunnel
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Koichi Kobayashi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
undici
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) Matteo Collina and Undici contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
uuid
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2010-2020 Robert Kieffer and other 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.
|
||||
1
dist/sourcemap-register.js
vendored
Normal file
1
dist/sourcemap-register.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ ! -d "$HOME/.kube" ]; then
|
||||
mkdir -p $HOME/.kube
|
||||
fi
|
||||
|
||||
echo "$BASE64_KUBE_CONFIG" | base64 -d > $HOME/.kube/config
|
||||
22
package.json
Normal file
22
package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "kubectl-action",
|
||||
"version": "1.0.8",
|
||||
"scripts": {
|
||||
"dev": "ncc -smw --license licenses.txt build src/main.ts",
|
||||
"build": "ncc -sm --license licenses.txt build src/main.ts",
|
||||
"push": "np --no-cleanup --no-publish --no-tests --message 'chore: v%s' && git tag --force v1 && git push -f --tags",
|
||||
"version": "pnpm run build && git add dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"undici": "^5.16.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.18",
|
||||
"@vercel/ncc": "^0.36.0",
|
||||
"eslint": "^8.32.0",
|
||||
"eslint-config-tale": "^1.0.15",
|
||||
"np": "^7.6.3",
|
||||
"typescript": "^4.9.4"
|
||||
}
|
||||
}
|
||||
3630
pnpm-lock.yaml
generated
Normal file
3630
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
curl -LO "https://dl.k8s.io/release/${{ inputs.kubectl-version }}/bin/linux/amd64/kubectl"
|
||||
curl -LO "https://dl.k8s.io/${{ inputs.kubectl-version }}/bin/linux/amd64/kubectl.sha256"
|
||||
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
|
||||
|
||||
mkdir $GITHUB_WORKSPACE/bin
|
||||
mv kubectl $GITHUB_WORKSPACE/bin
|
||||
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
|
||||
28
src/login.ts
Normal file
28
src/login.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { env } from 'node:process'
|
||||
|
||||
import { debug, getInput, saveState, setFailed } from '@actions/core'
|
||||
|
||||
export async function setupKubeconfig() {
|
||||
debug('Running kubectl-action setupKubeconfig()')
|
||||
|
||||
if (env.HOME === undefined) {
|
||||
setFailed('$HOME is not defined')
|
||||
return
|
||||
}
|
||||
|
||||
const config = getInput('base64-kube-config', {
|
||||
required: true,
|
||||
trimWhitespace: true
|
||||
})
|
||||
|
||||
const decoded = Buffer.from(config, 'base64')
|
||||
.toString('utf8')
|
||||
|
||||
const path = join(env.HOME, '.kube')
|
||||
saveState('kubeconfig-path', path)
|
||||
|
||||
await mkdir(path, { recursive: true })
|
||||
await writeFile(join(path, 'config'), decoded, 'utf8')
|
||||
}
|
||||
14
src/main.ts
Normal file
14
src/main.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/* eslint-disable unicorn/prefer-top-level-await */
|
||||
import { debug, getState, setFailed } from '@actions/core'
|
||||
import { installKubectl } from 'setup'
|
||||
|
||||
const post = Boolean(getState('isPost'))
|
||||
|
||||
if (!post) {
|
||||
debug('Running kubectl-action setup')
|
||||
installKubectl()
|
||||
.catch(error => {
|
||||
setFailed('Failed to install kubectl (this is a bug in kubectl-action): ')
|
||||
debug(JSON.stringify(error))
|
||||
})
|
||||
}
|
||||
126
src/setup.ts
Normal file
126
src/setup.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
import { createHash, randomUUID } from 'node:crypto'
|
||||
import { createWriteStream } from 'node:fs'
|
||||
import { mkdir } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { env, stdout } from 'node:process'
|
||||
import { Readable } from 'node:stream'
|
||||
|
||||
import { addPath, debug, getInput, saveState, setFailed, warning } from '@actions/core'
|
||||
import { fetch } from 'undici'
|
||||
|
||||
export async function installKubectl() {
|
||||
debug('Running kubectl-action installKubectl()')
|
||||
|
||||
if (env.RUNNER_TEMP === undefined) {
|
||||
setFailed('$RUNNER_TEMP is not defined')
|
||||
return
|
||||
}
|
||||
|
||||
const input = getInput('kubectl-version', {
|
||||
required: false,
|
||||
trimWhitespace: true
|
||||
})
|
||||
|
||||
const version = input === 'latest' ? await fetchLatestVersion() : input
|
||||
|
||||
if (!version?.startsWith('v')) {
|
||||
setFailed('Unable to determine the `kubectl` version to install')
|
||||
return
|
||||
}
|
||||
|
||||
console.log(`Installing kubectl version ${version}`)
|
||||
|
||||
const kubectl = await downloadKubectl(version)
|
||||
|
||||
if (!kubectl) {
|
||||
return
|
||||
}
|
||||
|
||||
const path = join(env.RUNNER_TEMP, randomUUID())
|
||||
await mkdir(path, { recursive: true })
|
||||
saveState('kubectl-path', path)
|
||||
|
||||
const stream = createWriteStream(join(path, 'kubectl'))
|
||||
|
||||
kubectl.pipe(stream)
|
||||
|
||||
console.log(`Installing kubectl to ${path}`)
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
stream.on('finish', resolve)
|
||||
stream.on('error', reject)
|
||||
})
|
||||
|
||||
addPath(path)
|
||||
}
|
||||
|
||||
// Fetches the latest kubectl version from the Kubernetes release server
|
||||
async function fetchLatestVersion() {
|
||||
const response = await fetch('https://dl.k8s.io/release/stable.txt')
|
||||
if (!response.ok) {
|
||||
setFailed(`Failed to fetch latest kubectl version with status ${response.status}`)
|
||||
return
|
||||
}
|
||||
|
||||
const version = await response.text()
|
||||
return version.trim()
|
||||
}
|
||||
|
||||
// Downloads the kubectl binary from the Kubernetes release server
|
||||
// Also runs a checksum verification on the downloaded binary
|
||||
async function downloadKubectl(version: string) {
|
||||
const url = `https://dl.k8s.io/release/${version}/bin/linux/amd64/kubectl`
|
||||
const hashUrl = `${url}.sha256`
|
||||
|
||||
console.log(`Downloading kubectl (${url})`)
|
||||
|
||||
const hashResponse = await fetch(hashUrl)
|
||||
if (!hashResponse.ok) {
|
||||
warning(`Skipping checksum verification for kubectl ${version}`)
|
||||
}
|
||||
|
||||
const hash = hashResponse.ok ? await hashResponse.text() : ''
|
||||
|
||||
const response = await fetch(url)
|
||||
if (!response.ok || !response.body) {
|
||||
setFailed(`Failed to download kubectl with status ${response.status}`)
|
||||
return
|
||||
}
|
||||
|
||||
const hashStream = createHash('sha256')
|
||||
const body = Readable.fromWeb(response.body)
|
||||
const size = Number(response.headers.get('content-length'))
|
||||
|
||||
return new Promise<Readable | void>((resolve, reject) => {
|
||||
let downloaded = 0
|
||||
let progressed = 0
|
||||
|
||||
body.on('data', (chunk: Buffer) => {
|
||||
hashStream.update(chunk)
|
||||
downloaded += chunk.length
|
||||
|
||||
if (Math.floor((downloaded / size) * 80) > progressed) {
|
||||
stdout.clearLine(0)
|
||||
stdout.cursorTo(0)
|
||||
|
||||
progressed++
|
||||
stdout.write(`[${'='.repeat(progressed)}>${' '.repeat(80 - progressed)}]`)
|
||||
}
|
||||
})
|
||||
|
||||
body.on('end', () => {
|
||||
stdout.clearLine(0)
|
||||
stdout.cursorTo(0)
|
||||
console.log(`[${'='.repeat(80)}]`)
|
||||
|
||||
const hashSum = hashStream.digest('hex')
|
||||
if (hashResponse.ok && hashSum !== hash) {
|
||||
setFailed(`Checksum verification failed for kubectl ${version}`)
|
||||
resolve()
|
||||
}
|
||||
|
||||
resolve(body)
|
||||
})
|
||||
|
||||
body.on('error', reject)
|
||||
})
|
||||
}
|
||||
14
src/teardown.ts
Normal file
14
src/teardown.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { rm } from 'node:fs/promises'
|
||||
|
||||
import { debug, getState } from '@actions/core'
|
||||
|
||||
export async function teardown() {
|
||||
debug('Running kubectl-action teardown()')
|
||||
console.log('Removing kubectl and kubeconfig')
|
||||
|
||||
const path = getState('kubectl-path')
|
||||
await rm(path, { recursive: true, force: true })
|
||||
|
||||
const configPath = getState('kubeconfig-path')
|
||||
await rm(configPath, { recursive: true, force: true })
|
||||
}
|
||||
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"exclude": ["dist"],
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./src",
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"target": "ESNext",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user