Compare commits
1 Commits
update-cod
...
v4.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
776406bce9 |
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -1 +1 @@
|
|||||||
* @Azure/cloud-native-github-action-owners
|
* @Azure/aks-atlanta
|
||||||
4
.github/workflows/codeql.yml
vendored
4
.github/workflows/codeql.yml
vendored
@@ -59,7 +59,7 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@d6bbdef45e766d081b84a2def353b0055f728d3e # v3.29.3
|
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
build-mode: ${{ matrix.build-mode }}
|
build-mode: ${{ matrix.build-mode }}
|
||||||
@@ -86,6 +86,6 @@ jobs:
|
|||||||
echo ' make release'
|
echo ' make release'
|
||||||
exit 1
|
exit 1
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@d6bbdef45e766d081b84a2def353b0055f728d3e # v3.29.3
|
uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
|
||||||
with:
|
with:
|
||||||
category: '/language:${{matrix.language}}'
|
category: '/language:${{matrix.language}}'
|
||||||
|
|||||||
2
.github/workflows/integration-tests.yml
vendored
2
.github/workflows/integration-tests.yml
vendored
@@ -27,8 +27,6 @@ jobs:
|
|||||||
if [[ $PR_BASE_REF != releases/* ]]; then
|
if [[ $PR_BASE_REF != releases/* ]]; then
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
# remove node_modules to match production environment where only index.js is present
|
|
||||||
rm -rf node_modules
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -330,4 +330,3 @@ ASALocalRun/
|
|||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
# Transpiled JS
|
# Transpiled JS
|
||||||
lib/
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
set +e
|
|
||||||
npm test
|
|
||||||
# Run format check
|
|
||||||
npm run format-check || {
|
|
||||||
echo ""
|
|
||||||
echo "❌ Formatting check failed."
|
|
||||||
echo "💡 Run 'npm run format' or 'prettier --write .' to fix formatting issues."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
6280
lib/index.js
Normal file
6280
lib/index.js
Normal file
File diff suppressed because it is too large
Load Diff
2275
package-lock.json
generated
2275
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@@ -8,8 +8,7 @@
|
|||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test-coverage": "jest --coverage",
|
"test-coverage": "jest --coverage",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format-check": "prettier --check .",
|
"format-check": "prettier --check ."
|
||||||
"prepare": "husky"
|
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"actions",
|
"actions",
|
||||||
@@ -21,15 +20,15 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.0",
|
||||||
"@actions/tool-cache": "^2.0.2"
|
"@actions/tool-cache": "^2.0.2",
|
||||||
|
"ncc": "^0.3.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^24.0.13",
|
"@types/node": "^24.0.2",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vercel/ncc": "^0.38.3",
|
||||||
"husky": "^9.1.7",
|
"jest": "^30.0.0",
|
||||||
"jest": "^30.0.4",
|
"prettier": "3.5.3",
|
||||||
"prettier": "3.6.2",
|
|
||||||
"ts-jest": "^29.4.0",
|
"ts-jest": "^29.4.0",
|
||||||
"typescript": "5.8.3"
|
"typescript": "5.8.3"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as util from 'util'
|
import * as util from 'util'
|
||||||
import * as fs from 'fs'
|
|
||||||
import * as core from '@actions/core'
|
|
||||||
import * as toolCache from '@actions/tool-cache'
|
|
||||||
export function getKubectlArch(): string {
|
export function getKubectlArch(): string {
|
||||||
const arch = os.arch()
|
const arch = os.arch()
|
||||||
if (arch === 'x64') {
|
if (arch === 'x64') {
|
||||||
@@ -25,29 +23,6 @@ export function getkubectlDownloadURL(version: string, arch: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLatestPatchVersion(
|
|
||||||
major: string,
|
|
||||||
minor: string
|
|
||||||
): Promise<string> {
|
|
||||||
const version = `${major}.${minor}`
|
|
||||||
const sourceURL = `https://cdn.dl.k8s.io/release/stable-${version}.txt`
|
|
||||||
try {
|
|
||||||
const downloadPath = await toolCache.downloadTool(sourceURL)
|
|
||||||
const latestPatch = fs
|
|
||||||
.readFileSync(downloadPath, 'utf8')
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
if (!latestPatch) {
|
|
||||||
throw new Error(`No patch version found for ${version}`)
|
|
||||||
}
|
|
||||||
return latestPatch
|
|
||||||
} catch (error) {
|
|
||||||
core.debug(error)
|
|
||||||
core.warning('GetLatestPatchVersionFailed')
|
|
||||||
throw new Error(`Failed to get latest patch version for ${version}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getExecutableExtension(): string {
|
export function getExecutableExtension(): string {
|
||||||
if (os.type().match(/^Win/)) {
|
if (os.type().match(/^Win/)) {
|
||||||
return '.exe'
|
return '.exe'
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import * as run from './run'
|
|||||||
import {
|
import {
|
||||||
getkubectlDownloadURL,
|
getkubectlDownloadURL,
|
||||||
getKubectlArch,
|
getKubectlArch,
|
||||||
getExecutableExtension,
|
getExecutableExtension
|
||||||
getLatestPatchVersion
|
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as toolCache from '@actions/tool-cache'
|
import * as toolCache from '@actions/tool-cache'
|
||||||
@@ -13,9 +12,6 @@ import * as core from '@actions/core'
|
|||||||
import * as util from 'util'
|
import * as util from 'util'
|
||||||
|
|
||||||
describe('Testing all functions in run file.', () => {
|
describe('Testing all functions in run file.', () => {
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks()
|
|
||||||
})
|
|
||||||
test('getExecutableExtension() - return .exe when os is Windows', () => {
|
test('getExecutableExtension() - return .exe when os is Windows', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||||
expect(getExecutableExtension()).toBe('.exe')
|
expect(getExecutableExtension()).toBe('.exe')
|
||||||
@@ -168,59 +164,6 @@ describe('Testing all functions in run file.', () => {
|
|||||||
)
|
)
|
||||||
expect(toolCache.downloadTool).not.toHaveBeenCalled()
|
expect(toolCache.downloadTool).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
test('getLatestPatchVersion() - download and return latest patch version', async () => {
|
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
|
||||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.27.15')
|
|
||||||
|
|
||||||
const result = await getLatestPatchVersion('1', '27')
|
|
||||||
|
|
||||||
expect(result).toBe('v1.27.15')
|
|
||||||
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
|
||||||
'https://cdn.dl.k8s.io/release/stable-1.27.txt'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getLatestPatchVersion() - throw error when patch version is empty', async () => {
|
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
|
||||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('')
|
|
||||||
|
|
||||||
await expect(getLatestPatchVersion('1', '27')).rejects.toThrow(
|
|
||||||
'Failed to get latest patch version for 1.27'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getLatestPatchVersion() - throw error when download fails', async () => {
|
|
||||||
jest
|
|
||||||
.spyOn(toolCache, 'downloadTool')
|
|
||||||
.mockRejectedValue(new Error('Network error'))
|
|
||||||
|
|
||||||
await expect(getLatestPatchVersion('1', '27')).rejects.toThrow(
|
|
||||||
'Failed to get latest patch version for 1.27'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
test('resolveKubectlVersion() - expands major.minor to latest patch', async () => {
|
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
|
||||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.27.15')
|
|
||||||
|
|
||||||
const result = await run.resolveKubectlVersion('1.27')
|
|
||||||
expect(result).toBe('v1.27.15')
|
|
||||||
})
|
|
||||||
|
|
||||||
test('resolveKubectlVersion() - returns full version unchanged', async () => {
|
|
||||||
const result = await run.resolveKubectlVersion('v1.27.15')
|
|
||||||
expect(result).toBe('v1.27.15')
|
|
||||||
})
|
|
||||||
test('resolveKubectlVersion() - adds v prefix to full version', async () => {
|
|
||||||
const result = await run.resolveKubectlVersion('1.27.15')
|
|
||||||
expect(result).toBe('v1.27.15')
|
|
||||||
})
|
|
||||||
test('resolveKubectlVersion() - expands v-prefixed major.minor to latest patch', async () => {
|
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
|
||||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.27.15')
|
|
||||||
|
|
||||||
const result = await run.resolveKubectlVersion('v1.27')
|
|
||||||
expect(result).toBe('v1.27.15')
|
|
||||||
})
|
|
||||||
test('run() - download specified version and set output', async () => {
|
test('run() - download specified version and set output', async () => {
|
||||||
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5')
|
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5')
|
||||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
||||||
|
|||||||
32
src/run.ts
32
src/run.ts
@@ -1,13 +1,14 @@
|
|||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as util from 'util'
|
import * as util from 'util'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
|
||||||
import * as toolCache from '@actions/tool-cache'
|
import * as toolCache from '@actions/tool-cache'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getkubectlDownloadURL,
|
getkubectlDownloadURL,
|
||||||
getKubectlArch,
|
getKubectlArch,
|
||||||
getExecutableExtension,
|
getExecutableExtension
|
||||||
getLatestPatchVersion
|
|
||||||
} from './helpers'
|
} from './helpers'
|
||||||
|
|
||||||
const kubectlToolName = 'kubectl'
|
const kubectlToolName = 'kubectl'
|
||||||
@@ -19,8 +20,6 @@ export async function run() {
|
|||||||
let version = core.getInput('version', {required: true})
|
let version = core.getInput('version', {required: true})
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
version = await getStableKubectlVersion()
|
version = await getStableKubectlVersion()
|
||||||
} else {
|
|
||||||
version = await resolveKubectlVersion(version)
|
|
||||||
}
|
}
|
||||||
const cachedPath = await downloadKubectl(version)
|
const cachedPath = await downloadKubectl(version)
|
||||||
|
|
||||||
@@ -90,28 +89,3 @@ export async function downloadKubectl(version: string): Promise<string> {
|
|||||||
fs.chmodSync(kubectlPath, '775')
|
fs.chmodSync(kubectlPath, '775')
|
||||||
return kubectlPath
|
return kubectlPath
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resolveKubectlVersion(version: string): Promise<string> {
|
|
||||||
const cleanedVersion = version.trim()
|
|
||||||
const versionMatch = cleanedVersion.match(
|
|
||||||
/^v?(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?$/
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!versionMatch?.groups) {
|
|
||||||
throw new Error(
|
|
||||||
`Invalid version format: "${version}". Version must be in "major.minor" or "major.minor.patch" format (e.g., "1.27" or "v1.27.15").`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const {major, minor, patch} = versionMatch.groups
|
|
||||||
|
|
||||||
if (patch) {
|
|
||||||
// Full version was provided, just ensure it has a 'v' prefix
|
|
||||||
return cleanedVersion.startsWith('v')
|
|
||||||
? cleanedVersion
|
|
||||||
: `v${cleanedVersion}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch version is missing, fetch the latest
|
|
||||||
return await getLatestPatchVersion(major, minor)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES6",
|
||||||
"module": "commonjs",
|
"module": "commonjs"
|
||||||
"lib": ["ES2020", "DOM"]
|
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "test"]
|
"exclude": ["node_modules", "test"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user