Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.
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
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,58 @@ It uses an API token to connect to the cluster.

The parameters input must be in form `parameters: '{"apitoken": "${{ secrets.API_TOKEN }}"}'`

## How does OpenShift Action work?

The action has been built to be quite flexible and be used in different use-cases - only set up `oc` to be used later on, or handle the login to the OpenShift cluster or execute a list of oc commands. Based on the inputs the action will behave accordingly.

#### Setup Oc

If you are only interested in setting up `oc` so to use it in a following script, you only need to define the version of the oc cli to be downloaded.

```yaml
steps:
- name: OpenShift Action
uses: redhat-developer/openshift-action
with:
version: '3.11.90'
- name: followingScript
run: |
oc login --token=${{ secrets.API_TOKEN }} --server=${{ secrets.OPENSHIFT_SERVER_URL }}
oc get pods | grep build
```

#### Setup Oc and log in to the Cluster

If you want the extension to handle the login you have to define the cluster url and the parameters needed to log in.

```yaml
steps:
- name: OpenShift Action
uses: redhat-developer/openshift-action
with:
version: '3.11.90'
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.API_TOKEN }}", "acceptUntrustedCerts": "true"}'
- name: followingScript
run: oc get pods | grep build
```
#### Setup Oc, log in to the cluster and execute commands

In case you just want to execute commands on your cluster, you can directly define them inside the action.

```yaml
steps:
- name: OpenShift Action
uses: redhat-developer/openshift-action
with:
version: '3.11.90'
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.API_TOKEN }}", "acceptUntrustedCerts": "true"}'
cmd: |
'get pods'
'new-project name'
```

## Example `workflow.yml` with Openshift Action

```yaml
Expand Down
39 changes: 37 additions & 2 deletions lib/src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
*-----------------------------------------------------------------------------------------------*/
const core = require("@actions/core");
const fs = require("mz/fs");
const glob = require("glob");
const io = require("@actions/io/lib/io");
const ioUtil = require("@actions/io/lib/io-util");
const path = require("path");
Expand Down Expand Up @@ -66,9 +67,9 @@ class Installer {
downloadDir = yield tc.extractTar(pathOcArchive);
}
let ocBinary = Installer.ocBinaryByOS(runnerOS);
ocBinary = path.join(downloadDir, ocBinary);
ocBinary = yield Installer.findOcFile(downloadDir, ocBinary);
if (!(yield ioUtil.exists(ocBinary))) {
return { found: false, reason: `An error occurred while downloading and extracting oc binary from ${url}.` };
return { found: false, reason: `An error occurred while downloading and extracting oc binary from ${url}. File ${ocBinary} not found.` };
}
fs.chmodSync(ocBinary, '0755');
if (versionToCache) {
Expand Down Expand Up @@ -247,5 +248,39 @@ class Installer {
return 'oc.exe';
return 'oc';
}
/**
* Adds oc to the PATH environment variable.
*
* @param ocPath the full path to the oc binary. Must be a non null.
* @param osType the OS type. One of 'Linux', 'Darwin' or 'Windows_NT'.
*/
static addOcToPath(ocPath, osType) {
if (!ocPath) {
core.debug('Unable to add null or empty Oc path to the PATH.');
return;
}
let dir = '';
if (osType.includes('Windows')) {
dir = ocPath.substr(0, ocPath.lastIndexOf('\\'));
}
else {
dir = ocPath.substr(0, ocPath.lastIndexOf('/'));
}
core.addPath(dir);
}
static findOcFile(folder, file) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
glob(`${folder}/**/${file}`, (err, res) => {
if (err) {
reject(new Error(`Unable to find oc exewcutable inside the directory ${folder}`));
}
else {
resolve(res[0]);
}
});
});
});
}
}
exports.Installer = Installer;
12 changes: 6 additions & 6 deletions lib/src/ocExec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ function run() {
core.debug(version);
core.debug(runnerOS);
core.debug(process.env.RUNNER_TEMP);
if (!args) {
return Promise.reject(new Error('Invalid cmd input. Insert at least one command to be executed.'));
}
const cmds = args.split('\n');
const binaryVersion = execHelper_1.convertStringToBinaryVersion(version);
const ocBinary = yield installer_1.Installer.installOc(binaryVersion, runnerOS, useLocalOc === 'true');
if (ocBinary.found === false) {
return Promise.reject(new Error(execHelper_1.getReason(ocBinary)));
}
const endpoint = auth_1.OcAuth.initOpenShiftEndpoint(openShiftUrl, parameters);
yield auth_1.OcAuth.loginOpenshift(endpoint, ocBinary.path);
installer_1.Installer.addOcToPath(ocBinary.path, runnerOS);
if (openShiftUrl && parameters) {
const endpoint = auth_1.OcAuth.initOpenShiftEndpoint(openShiftUrl, parameters);
yield auth_1.OcAuth.loginOpenshift(endpoint, ocBinary.path);
}
const cmds = args ? args.split('\n') : [];
for (const cmd of cmds) {
// eslint-disable-next-line no-await-in-loop
yield command_1.Command.execute(ocBinary.path, cmd);
Expand Down
5 changes: 5 additions & 0 deletions node_modules/balanced-match/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/balanced-match/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions node_modules/balanced-match/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions node_modules/balanced-match/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading