generated from actions/typescript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of intalling argocd cli in github action
- Loading branch information
1 parent
0b8b282
commit 030088d
Showing
10 changed files
with
384 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,4 @@ | |
"es6": true, | ||
"jest/globals": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
name: integration | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- 'dist/**' | ||
- 'src/**' | ||
- 'action.yml' | ||
- 'yarn.lock' | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'dist/**' | ||
- 'src/**' | ||
- 'action.yml' | ||
- 'yarn.lock' | ||
|
||
jobs: | ||
no-auth: | ||
name: Download w/o auth | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [macos-latest, windows-latest, ubuntu-latest] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Show version | ||
uses: ./ | ||
with: | ||
command: version | ||
options: --client | ||
|
||
- name: Check install - should not re-download | ||
uses: ./ | ||
|
||
with-auth: | ||
name: Download with auth | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [macos-latest, windows-latest, ubuntu-latest] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Show version | ||
uses: ./ | ||
env: | ||
# Only required for first step in workflow where API is called | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
command: version | ||
options: --client | ||
|
||
- name: Check install - should not re-download | ||
uses: ./ | ||
|
||
set-version: | ||
name: Set version | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [macos-latest, windows-latest, ubuntu-latest] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Show version | ||
uses: ./ | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
version: 1.8.0 | ||
command: version | ||
options: --client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
name: Argo CD Action | ||
author: Clowd Haus, LLC | ||
description: GitHub action for executing Argo CD | ||
description: GitHub action for installing/executing Argo CD cli | ||
branding: | ||
icon: anchor | ||
color: gray-dark | ||
|
||
inputs: | ||
command: | ||
description: > | ||
Command passed to the cli | ||
Reference - https://argoproj.github.io/argo-cd/user-guide/commands/argocd/ | ||
required: false | ||
options: | ||
description: > | ||
Command options passed to the cli | ||
Reference - https://argoproj.github.io/argo-cd/user-guide/commands/argocd/ | ||
required: false | ||
version: | ||
description: > | ||
Version of Argo CD to install - https://github.com/argoproj/argo-cd/releases | ||
required: false | ||
default: 1.8.4 | ||
|
||
runs: | ||
using: node12 | ||
main: dist/index.js |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import * as core from '@actions/core'; | ||
import * as exec from '@actions/exec'; | ||
import * as tc from '@actions/tool-cache'; | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import * as process from 'process'; | ||
import {createActionAuth} from '@octokit/auth-action'; | ||
import {Octokit} from '@octokit/rest'; | ||
import {existsSync, promises as fs} from 'fs'; | ||
|
||
const PLATFORM = process.platform; | ||
const EXE_NAME = PLATFORM === 'win32' ? 'argocd.exe' : 'argocd'; | ||
const ASSET_DEST = path.join(os.homedir(), EXE_NAME); | ||
|
||
enum Executable { | ||
aix, | ||
android, | ||
cygwin, | ||
freebsd, | ||
netbsd, | ||
openbsd, | ||
sunos, | ||
darwin = 'argocd-darwin-amd64', | ||
linux = 'argocd-linux-amd64', | ||
win32 = 'argocd-windows-amd64.exe', | ||
} | ||
|
||
export default class ArgoCD { | ||
private readonly path: string; | ||
|
||
private constructor(exePath: string) { | ||
this.path = exePath; | ||
} | ||
|
||
static async getOrDownload(version: string): Promise<ArgoCD> { | ||
if (existsSync(ASSET_DEST)) { | ||
return new ArgoCD(ASSET_DEST); | ||
} else { | ||
core.debug('Unable to find "argocd" executable, downloading it now'); | ||
return await ArgoCD.download(version); | ||
} | ||
} | ||
|
||
static async getExecutableUrl(version: string): Promise<string> { | ||
// If hitting GitHub API rate limit, add `GITHUB_TOKEN` to raise limit | ||
const octoConfig = process.env.GITHUB_TOKEN ? {authStrategy: createActionAuth} : {}; | ||
const octokit = new Octokit(octoConfig); | ||
const executable = Executable[PLATFORM]; | ||
|
||
try { | ||
const releases = await octokit.repos.getReleaseByTag({ | ||
owner: 'argoproj', | ||
repo: 'argo-cd', | ||
tag: `v${version}`, | ||
}); | ||
|
||
const asset = releases.data.assets.filter((rel: any) => rel.name === executable)[0]; | ||
return asset.browser_download_url; | ||
} catch (err) { | ||
core.setFailed(`Action failed with error ${err}`); | ||
return ''; | ||
} | ||
} | ||
|
||
// download executable for the appropriate platform | ||
static async download(version: string): Promise<ArgoCD> { | ||
const exeutableUrl = await ArgoCD.getExecutableUrl(version); | ||
core.debug(`[debug()] getExecutableUrl: ${exeutableUrl}`); | ||
const assetPath = await tc.downloadTool(exeutableUrl, ASSET_DEST); | ||
core.addPath(assetPath); | ||
|
||
if (PLATFORM !== 'win32') { | ||
await fs.chmod(assetPath, 0o755); | ||
} | ||
|
||
return new ArgoCD(assetPath); | ||
} | ||
|
||
async version(): Promise<string> { | ||
const stdout = await this.callStdout(['version', '--client']); | ||
return stdout.split(' ')[1]; | ||
} | ||
|
||
async call(args: string[], options?: Record<string, unknown>): Promise<number> { | ||
return await exec.exec(this.path, args, options); | ||
} | ||
|
||
// Call the cli and return stdout | ||
async callStdout(args: string[], options?: Record<string, unknown>): Promise<string> { | ||
let stdout = ''; | ||
const resOptions = Object.assign({}, options, { | ||
listeners: { | ||
stdout: (buffer: Buffer) => { | ||
stdout += buffer.toString(); | ||
}, | ||
}, | ||
}); | ||
|
||
await this.call(args, resOptions); | ||
|
||
return stdout; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.