Skip to content

Commit

Permalink
Test cases (#6)
Browse files Browse the repository at this point in the history
* initial test ourselves

* Added in_container test

* New names, check Python

* don't setup python in containers

* Added comments on actions/setup-python@v2

* Updated README

* Added pythonExe option

* Actually use and check rez python

* Updated tests

* Actually test with pythonExe
  • Loading branch information
j0yu authored Jul 19, 2021
1 parent f925173 commit 6e84942
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 17 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/test-cases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Tests
on: push

jobs:
no_container:
name: "On VM: ${{ matrix.platform }} Py${{ matrix.python }}"
runs-on: ${{ matrix.platform }}-latest
strategy:
matrix:
platform: [ubuntu, windows, macos]
python: [2.7, 3.7]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- uses: ./.
- name: Check rez installed
run: rez --version

in_container:
name: "In CentOS 7: ${{ matrix.yum_python }}"
runs-on: ubuntu-latest
container:
image: "centos:7"
strategy:
matrix:
yum_python:
- "python" # Python 2.7
- "python3" # Python 3.6

steps:
- run: yum install -y ${{ matrix.yum_python }}
- uses: actions/checkout@v2
# ---- WARNING: using actions/setup-python@v2 ----
# It MAY conflict with container's on Python interpreter/glibc
# e.g. for centos:7, which ships with it's own python2.7 and
# in that case, don't use "actions/setup-python@v2" and just
# let "j0yu/setup-rez" use the system's Python interpreter
- uses: ./.
with:
pythonExe: ${{ matrix.yum_python }}
- name: Check rez installed
run: rez --version
- name: Check rez python version is correct
run: |
set -x
rez python -V | tee rez_python.txt
${{ matrix.yum_python }} -V | tee python.txt
diff -y rez_python.txt python.txt
59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![CI](https://github.com/j0yu/setup-rez/workflows/CI/badge.svg?branch=master)](https://github.com/j0yu/setup-rez/actions?query=branch%3Amaster+workflow%3ACI)
[![CI](https://github.com/j0yu/setup-rez/workflows/CI/badge.svg?branch=main)](https://github.com/j0yu/setup-rez/actions?query=branch:main+workflow:CI)

# setup-rez

Expand Down Expand Up @@ -34,8 +34,8 @@ Github Action to setup [rez] package system.
## Example
Make sure you run [actions/setup-python](github.com/actions/setup-python)
before using [j0yu/setup-rez](github.com/j0yu/setup-rez)
For VMs, make sure you run [actions/setup-python] before using
[j0yu/setup-rez] so it has access to a Python Interpreter.
```yaml
name: CI
Expand All @@ -55,7 +55,7 @@ jobs:
with:
source: "mottosso/bleeding-rez"
ref: "2.33.0"

# Check if rez is on PATH, check configs and rez bind packages
- run: rez --version
- run: rez config local_packages_path
Expand All @@ -69,6 +69,46 @@ jobs:
- run: rez build --install
```
### Containers
If you're using [`container`](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idcontainer)
you'll need to install Python as per the image/system instead of using [actions/setup-python].


```yaml
name: CI
on: [push]
jobs:
test-centos7:
name: Test CentOS 7 (${{ matrix.yum_python }})
runs-on: ubuntu-latest
container:
image: "centos:7"
strategy:
matrix:
yum_python:
- "python" # Python 2.7
- "python3" # Python 3.6
steps:
- run: yum install -y ${{ matrix.yum_python }}
- uses: j0yu/setup-rez@v1
with:
pythonExe: ${{ matrix.yum_python }}
- run: rez --version
- run: rez python -V
```

In this example, `centos:7` uses an old `glibc` and isn't compatible with
[actions/setup-python]. But `rez` is ok with Python 2.7 and above (as recent as 2.93.0):

- `python`: [j0yu/setup-rez] will use a slightly updated Python 2.7 interpreter that's
already shipped with `centos:7`.
- `python3`: [j0yu/setup-rez] will run rez's `install.py` using `python3`
(nice coincidence) as the interpreter, instead of the default `python`.


## How it works

Everything is done in the `run` function in `index.js`:
Expand All @@ -77,7 +117,7 @@ Everything is done in the `run` function in `index.js`:
1. If there is no installs/tools cache install rez:
1. Downloads and extracts from `https://github.com/${source}/archive/${ref}.tar.gz`
1. If `install.py` exists, install via `python install.py DEST`

else, if `setup.py` exists, install via `pip install --target DEST SRC`
1. Store required environment variable paths to append in a `setup.json`
1. Load and append environment variables paths from `setup.json`
Expand All @@ -89,10 +129,10 @@ Everything is done in the `run` function in `index.js`:

Notes on install style availability:

Rez | (1st) install.py | (2nd) pip install
Rez | (1st) install.py | (2nd) pip install
----------------------|------------------|------------------
nerdvegas/rez | Always | 2.33.0+
mottosso/bleeding-rez | NEVER | Always
nerdvegas/rez | Always | 2.33.0+
mottosso/bleeding-rez | NEVER | Always


## Developing
Expand Down Expand Up @@ -141,6 +181,9 @@ worked on CentOS-7. See [Creating a JavaScript action].

</details>


[j0yu/setup-rez]: github.com/j0yu/setup-rez
[actions/setup-python]: github.com/actions/setup-python
[GitHub Action Toolkit Sub-Packages]: https://github.com/actions/toolkit#packages
[Metadata Syntax]: https://help.github.com/en/actions/building-actions/metadata-syntax-for-github-actions
[Node.js 12x]: https://nodejs.org/dist/latest-v12.x/docs/api/
Expand Down
12 changes: 12 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ inputs:
required: false
default: 'master'

pythonExe:
description: |
Python executable to run install.py with.
Can be switched to a more specific executable name, python3.6, or even
the full path to the interperter, /opt/rh/rh-python38/root/usr/bin/python3
Internally passed as commandLine to actions/toolkit:exec.exec()
https://github.com/actions/toolkit/blob/main/packages/exec/src/exec.ts#L12
required: false
default: 'python'

makePackagesPaths:
description: Create all default "rez config packages_path".
required: false
Expand Down
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ async function getRepoRootFile(fileName, extractedPath) {
// Tarball extracts to repo name + git ref sub-folder
const srcFolder = await getDirentPath(
extractedPath,
(dirent) => {return dirent.isDirectory()},
(dirent) => { return dirent.isDirectory() },
);
if (srcFolder) {
const filePath = await getDirentPath(
srcFolder,
(dirent) => {return dirent.isFile() && dirent.name == fileName},
(dirent) => { return dirent.isFile() && dirent.name == fileName },
);
if (filePath) {
return filePath;
Expand Down Expand Up @@ -73,10 +73,11 @@ async function getRepoRootFile(fileName, extractedPath) {
*
* @param {string} rezGitRepo "user or org"/"repository name"
* @param {string} gitRef master or commit hash or tag name or branch name.
* @param {string} pythonExe command line to feed exec.exec() as Python interpreter.
* @returns {envPaths} Environment variable names and paths to add for
* them to setup the installed/cached rez install.
*/
async function installRez(rezGitRepo, gitRef) {
async function installRez(rezGitRepo, gitRef, pythonExe) {
var rezInstallPath = tc.find(rezGitRepo, gitRef);
if (rezInstallPath.length) {
var manifestData = null;
Expand All @@ -94,7 +95,7 @@ async function installRez(rezGitRepo, gitRef) {
let exeArgs = [];
let filePath = '';
let rezInstall = {};
const binFolder = ((process.platform == 'win32') ? 'Scripts': 'bin');
const binFolder = ((process.platform == 'win32') ? 'Scripts' : 'bin');

const downloadURL = `https://github.com/${rezGitRepo}/archive/${gitRef}.tar.gz`;
core.info(`Downloading "${downloadURL}"...`);
Expand All @@ -104,7 +105,7 @@ async function installRez(rezGitRepo, gitRef) {

try {
filePath = await getRepoRootFile('install.py', rezInstallPath);
exeArgs = ['python', filePath, rezInstallPath];
exeArgs = [pythonExe, filePath, rezInstallPath];
rezInstall['PATH'] = [path.join(rezInstallPath, binFolder, 'rez')];
} catch (error) {
if (error.name != 'MissingFileError') {
Expand Down Expand Up @@ -147,7 +148,7 @@ async function makePackagesPaths() {
let output = '';

await exec.exec('rez', ['config', 'packages_path'], {
listeners: {stdout: (data) => (output += data.toString())},
listeners: { stdout: (data) => (output += data.toString()) },
})
for (line of output.trim().split(os.EOL)) {
await io.mkdirP(line.replace(/^- /, ''));
Expand All @@ -166,7 +167,7 @@ function addPathsToEnvs(envPaths) {
for (varName in envPaths) {
if (varName == 'PATH') {
// Make rez bin available for binding later, if any
envPaths[varName].forEach(element => {core.addPath(element)});
envPaths[varName].forEach(element => { core.addPath(element) });
} else {
// Add to current process.env so exec.exec will also pick it up
currentPath = process.env[varName];
Expand All @@ -190,7 +191,7 @@ async function run() {
try {
// Export relevant env vars for a rez install
addPathsToEnvs(
await installRez(core.getInput('source'), core.getInput('ref'))
await installRez(core.getInput('source'), core.getInput('ref'), core.getInput('pythonExe'))
);

// Create all packages_path folders
Expand All @@ -203,7 +204,7 @@ async function run() {
// Create local packages path
let output = '';
await exec.exec('rez', ['config', 'local_packages_path'], {
listeners: {stdout: (data) => (output += data.toString())},
listeners: { stdout: (data) => (output += data.toString()) },
})
await io.mkdirP(output.trimRight());

Expand Down

0 comments on commit 6e84942

Please sign in to comment.