mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-06-23 21:19:28 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 66eca59f67 | |||
| d565a17533 | |||
| 1811836de2 |
@@ -10,10 +10,13 @@ jobs:
|
|||||||
CodeQL-Build:
|
CodeQL-Build:
|
||||||
# CodeQL runs on ubuntu-latest and windows-latest
|
# CodeQL runs on ubuntu-latest and windows-latest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 #v4.1.1
|
||||||
with:
|
with:
|
||||||
# We must fetch at least the immediate parents so that if this is
|
# We must fetch at least the immediate parents so that if this is
|
||||||
# a pull request then we can checkout the head.
|
# a pull request then we can checkout the head.
|
||||||
@@ -21,7 +24,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@v2
|
uses: github/codeql-action/init@05963f47d870e2cb19a537396c1f668a348c7d8f #v3.24.8
|
||||||
# Override language selection by uncommenting this and choosing your languages
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
# with:
|
# with:
|
||||||
# languages: go, javascript, csharp, python, cpp, java
|
# languages: go, javascript, csharp, python, cpp, java
|
||||||
@@ -29,7 +32,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v2
|
uses: github/codeql-action/autobuild@05963f47d870e2cb19a537396c1f668a348c7d8f #v3.24.8
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -43,4 +46,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v2
|
uses: github/codeql-action/analyze@05963f47d870e2cb19a537396c1f668a348c7d8f #v3.24.8
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: release Project
|
name: Release Project
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -10,6 +10,9 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@e4a1a0385530d6861c9a9b7262058ad33b10c769
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: write
|
||||||
|
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@v1
|
||||||
with:
|
with:
|
||||||
changelogPath: ./CHANGELOG.md
|
changelogPath: ./CHANGELOG.md
|
||||||
|
|||||||
+18
-1
@@ -1,6 +1,23 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [v4.10.0] - 2023-10-30
|
## [5.0.0] - 2024-03-12
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- #309 Updated to Node20 and upgraded release workflows to @v1 tag
|
||||||
|
- #306 update release workflow to use new prefix, remove deprecated release
|
||||||
|
- #303 fix: ensure imageNames are not empty strings
|
||||||
|
- #299 bump release workflow sha
|
||||||
|
- #298 bump minikube to fix runner deps
|
||||||
|
- #297 update release workflow
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- #304 add v prefix for version tagging
|
||||||
|
- #302 adding ncc to build
|
||||||
|
- #301 adding release workflow artifact fix
|
||||||
|
|
||||||
|
## [4.10.0] - 2023-10-30
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ Following are the key capabilities of this action:
|
|||||||
### Basic deployment (without any deployment strategy)
|
### Basic deployment (without any deployment strategy)
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
manifests: |
|
manifests: |
|
||||||
@@ -146,7 +146,7 @@ Following are the key capabilities of this action:
|
|||||||
### Private cluster deployment
|
### Private cluster deployment
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
resource-group: yourResourceGroup
|
resource-group: yourResourceGroup
|
||||||
name: yourClusterName
|
name: yourClusterName
|
||||||
@@ -166,7 +166,7 @@ Following are the key capabilities of this action:
|
|||||||
### Canary deployment without service mesh
|
### Canary deployment without service mesh
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||||
@@ -185,7 +185,7 @@ Following are the key capabilities of this action:
|
|||||||
To promote/reject the canary created by the above snippet, the following YAML snippet could be used:
|
To promote/reject the canary created by the above snippet, the following YAML snippet could be used:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||||
@@ -203,7 +203,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
|||||||
### Canary deployment based on Service Mesh Interface
|
### Canary deployment based on Service Mesh Interface
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||||
@@ -224,7 +224,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
|||||||
To promote/reject the canary created by the above snippet, the following YAML snippet could be used:
|
To promote/reject the canary created by the above snippet, the following YAML snippet could be used:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }} '
|
images: 'contoso.azurecr.io/myapp:${{ event.run_id }} '
|
||||||
@@ -243,7 +243,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
|||||||
### Blue-Green deployment with different route methods
|
### Blue-Green deployment with different route methods
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||||
@@ -263,7 +263,7 @@ To promote/reject the canary created by the above snippet, the following YAML sn
|
|||||||
To promote/reject the green workload created by the above snippet, the following YAML snippet could be used:
|
To promote/reject the green workload created by the above snippet, the following YAML snippet could be used:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
namespace: 'myapp'
|
namespace: 'myapp'
|
||||||
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
images: 'contoso.azurecr.io/myapp:${{ event.run_id }}'
|
||||||
@@ -292,7 +292,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: Azure/docker-login@v1
|
- uses: Azure/docker-login@v1
|
||||||
with:
|
with:
|
||||||
@@ -304,23 +304,23 @@ jobs:
|
|||||||
docker build . -t contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
docker build . -t contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
||||||
docker push contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
docker push contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
||||||
|
|
||||||
- uses: azure/setup-kubectl@v2.0
|
- uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
# Set the target AKS cluster.
|
# Set the target AKS cluster.
|
||||||
- uses: Azure/aks-set-context@v1
|
- uses: Azure/aks-set-context@v4
|
||||||
with:
|
with:
|
||||||
creds: '${{ secrets.AZURE_CREDENTIALS }}'
|
creds: '${{ secrets.AZURE_CREDENTIALS }}'
|
||||||
cluster-name: contoso
|
cluster-name: contoso
|
||||||
resource-group: contoso-rg
|
resource-group: contoso-rg
|
||||||
|
|
||||||
- uses: Azure/k8s-create-secret@v1.1
|
- uses: Azure/k8s-create-secret@v4
|
||||||
with:
|
with:
|
||||||
container-registry-url: contoso.azurecr.io
|
container-registry-url: contoso.azurecr.io
|
||||||
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
secret-name: demo-k8s-secret
|
secret-name: demo-k8s-secret
|
||||||
|
|
||||||
- uses: Azure/k8s-deploy@v4
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
action: deploy
|
action: deploy
|
||||||
manifests: |
|
manifests: |
|
||||||
@@ -341,7 +341,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: Azure/docker-login@v1
|
- uses: Azure/docker-login@v1
|
||||||
with:
|
with:
|
||||||
@@ -353,13 +353,13 @@ jobs:
|
|||||||
docker build . -t contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
docker build . -t contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
||||||
docker push contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
docker push contoso.azurecr.io/k8sdemo:${{ github.sha }}
|
||||||
|
|
||||||
- uses: azure/setup-kubectl@v2.0
|
- uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
- uses: Azure/k8s-set-context@v2
|
- uses: Azure/k8s-set-context@v4
|
||||||
with:
|
with:
|
||||||
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
kubeconfig: ${{ secrets.KUBE_CONFIG }}
|
||||||
|
|
||||||
- uses: Azure/k8s-create-secret@v1.1
|
- uses: Azure/k8s-create-secret@v4
|
||||||
with:
|
with:
|
||||||
container-registry-url: contoso.azurecr.io
|
container-registry-url: contoso.azurecr.io
|
||||||
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
container-registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
@@ -391,7 +391,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: Azure/docker-login@v1
|
- uses: Azure/docker-login@v1
|
||||||
with:
|
with:
|
||||||
@@ -423,16 +423,16 @@ jobs:
|
|||||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
password: ${{ secrets.REGISTRY_PASSWORD }}
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
- uses: azure/setup-kubectl@v2.0
|
- uses: azure/setup-kubectl@v4
|
||||||
|
|
||||||
# Set the target AKS cluster.
|
# Set the target AKS cluster.
|
||||||
- uses: Azure/aks-set-context@v1
|
- uses: Azure/aks-set-context@v4
|
||||||
with:
|
with:
|
||||||
creds: '${{ secrets.AZURE_CREDENTIALS }}'
|
creds: '${{ secrets.AZURE_CREDENTIALS }}'
|
||||||
cluster-name: contoso
|
cluster-name: contoso
|
||||||
resource-group: contoso-rg
|
resource-group: contoso-rg
|
||||||
|
|
||||||
- uses: Azure/k8s-create-secret@v1.1
|
- uses: Azure/k8s-create-secret@v4
|
||||||
with:
|
with:
|
||||||
namespace: ${{ env.NAMESPACE }}
|
namespace: ${{ env.NAMESPACE }}
|
||||||
container-registry-url: contoso.azurecr.io
|
container-registry-url: contoso.azurecr.io
|
||||||
@@ -440,7 +440,7 @@ jobs:
|
|||||||
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
container-registry-password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
secret-name: demo-k8s-secret
|
secret-name: demo-k8s-secret
|
||||||
|
|
||||||
- uses: azure/k8s-bake@v2
|
- uses: azure/k8s-bake@v3
|
||||||
with:
|
with:
|
||||||
renderEngine: 'helm'
|
renderEngine: 'helm'
|
||||||
helmChart: './aks-helloworld/'
|
helmChart: './aks-helloworld/'
|
||||||
@@ -450,7 +450,7 @@ jobs:
|
|||||||
helm-version: 'latest'
|
helm-version: 'latest'
|
||||||
id: bake
|
id: bake
|
||||||
|
|
||||||
- uses: Azure/k8s-deploy@v1.2
|
- uses: Azure/k8s-deploy@v5
|
||||||
with:
|
with:
|
||||||
action: deploy
|
action: deploy
|
||||||
manifests: ${{ steps.bake.outputs.manifestsBundle }}
|
manifests: ${{ steps.bake.outputs.manifestsBundle }}
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "k8s-deploy-action",
|
"name": "k8s-deploy-action",
|
||||||
"version": "0.0.0",
|
"version": "5.0.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "k8s-deploy-action",
|
"name": "k8s-deploy-action",
|
||||||
"version": "0.0.0",
|
"version": "5.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
|||||||
+3
-2
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "k8s-deploy-action",
|
"name": "k8s-deploy-action",
|
||||||
"version": "0.0.0",
|
"version": "5.0.0",
|
||||||
"author": "Deepak Sattiraju",
|
"author": "Deepak Sattiraju",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm i ncc && npx ncc build src/run.ts -o lib",
|
"prebuild": "npm i @vercel/ncc",
|
||||||
|
"build": "ncc build src/run.ts -o lib",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"coverage": "jest --coverage=true",
|
"coverage": "jest --coverage=true",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {PrivateKubectl} from './privatekubectl'
|
import { PrivateKubectl, extractFileNames, replaceFileNamesWithBaseNames } from './privatekubectl'
|
||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
|
|
||||||
describe('Private kubectl', () => {
|
describe('Private kubectl', () => {
|
||||||
const testString = `kubectl annotate -f test.yml,test2.yml,test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832`
|
const testString = `kubectl annotate -f testdir/test.yml,test2.yml,testdir/subdir/test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832`
|
||||||
const mockKube = new PrivateKubectl(
|
const mockKube = new PrivateKubectl(
|
||||||
'kubectlPath',
|
'kubectlPath',
|
||||||
'namespace',
|
'namespace',
|
||||||
@@ -12,15 +12,21 @@ describe('Private kubectl', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
it('should extract filenames correctly', () => {
|
it('should extract filenames correctly', () => {
|
||||||
expect(mockKube.extractFilesnames(testString)).toEqual(
|
expect(extractFileNames(testString)).toEqual(
|
||||||
'test.yml test2.yml test3.yml test4.yml test5.yml'
|
['testdir/test.yml', 'test2.yml', 'testdir/subdir/test3.yml', 'test4.yml', 'test5.yml']
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should replace filenames with basenames correctly', () => {
|
||||||
|
expect(replaceFileNamesWithBaseNames(testString)).toEqual(
|
||||||
|
`kubectl annotate -f test.yml,test2.yml,test3.yml -f test4.yml --filename test5.yml actions.github.com/k8s-deploy={"run":"3498366832","repository":"jaiveerk/k8s-deploy","workflow":"Minikube Integration Tests - private cluster","workflowFileName":"run-integration-tests-private.yml","jobName":"run-integration-test","createdBy":"jaiveerk","runUri":"https://github.com/jaiveerk/k8s-deploy/actions/runs/3498366832","commit":"c63b323186ea1320a31290de6dcc094c06385e75","lastSuccessRunCommit":"NA","branch":"refs/heads/main","deployTimestamp":1668787848577,"dockerfilePaths":{"nginx:1.14.2":""},"manifestsPaths":["https://github.com/jaiveerk/k8s-deploy/blob/c63b323186ea1320a31290de6dcc094c06385e75/test/integration/manifests/test.yml"],"helmChartPaths":[],"provider":"GitHub"} --overwrite --namespace test-3498366832`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Should throw well defined Error on error from Azure', async () => {
|
test('Should throw well defined Error on error from Azure', async () => {
|
||||||
const errorMsg = 'An error message'
|
const errorMsg = 'An error message'
|
||||||
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
|
||||||
return {exitCode: 1, stdout: '', stderr: errorMsg}
|
return { exitCode: 1, stdout: '', stderr: errorMsg }
|
||||||
})
|
})
|
||||||
|
|
||||||
await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
|
await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
|
||||||
|
|||||||
+64
-66
@@ -1,6 +1,6 @@
|
|||||||
import {Kubectl} from './kubectl'
|
import { Kubectl } from './kubectl'
|
||||||
import * as minimist from 'minimist'
|
import * as minimist from 'minimist'
|
||||||
import {ExecOptions, ExecOutput, getExecOutput} from '@actions/exec'
|
import { ExecOptions, ExecOutput, getExecOutput } from '@actions/exec'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
@@ -19,7 +19,7 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
|
|
||||||
if (this.containsFilenames(kubectlCmd)) {
|
if (this.containsFilenames(kubectlCmd)) {
|
||||||
// For private clusters, files will referenced solely by their basename
|
// For private clusters, files will referenced solely by their basename
|
||||||
kubectlCmd = this.replaceFilnamesWithBasenames(kubectlCmd)
|
kubectlCmd = replaceFileNamesWithBaseNames(kubectlCmd)
|
||||||
addFileFlag = true
|
addFileFlag = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,21 +43,19 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
]
|
]
|
||||||
|
|
||||||
if (addFileFlag) {
|
if (addFileFlag) {
|
||||||
const filenames = this.extractFilesnames(kubectlCmd).split(' ')
|
const filenames = extractFileNames(kubectlCmd)
|
||||||
|
|
||||||
const tempDirectory =
|
const tempDirectory =
|
||||||
process.env['runner.tempDirectory'] || os.tmpdir() + '/manifests'
|
process.env['runner.tempDirectory'] || os.tmpdir() + '/manifests'
|
||||||
eo.cwd = tempDirectory
|
eo.cwd = tempDirectory
|
||||||
privateClusterArgs.push(...['--file', '.'])
|
privateClusterArgs.push(...['--file', '.'])
|
||||||
|
|
||||||
let filenamesArr = filenames[0].split(',')
|
for (const filename of filenames) {
|
||||||
for (let index = 0; index < filenamesArr.length; index++) {
|
try {
|
||||||
const file = filenamesArr[index]
|
this.moveFileToTempManifestDir(filename)
|
||||||
|
} catch (e) {
|
||||||
if (!file) {
|
core.debug(`Error moving file ${filename} to temp directory: ${e}`)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
this.moveFileToTempManifestDir(file)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +78,7 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const runObj: {logs: string; exitCode: number} = JSON.parse(
|
const runObj: { logs: string; exitCode: number } = JSON.parse(
|
||||||
runOutput.stdout
|
runOutput.stdout
|
||||||
)
|
)
|
||||||
if (!silent) core.info(runObj.logs)
|
if (!silent) core.info(runObj.logs)
|
||||||
@@ -95,48 +93,6 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
} as ExecOutput
|
} as ExecOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
private replaceFilnamesWithBasenames(kubectlCmd: string) {
|
|
||||||
let exFilenames = this.extractFilesnames(kubectlCmd)
|
|
||||||
let filenames = exFilenames.split(' ')
|
|
||||||
let filenamesArr = filenames[0].split(',')
|
|
||||||
|
|
||||||
for (let index = 0; index < filenamesArr.length; index++) {
|
|
||||||
filenamesArr[index] = path.basename(filenamesArr[index])
|
|
||||||
}
|
|
||||||
|
|
||||||
let baseFilenames = filenamesArr.join()
|
|
||||||
|
|
||||||
let result = kubectlCmd.replace(exFilenames, baseFilenames)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
public extractFilesnames(strToParse: string) {
|
|
||||||
const fileNames: string[] = []
|
|
||||||
const argv = minimist(strToParse.split(' '))
|
|
||||||
const fArg = 'f'
|
|
||||||
const filenameArg = 'filename'
|
|
||||||
|
|
||||||
fileNames.push(...this.extractFilesFromMinimist(argv, fArg))
|
|
||||||
fileNames.push(...this.extractFilesFromMinimist(argv, filenameArg))
|
|
||||||
|
|
||||||
return fileNames.join(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
private extractFilesFromMinimist(argv, arg: string): string[] {
|
|
||||||
if (!argv[arg]) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
const toReturn: string[] = []
|
|
||||||
if (typeof argv[arg] === 'string') {
|
|
||||||
toReturn.push(...argv[arg].split(','))
|
|
||||||
} else {
|
|
||||||
for (const value of argv[arg] as string[]) {
|
|
||||||
toReturn.push(...value.split(','))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return toReturn
|
|
||||||
}
|
|
||||||
|
|
||||||
private containsFilenames(str: string) {
|
private containsFilenames(str: string) {
|
||||||
return str.includes('-f ') || str.includes('filename ')
|
return str.includes('-f ') || str.includes('filename ')
|
||||||
@@ -145,7 +101,7 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
private createTempManifestsDirectory() {
|
private createTempManifestsDirectory() {
|
||||||
const manifestsDir = '/tmp/manifests'
|
const manifestsDir = '/tmp/manifests'
|
||||||
if (!fs.existsSync('/tmp/manifests')) {
|
if (!fs.existsSync('/tmp/manifests')) {
|
||||||
fs.mkdirSync('/tmp/manifests', {recursive: true})
|
fs.mkdirSync('/tmp/manifests', { recursive: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,8 +110,8 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
if (!fs.existsSync('/tmp/' + file)) {
|
if (!fs.existsSync('/tmp/' + file)) {
|
||||||
core.debug(
|
core.debug(
|
||||||
'/tmp/' +
|
'/tmp/' +
|
||||||
file +
|
file +
|
||||||
' does not exist, and therefore cannot be moved to the manifest directory'
|
' does not exist, and therefore cannot be moved to the manifest directory'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,21 +119,63 @@ export class PrivateKubectl extends Kubectl {
|
|||||||
if (err) {
|
if (err) {
|
||||||
core.debug(
|
core.debug(
|
||||||
'Could not rename ' +
|
'Could not rename ' +
|
||||||
'/tmp/' +
|
'/tmp/' +
|
||||||
file +
|
file +
|
||||||
' to ' +
|
' to ' +
|
||||||
'/tmp/manifests/' +
|
'/tmp/manifests/' +
|
||||||
file +
|
file +
|
||||||
' ERROR: ' +
|
' ERROR: ' +
|
||||||
err
|
err
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
core.debug(
|
core.debug(
|
||||||
"Successfully moved file '" +
|
"Successfully moved file '" +
|
||||||
file +
|
file +
|
||||||
"' from /tmp to /tmp/manifest directory"
|
"' from /tmp to /tmp/manifest directory"
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function replaceFileNamesWithBaseNames(kubectlCmd: string) {
|
||||||
|
let filenames = extractFileNames(kubectlCmd)
|
||||||
|
let basenames = filenames.map((filename) => path.basename(filename))
|
||||||
|
|
||||||
|
let result = kubectlCmd
|
||||||
|
if (filenames.length != basenames.length) {
|
||||||
|
throw Error('replacing filenames with basenames, ' + filenames.length + ' filenames != ' + basenames.length + 'basenames')
|
||||||
|
}
|
||||||
|
for (let index = 0; index < filenames.length; index++) {
|
||||||
|
result = result.replace(filenames[index], basenames[index])
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractFileNames(strToParse: string) {
|
||||||
|
const fileNames: string[] = []
|
||||||
|
const argv = minimist(strToParse.split(' '))
|
||||||
|
const fArg = 'f'
|
||||||
|
const filenameArg = 'filename'
|
||||||
|
|
||||||
|
fileNames.push(...extractFilesFromMinimist(argv, fArg))
|
||||||
|
fileNames.push(...extractFilesFromMinimist(argv, filenameArg))
|
||||||
|
|
||||||
|
return fileNames
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractFilesFromMinimist(argv, arg: string): string[] {
|
||||||
|
if (!argv[arg]) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
const toReturn: string[] = []
|
||||||
|
if (typeof argv[arg] === 'string') {
|
||||||
|
toReturn.push(...argv[arg].split(','))
|
||||||
|
} else {
|
||||||
|
for (const value of argv[arg] as string[]) {
|
||||||
|
toReturn.push(...value.split(','))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toReturn
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user