Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions actions/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ Pre-requisites:

Example usage:

```yaml
on:
workflow_dispatch: {}
jobs:
demo-setup:
runs-on: ubuntu-latest
steps:
- name: Install Teleport
uses: teleport-actions/setup@v1
with:
# specify version as "auto" and provide the address of your Teleport
# proxy using the "proxy" input.
version: auto
proxy: example.teleport.sh:443
- run: tsh # tsh, tbot and tctl will now be available
```

You can also specify a particular version of the Teleport binaries to install:

```yaml
on:
workflow_dispatch: {}
Expand Down
5 changes: 4 additions & 1 deletion actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ description: 'Installs `teleport`, `tsh`, `tbot` and `tctl`.'
inputs:
version:
required: true
description: 'Specify the Teleport version without the preceding "v"'
description: 'Specify the Teleport version without the preceding "v" or specify "auto" to use the version indicated by your Teleport cluster.'
proxy:
description: 'Specify the address of your Teleport Proxy, required if version is set to "auto".'
required: false
enterprise:
required: false
default: 'false'
Expand Down
2 changes: 1 addition & 1 deletion actions/setup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup",
"version": "1.0.6",
"version": "1.1.0",
"license": "Apache-2.0",
"repository": "https://github.com/teleport-actions/setup.git",
"scripts": {
Expand Down
54 changes: 43 additions & 11 deletions actions/setup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,67 @@ function versionString(
interface Inputs {
version: string;
enterprise: boolean;
proxyAddr: string;
}

function getInputs(): Inputs {
const version = core.getInput('version');
if (version === '') {
throw new Error("'version' input must be non-empty");
}
if (version.startsWith('v')) {
throw new Error("'version' input should not be prefixed with 'v'");
}
const versionRegex =
/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/i;

if (!versionRegex.test(version)) {
throw new Error(
"incorrect 'version' specified, it should include all parts of the version e.g 11.0.1"
);
}

const enterprise = core.getBooleanInput('enterprise');
const proxyAddr = core.getInput('proxy');

if (version !== 'auto') {
if (version.startsWith('v')) {
throw new Error("'version' input should not be prefixed with 'v'");
}
const versionRegex =
/^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/i;

if (!versionRegex.test(version)) {
throw new Error(
"incorrect 'version' specified, it should include all parts of the version e.g 11.0.1 or be set to 'auto'"
);
}
} else {
if (proxyAddr === '') {
throw new Error(
"'proxy' input must be non-empty when 'version' is set to 'auto'"
);
}
}

return {
version,
enterprise,
proxyAddr,
};
}

async function fetchVersionFromProxy(proxyAddr: string): Promise<string> {
const resp = await fetch(`https://${proxyAddr}/webapi/find`);
const data = await resp.json();
const version = data?.auto_update?.tools_version;
if (!version) {
throw new Error(
`malformed response from proxy missing version: ${JSON.stringify(data)}`
);
}
return version;
}

async function run(): Promise<void> {
const inputs = getInputs();

if (inputs.version === 'auto') {
core.info(`Fetching version from proxy: ${inputs.proxyAddr}`);
const proxyVersion = await fetchVersionFromProxy(inputs.proxyAddr);
core.info(`Fetched version: ${proxyVersion}`);
inputs.version = proxyVersion;
}

const version = versionString(os.platform(), os.arch(), inputs.version);
const toolName = inputs.enterprise ? 'teleport-ent' : 'teleport';
core.info(`Installing ${toolName} ${version}`);
Expand Down
Loading