Skip to content

Commit

Permalink
fix: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
shakefu committed Nov 4, 2023
1 parent bd15a44 commit e150f69
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 62 deletions.
72 changes: 54 additions & 18 deletions dist/main/index.js

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

2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

64 changes: 28 additions & 36 deletions python.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Python extends Tool {
}

async setup(desiredVersion) {
const [checkVersion, isVersionOverridden] = this.getVersion(
const [checkVersion, ] = this.getVersion(
desiredVersion,
".python-version",
)
Expand Down Expand Up @@ -58,42 +58,34 @@ export default class Python extends Tool {
this.logAndExit(`failed to check out setup-python`),
)

this.logAndExit("testing")

// Sanity check the python command works, and output its version
await this.validateVersion(checkVersion)

// Sanity check the pip command works, and output its version
await this.version("pip --version")

// If we got this far, we have successfully configured python.
core.setOutput(Python.tool, checkVersion)
this.info("python success!")
return checkVersion
}

async oldSetup(desiredVersion) {
// Check if pyenv exists and can be run, and capture the version info while
// we're at it
await this.findInstaller()

// Ensure we have the latest pyenv and python versions available
await this.updatePyenv()

// Set downstream environment variable for future steps in this Job
if (isVersionOverridden) {
core.exportVariable("PYENV_VERSION", checkVersion)
// Run the setup-python action
const actionPath = path.join(repositoryPath, "dist", "setup", "index.js")
const actionCommand = `node ${actionPath}`
core.debug(`actionCommand = '${actionCommand}'`)

// Actually run it
core.debug(`checkVersion = '${checkVersion}'`)
const opts = {
env: {
...process.env,
...(await this.getEnv()),
'INPUT_ALLOW-PRERELEASES': "FALSE",
'INPUT_ARCHITECTURE': "",
'INPUT_CACHE': "pip",
'INPUT_CACHE-DEPENDENCY-PATH': "",
'INPUT_CHECK-LATEST': "FALSE",
'INPUT_PYTHON-VERSION': checkVersion,
'INPUT_PYTHON-VERSION-FILE': "",
'INPUT_TOKEN': "",
'INPUT_UPDATE-ENVIRONMENT': "TRUE",
RUNNER_TOOL_CACHE: process.env.RUNNER_TOOL_CACHE || path.dirname(this.tempRoot),
RUNNER_DEBUG: "1",
}
}

// using -s option to skip the install and become a no-op if the
// version requested to be installed is already installed according to pyenv.
let installCommand = `pyenv install -s`
// pyenv install does not pick up the environment variable PYENV_VERSION
// unlike tfenv, so we specify it here as an argument explicitly, if it's set
if (isVersionOverridden) installCommand += ` ${checkVersion}`

await this.subprocessShell(installCommand).catch(
this.logAndExit(`failed to install python version ${checkVersion}`),
// This is super loud
// core.debug(`opts = '${JSON.stringify(opts)}'`)
await this.subprocessShell(actionCommand, opts).catch(
this.logAndExit(`failed to run setup-python`),
)

// Sanity check the python command works, and output its version
Expand Down
28 changes: 21 additions & 7 deletions python.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "path"

import Python from "./python"

import {
Expand All @@ -11,9 +13,17 @@ import {

Mute.all()

function getEnv(env){
return {
...env,
...ignoreInstalled(),
GITHUB_WORKSPACE: path.dirname(Python.tempRoot()),
}
}

describe("skipping slow tests", () => {
if (process.env.TEST_FAST) {
it.only("", () => {})
it.only("all python tests skipped", () => {})
}
})

Expand All @@ -23,10 +33,9 @@ describe("runAction python", () => {

it("works", async () => {
const desiredVersion = "3.10.2"
const env = {
const env = getEnv({
INPUT_PYTHON: desiredVersion,
...ignoreInstalled(),
}
})
return runAction("index", env).then((proc) => {
expect(proc.stderr.toString()).toBe("")
expect(proc.stdout).toContain(`python --version: ${desiredVersion}`)
Expand All @@ -36,12 +45,11 @@ describe("runAction python", () => {

it("fails with bad PYENV_ROOT", () => {
// This nonsense is to filter out pyenv if it's already on the path
const env = {
const env = getEnv({
INPUT_PYTHON: "3.10.2",
PYENV_ROOT: "/tmp/.pyenv",
PATH: cleanPath("pyenv"),
...ignoreInstalled(),
}
})
return expect(
runActionExpectError("index", env).catch((err) => {
throw new Error(err.stdout)
Expand All @@ -64,6 +72,12 @@ describe("install", () => {
describe("setup", () => {
const cleaner = new Cleaner(Python)
afterEach(cleaner.clean)
beforeEach(() => {
process.env.GITHUB_WORKSPACE = path.dirname(Python.tempRoot())
})
afterAll(() => {
delete process.env.GITHUB_WORKSPACE
})

it("works with an override version", () => {
return new Python().setup("3.10.2")
Expand Down

0 comments on commit e150f69

Please sign in to comment.