Skip to content

Commit

Permalink
Add automatic toolchain version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Jul 13, 2024
1 parent f406a0a commit 774504b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,34 @@ jobs:
version: latest
- run: rye sync
working-directory: __tests__/fixtures/rye-project

test-latest-automatic-toolchain:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-14, oracle-aarch64]
steps:
- uses: actions/checkout@v4
- name: Determine expected python version
id: determine-expected-python-version
run: |
EXPECTED_PYTHON_VERSION=$(cat .python-version)
echo "EXPECTED_PYTHON_VERSION=$EXPECTED_PYTHON_VERSION" >> "$GITHUB_OUTPUT"
working-directory: __tests__/fixtures/rye-project
- name: Setup rye
uses: ./
with:
version: latest
working-directory: __tests__/fixtures/rye-project
- run: rye sync
working-directory: __tests__/fixtures/rye-project
- name: Check python version
run: |
ACTUAL_PYTHON_VERSION=$(ls $RYE_HOME/py)
if [ "$ACTUAL_PYTHON_VERSION" != "$EXPECTED_PYTHON_VERSION" ];
then
echo "$ACTUAL_PYTHON_VERSION is not the same as $EXPECTED_PYTHON_VERSION"
exit 1
fi
env:
EXPECTED_PYTHON_VERSION: ${{ steps.determine-expected-python-version.outputs.EXPECTED_PYTHON_VERSION }}
17 changes: 16 additions & 1 deletion dist/setup/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/setup/index.js.map

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions src/setup-rye.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as io from '@actions/io'
import * as path from 'path'
import * as fs from 'fs'
import {downloadVersion, tryGetFromCache} from './download/download-version'
import {restoreCache} from './restore-cache'
import {restoreCache, workingDir} from './restore-cache'
import {
Architecture,
EARLIEST_VERSION_WITH_NO_MODIFY_PATHSUPPORT,
Expand Down Expand Up @@ -103,13 +103,18 @@ async function installRye(
core.debug(`Created temporary directory ${tempDir}`)
// Cache first to get the correct path
const cachedPath = await tc.cacheDir(tempDir, toolsCacheName, version, arch)
const toolchainVersion = await determineToolchainVersion()
const env = toolchainVersion
? {
...process.env,
RYE_HOME: cachedPath,
RYE_TOOLCHAIN_VERSION: toolchainVersion
}
: {...process.env, RYE_HOME: cachedPath}
const options: exec.ExecOptions = {
cwd: cachedPath,
silent: !core.isDebug(),
env: {
...process.env,
RYE_HOME: cachedPath
}
env: env
}
core.info(`Installing Rye into ${cachedPath}`)
const execArgs = ['self', 'install', '--yes']
Expand All @@ -122,6 +127,22 @@ async function installRye(
return cachedPath
}

async function determineToolchainVersion(): Promise<string | void> {
const pythonVersionFile = `${workingDir}${path.sep}.python_version`
if (fs.existsSync(pythonVersionFile)) {
const toolchainVersion = await fs.promises.readFile(
pythonVersionFile,
'utf8'
)
core.info(`Determined RYE_TOOLCHAIN_VERSION: ${toolchainVersion}`)
return toolchainVersion
}
core.warning(
`No .python_version file found, using default RYE_TOOLCHAIN_VERSION`
)
return
}

async function createConfigBackup(installedPath: string): Promise<void> {
if (fs.existsSync(`${installedPath}${path.sep}${RYE_CONFIG_TOML}`)) {
await io.cp(
Expand Down

0 comments on commit 774504b

Please sign in to comment.