Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c4badf72a | ||
|
|
ff8bf47b42 | ||
|
|
4933a15eb6 | ||
|
|
c2bec5ff29 | ||
|
|
443c3cc7e1 | ||
|
|
7eb54a9e39 | ||
|
|
22c5cc3864 | ||
|
|
a0fc1ed3bf | ||
|
|
9814a57069 | ||
|
|
0597b11a08 | ||
|
|
0c2bcc2bf3 | ||
|
|
aa17f278e9 | ||
|
|
641b6b74db | ||
|
|
c370e32093 | ||
|
|
d9fb2b8307 | ||
|
|
b061303a52 | ||
|
|
d37d346399 | ||
|
|
36563347fa | ||
|
|
6ac935ba0c | ||
|
|
f7e6d667ef | ||
|
|
34e21c7e3f | ||
|
|
5fe2f65f42 |
29
.github/workflows/deploy.yaml
vendored
Normal file
29
.github/workflows/deploy.yaml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: Deploy Action
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
- '!v1'
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
name: Deploy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Build latest dist/ folder
|
||||
run: |
|
||||
npm install -g pnpm
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm run build
|
||||
- name: Upload dist/ folder
|
||||
run: |
|
||||
git config --global user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git checkout --orphan deploy
|
||||
git add -f dist README.md LICENSE action.yaml
|
||||
git commit -m "chore: create ci release ($GITHUB_SHA)"
|
||||
git tag --force v1
|
||||
git push -f --tags origin deploy
|
||||
25
.github/workflows/test.yaml
vendored
25
.github/workflows/test.yaml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Kubectl Action
|
||||
name: Test Action
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -6,10 +6,31 @@ on:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Build latest dist/ folder
|
||||
run: |
|
||||
npm install -g pnpm
|
||||
pnpm install --frozen-lockfile
|
||||
pnpm run build
|
||||
- name: Upload dist/ folder
|
||||
run: |
|
||||
git config --global user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git checkout --orphan ci
|
||||
git add -f dist README.md LICENSE action.yaml
|
||||
git commit -m "chore: create ci release ($GITHUB_SHA)"
|
||||
git push -f origin ci
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Setup tale/kubectl-action
|
||||
uses: tale/kubectl-action@v1
|
||||
uses: tale/kubectl-action@ci
|
||||
with:
|
||||
base64-kube-config: ${{ secrets.KUBE_CONFIG }}
|
||||
- name: Test the output of `kubectl cluster-info`
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
node_modules/
|
||||
dist/
|
||||
|
||||
4
dist/index.js
vendored
4
dist/index.js
vendored
File diff suppressed because one or more lines are too long
1
dist/index.js.map
vendored
1
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
142
dist/licenses.txt
vendored
142
dist/licenses.txt
vendored
@@ -1,142 +0,0 @@
|
||||
@actions/core
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/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
1
dist/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,11 +1,10 @@
|
||||
{
|
||||
"name": "kubectl-action",
|
||||
"version": "1.0.8",
|
||||
"version": "1.1.2",
|
||||
"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"
|
||||
"push": "np --no-cleanup --no-publish --no-tests --message 'chore: v%s'"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
|
||||
25
src/main.ts
25
src/main.ts
@@ -1,12 +1,27 @@
|
||||
/* eslint-disable unicorn/prefer-top-level-await */
|
||||
import { debug, getState, setFailed } from '@actions/core'
|
||||
import { setupKubeconfig } from 'login'
|
||||
import { installKubectl } from 'setup'
|
||||
import { teardown } from 'teardown'
|
||||
|
||||
const post = Boolean(getState('isPost'))
|
||||
|
||||
if (!post) {
|
||||
if (getState('kubectl-path')) {
|
||||
debug('Running post kubectl-action setup')
|
||||
teardown()
|
||||
// eslint-disable-next-line unicorn/prefer-top-level-await
|
||||
.catch(error => {
|
||||
setFailed('Failed to install kubectl (this is a bug in kubectl-action): ')
|
||||
debug(JSON.stringify(error))
|
||||
})
|
||||
} else {
|
||||
debug('Running kubectl-action setup')
|
||||
installKubectl()
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
new Promise(async () => {
|
||||
await installKubectl()
|
||||
debug('kubectl-action setup complete')
|
||||
|
||||
await setupKubeconfig()
|
||||
debug('kubectl-action kubeconfig setup complete')
|
||||
})
|
||||
// eslint-disable-next-line unicorn/prefer-top-level-await
|
||||
.catch(error => {
|
||||
setFailed('Failed to install kubectl (this is a bug in kubectl-action): ')
|
||||
debug(JSON.stringify(error))
|
||||
|
||||
78
src/setup.ts
78
src/setup.ts
@@ -1,9 +1,8 @@
|
||||
import { createHash, randomUUID } from 'node:crypto'
|
||||
import { createWriteStream } from 'node:fs'
|
||||
import { mkdir } from 'node:fs/promises'
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import { join } from 'node:path'
|
||||
import { env, stdout } from 'node:process'
|
||||
import { Readable } from 'node:stream'
|
||||
import { clearLine, cursorTo } from 'node:readline'
|
||||
|
||||
import { addPath, debug, getInput, saveState, setFailed, warning } from '@actions/core'
|
||||
import { fetch } from 'undici'
|
||||
@@ -21,7 +20,8 @@ export async function installKubectl() {
|
||||
trimWhitespace: true
|
||||
})
|
||||
|
||||
const version = input === 'latest' ? await fetchLatestVersion() : input
|
||||
const version = input === 'latest' || input === '' ? await fetchLatestVersion() : input
|
||||
debug(`kubectl-version: ${version ?? 'undefined'}`)
|
||||
|
||||
if (!version?.startsWith('v')) {
|
||||
setFailed('Unable to determine the `kubectl` version to install')
|
||||
@@ -29,7 +29,6 @@ export async function installKubectl() {
|
||||
}
|
||||
|
||||
console.log(`Installing kubectl version ${version}`)
|
||||
|
||||
const kubectl = await downloadKubectl(version)
|
||||
|
||||
if (!kubectl) {
|
||||
@@ -40,16 +39,8 @@ export async function installKubectl() {
|
||||
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)
|
||||
})
|
||||
|
||||
await writeFile(join(path, 'kubectl'), kubectl)
|
||||
addPath(path)
|
||||
}
|
||||
|
||||
@@ -72,9 +63,11 @@ async function downloadKubectl(version: string) {
|
||||
const hashUrl = `${url}.sha256`
|
||||
|
||||
console.log(`Downloading kubectl (${url})`)
|
||||
debug(`Downloading kubectl checksum (${hashUrl})`)
|
||||
|
||||
const hashResponse = await fetch(hashUrl)
|
||||
if (!hashResponse.ok) {
|
||||
debug(`Failed to download kubectl checksum with status ${hashResponse.status}`)
|
||||
warning(`Skipping checksum verification for kubectl ${version}`)
|
||||
}
|
||||
|
||||
@@ -82,45 +75,44 @@ async function downloadKubectl(version: string) {
|
||||
|
||||
const response = await fetch(url)
|
||||
if (!response.ok || !response.body) {
|
||||
debug(`Failed to download kubectl with status ${response.status}`)
|
||||
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'))
|
||||
const { body, headers } = response
|
||||
const size = Number(headers.get('content-length'))
|
||||
debug(`Downloaded kubectl (${size} bytes)`)
|
||||
|
||||
return new Promise<Readable | void>((resolve, reject) => {
|
||||
let downloaded = 0
|
||||
let progressed = 0
|
||||
let downloaded = 0
|
||||
let progressed = 0
|
||||
const buffer = Buffer.alloc(size)
|
||||
|
||||
body.on('data', (chunk: Buffer) => {
|
||||
hashStream.update(chunk)
|
||||
downloaded += chunk.length
|
||||
for await (const chunk of body as AsyncIterable<Buffer>) {
|
||||
buffer.write(chunk.toString('binary'), downloaded, 'binary')
|
||||
hashStream.update(chunk)
|
||||
downloaded += chunk.length
|
||||
|
||||
if (Math.floor((downloaded / size) * 80) > progressed) {
|
||||
stdout.clearLine(0)
|
||||
stdout.cursorTo(0)
|
||||
if (Math.floor((downloaded / size) * 80) > progressed) {
|
||||
clearLine(stdout, 0)
|
||||
cursorTo(stdout, 0)
|
||||
|
||||
progressed++
|
||||
stdout.write(`[${'='.repeat(progressed)}>${' '.repeat(80 - progressed)}]`)
|
||||
}
|
||||
})
|
||||
progressed++
|
||||
stdout.write(`[${'='.repeat(progressed)}>${' '.repeat(80 - progressed)}]`)
|
||||
}
|
||||
}
|
||||
|
||||
body.on('end', () => {
|
||||
stdout.clearLine(0)
|
||||
stdout.cursorTo(0)
|
||||
console.log(`[${'='.repeat(80)}]`)
|
||||
clearLine(stdout, 0)
|
||||
cursorTo(stdout, 0)
|
||||
console.log(`[${'='.repeat(80)}]`)
|
||||
|
||||
const hashSum = hashStream.digest('hex')
|
||||
if (hashResponse.ok && hashSum !== hash) {
|
||||
setFailed(`Checksum verification failed for kubectl ${version}`)
|
||||
resolve()
|
||||
}
|
||||
const hashSum = hashStream.digest('hex')
|
||||
if (hashResponse.ok && hashSum !== hash) {
|
||||
debug(`Checksum verification failed for kubectl ${version}`)
|
||||
setFailed(`Checksum verification failed for kubectl ${version}`)
|
||||
return
|
||||
}
|
||||
|
||||
resolve(body)
|
||||
})
|
||||
|
||||
body.on('error', reject)
|
||||
})
|
||||
return buffer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user