mirror of
https://github.com/Azure/k8s-set-context.git
synced 2026-06-23 07:19:32 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d647bdf47 | |||
| f76da0c3d8 |
@@ -55,11 +55,11 @@ jobs:
|
||||
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5
|
||||
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
build-mode: ${{ matrix.build-mode }}
|
||||
@@ -86,6 +86,6 @@ jobs:
|
||||
echo ' make release'
|
||||
exit 1
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@0499de31b99561a6d14a36a5f662c2a54f91beee # v3.29.5
|
||||
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
|
||||
with:
|
||||
category: '/language:${{matrix.language}}'
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
- uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10.1.0
|
||||
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
|
||||
name: Setting Issue as Idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
operations-per-run: 100
|
||||
exempt-issue-labels: 'backlog'
|
||||
|
||||
- uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10.1.0
|
||||
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0
|
||||
name: Setting PR as Idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
@@ -15,7 +15,7 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout Source Code
|
||||
id: checkout-code
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- name: Npm Install and Build
|
||||
id: npm-build
|
||||
run: |
|
||||
|
||||
@@ -10,10 +10,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
cache: 'npm'
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
unit-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- name: Run Unit Tests
|
||||
run: |
|
||||
npm install
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
# Change Log
|
||||
|
||||
## [4.0.2] - 2025-11-13
|
||||
|
||||
- #[164](https://github.com/Azure/k8s-set-context/pull/164) Adding optional kubeconfig encoding variable
|
||||
- Dependabot updates
|
||||
|
||||
## [4.0.1] - 2024-09-06
|
||||
|
||||
- #90 update dev dependencies with Typescript to 5
|
||||
|
||||
@@ -13,10 +13,6 @@ inputs:
|
||||
kubeconfig:
|
||||
description: 'Contents of kubeconfig file'
|
||||
required: false
|
||||
kubeconfig-encoding:
|
||||
description: 'Encoding of the kubeconfig input. Accepts "plaintext" (default) or "base64".'
|
||||
required: false
|
||||
default: 'plaintext'
|
||||
context:
|
||||
description: 'If your kubeconfig has multiple contexts, use this field to use a specific context, otherwise the default one would be chosen'
|
||||
required: false
|
||||
|
||||
Generated
+1434
-1308
File diff suppressed because it is too large
Load Diff
+11
-11
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "k8s-set-context-action",
|
||||
"version": "4.0.2",
|
||||
"version": "4.0.0",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"type": "module",
|
||||
@@ -23,22 +23,22 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/io": "^2.0.0",
|
||||
"@kubernetes/client-node": "^1.4.0",
|
||||
"@actions/io": "^1.1.3",
|
||||
"@kubernetes/client-node": "^1.3.0",
|
||||
"husky": "^9.1.7",
|
||||
"js-yaml": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/preset-env": "^7.28.5",
|
||||
"@babel/preset-typescript": "^7.28.5",
|
||||
"@babel/preset-env": "^7.28.0",
|
||||
"@babel/preset-typescript": "^7.27.1",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/node": "^24.9.2",
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"babel-jest": "^30.2.0",
|
||||
"jest": "^30.2.0",
|
||||
"@types/node": "^24.0.13",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"babel-jest": "^30.0.4",
|
||||
"jest": "^30.0.4",
|
||||
"prettier": "^3.6.2",
|
||||
"ts-jest": "^29.4.5",
|
||||
"typescript": "^5.9.3"
|
||||
"ts-jest": "^29.4.0",
|
||||
"typescript": "^5.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import * as fs from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
import {getRequiredInputError} from '../../tests/util'
|
||||
import {createKubeconfig, getDefaultKubeconfig} from './default'
|
||||
|
||||
@@ -63,47 +62,6 @@ describe('Default kubeconfig', () => {
|
||||
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('returns kubeconfig as plaintext when encoding is plaintext', () => {
|
||||
const kc = 'example kc'
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return 'plaintext'
|
||||
if (name === 'kubeconfig') return kc
|
||||
return ''
|
||||
})
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('it gets default config through base64 kubeconfig input', () => {
|
||||
const kc = 'example kc'
|
||||
const base64Kc = Buffer.from(kc, 'utf-8').toString('base64')
|
||||
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return 'base64'
|
||||
if (name === 'kubeconfig') return base64Kc
|
||||
return ''
|
||||
})
|
||||
|
||||
expect(getDefaultKubeconfig()).toBe(kc)
|
||||
})
|
||||
|
||||
test('it throws error for unknown kubeconfig-encoding', () => {
|
||||
const kc = 'example kc'
|
||||
const unknownEncoding = 'foobar'
|
||||
|
||||
jest.spyOn(core, 'getInput').mockImplementation((name: string) => {
|
||||
if (name === 'method') return 'default'
|
||||
if (name === 'kubeconfig-encoding') return unknownEncoding
|
||||
if (name === 'kubeconfig') return kc
|
||||
return ''
|
||||
})
|
||||
|
||||
expect(() => getDefaultKubeconfig()).toThrow(
|
||||
"Invalid kubeconfig-encoding: 'foobar'. Must be 'plaintext' or 'base64'."
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
test('it defaults to default method', () => {
|
||||
|
||||
@@ -44,27 +44,7 @@ export function getDefaultKubeconfig(): string {
|
||||
}
|
||||
default: {
|
||||
core.debug('Setting context using kubeconfig')
|
||||
enum Encoding {
|
||||
Base64 = 'base64',
|
||||
Plaintext = 'plaintext'
|
||||
}
|
||||
|
||||
const rawKubeconfig = core.getInput('kubeconfig', {required: true})
|
||||
const encoding =
|
||||
core.getInput('kubeconfig-encoding')?.toLowerCase() ||
|
||||
Encoding.Plaintext
|
||||
|
||||
if (encoding !== Encoding.Base64 && encoding !== Encoding.Plaintext) {
|
||||
throw new Error(
|
||||
`Invalid kubeconfig-encoding: '${encoding}'. Must be 'plaintext' or 'base64'.`
|
||||
)
|
||||
}
|
||||
const kubeconfig =
|
||||
encoding === Encoding.Base64
|
||||
? Buffer.from(rawKubeconfig, 'base64').toString('utf-8')
|
||||
: rawKubeconfig
|
||||
|
||||
return kubeconfig
|
||||
return core.getInput('kubeconfig', {required: true})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user