Skip to content

Commit 8edcd12

Browse files
authored
Merge branch 'actions:main' into main
2 parents ebfdb41 + c474c82 commit 8edcd12

12 files changed

+116
-62
lines changed

.github/workflows/check-dist.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525

2626
- name: Set Node.js 16.x
2727
uses: actions/setup-node@v3
@@ -45,7 +45,7 @@ jobs:
4545
id: diff
4646

4747
# If index.js was different than expected, upload the expected version as an artifact
48-
- uses: actions/upload-artifact@v2
48+
- uses: actions/upload-artifact@v3
4949
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
5050
with:
5151
name: dist

.github/workflows/codeql-analysis.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ jobs:
1818

1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v3
2222

2323
# Initializes the CodeQL tools for scanning.
2424
- name: Initialize CodeQL
25-
uses: github/codeql-action/init@v1
25+
uses: github/codeql-action/init@v2
2626
# Override language selection by uncommenting this and choosing your languages
2727
# with:
2828
# languages: go, javascript, csharp, python, cpp, java
2929

3030
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
3131
# If this step fails, then you should remove it and run the build manually (see below)
3232
- name: Autobuild
33-
uses: github/codeql-action/autobuild@v1
33+
uses: github/codeql-action/autobuild@v2
3434

3535
# ℹ️ Command-line programs to run using the OS shell.
3636
# 📚 https://git.io/JvXDl
@@ -44,4 +44,4 @@ jobs:
4444
# make release
4545

4646
- name: Perform CodeQL Analysis
47-
uses: github/codeql-action/analyze@v1
47+
uses: github/codeql-action/analyze@v2

.github/workflows/licensed.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
name: Check licenses
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717
- name: Set Node.js 16.x
1818
uses: actions/setup-node@v3
1919
with:

.github/workflows/release-new-action-version.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
steps:
2323
- name: Update the ${{ env.TAG_NAME }} tag
24-
uses: actions/publish-action@v0.1.0
24+
uses: actions/publish-action@v0.2.0
2525
with:
2626
source-tag: ${{ env.TAG_NAME }}
27-
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
27+
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

.github/workflows/test-pypy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
steps:
3636
- name: Checkout
37-
uses: actions/checkout@v2
37+
uses: actions/checkout@v3
3838

3939
- name: setup-python ${{ matrix.pypy }}
4040
id: setup-python

.github/workflows/workflow.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
operating-system: [ubuntu-latest, windows-latest]
1818
steps:
1919
- name: Checkout
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v3
2121

2222
- name: Set Node.js 16.x
2323
uses: actions/setup-node@v3

README.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ steps:
127127
- run: python my_script.py
128128
```
129129
130+
Download and set up the latest patch version of Python (for specified major & minor versions):
131+
```yaml
132+
steps:
133+
- uses: actions/checkout@v3
134+
- uses: actions/setup-python@v4
135+
with:
136+
python-version: '3.11-dev'
137+
- run: python my_script.py
138+
```
139+
140+
Download and set up the latest stable version of Python (for specified major version):
141+
```yaml
142+
steps:
143+
- uses: actions/checkout@v3
144+
- uses: actions/setup-python@v4
145+
with:
146+
python-version: '3.x'
147+
- run: python my_script.py
148+
```
149+
130150
Download and set up PyPy:
131151
132152
```yaml
@@ -320,6 +340,21 @@ steps:
320340
- run: pipenv install
321341
```
322342
343+
**Using a list of wildcard patterns to cache dependencies**
344+
```yaml
345+
steps:
346+
- uses: actions/checkout@v3
347+
- uses: actions/setup-python@v4
348+
with:
349+
python-version: '3.10'
350+
cache: 'pip'
351+
cache-dependency-path: |
352+
**/setup.cfg
353+
**/requirements*.txt
354+
- run: pip install -e . -r subdirectory/requirements-dev.txt
355+
```
356+
357+
323358
# Environment variables
324359
325360
The `update-environment` flag defaults to `true`.
@@ -357,7 +392,7 @@ If you are experiencing problems while configuring Python on your self-hosted ru
357392
### Linux
358393

359394
- The Python packages that are downloaded from `actions/python-versions` are originally compiled from source in `/opt/hostedtoolcache/` with the [--enable-shared](https://github.com/actions/python-versions/blob/94f04ae6806c6633c82db94c6406a16e17decd5c/builders/ubuntu-python-builder.psm1#L35) flag, which makes them non-relocatable.
360-
- Create an environment variable called `AGENT_TOOLSDIRECTORY` and set it to `/opt/hostedtoolcache`. This controls where the runner downloads and installs tools.
395+
- By default runner downloads and install the tools to `/opt/hostedtoolcache`. The environment variable called `AGENT_TOOLSDIRECTORY` can be set to change this location.
361396
- In the same shell that your runner is using, type `export AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`.
362397
- A more permanent way of setting the environment variable is to create a `.env` file in the same directory as your runner and to add `AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache`. This ensures the variable is always set if your runner is configured as a service.
363398
- Create a directory called `hostedtoolcache` inside `/opt`.

__tests__/find-pypy.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ describe('findPyPyVersion', () => {
151151
let spyChmodSync: jest.SpyInstance;
152152
let spyCoreAddPath: jest.SpyInstance;
153153
let spyCoreExportVariable: jest.SpyInstance;
154+
const env = process.env;
154155

155156
beforeEach(() => {
157+
jest.resetModules();
158+
process.env = {...env};
156159
tcFind = jest.spyOn(tc, 'find');
157160
tcFind.mockImplementation((tool: string, version: string) => {
158161
const semverRange = new semver.Range(version);
@@ -214,6 +217,7 @@ describe('findPyPyVersion', () => {
214217
jest.resetAllMocks();
215218
jest.clearAllMocks();
216219
jest.restoreAllMocks();
220+
process.env = env;
217221
});
218222

219223
it('found PyPy in toolcache', async () => {

__tests__/finder.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ const manifestData = require('./data/versions-manifest.json');
2828
describe('Finder tests', () => {
2929
let spyCoreAddPath: jest.SpyInstance;
3030
let spyCoreExportVariable: jest.SpyInstance;
31+
const env = process.env;
3132

3233
beforeEach(() => {
34+
jest.resetModules();
35+
process.env = {...env};
3336
spyCoreAddPath = jest.spyOn(core, 'addPath');
34-
3537
spyCoreExportVariable = jest.spyOn(core, 'exportVariable');
3638
});
3739

3840
afterEach(() => {
3941
jest.resetAllMocks();
4042
jest.clearAllMocks();
4143
jest.restoreAllMocks();
44+
process.env = env;
4245
});
4346

4447
it('Finds Python if it is installed', async () => {
@@ -66,7 +69,6 @@ describe('Finder tests', () => {
6669
await finder.useCpythonVersion('3.x', 'x64', false);
6770
expect(spyCoreAddPath).not.toHaveBeenCalled();
6871
expect(spyCoreExportVariable).not.toHaveBeenCalled();
69-
expect(spyCoreExportVariable).not.toHaveBeenCalled();
7072
});
7173

7274
it('Finds stable Python version if it is not installed, but exists in the manifest', async () => {

dist/setup/index.js

+27-20
Original file line numberDiff line numberDiff line change
@@ -64845,15 +64845,6 @@ function useCpythonVersion(version, architecture, updateEnvironment) {
6484564845
`The list of all available versions can be found here: ${installer.MANIFEST_URL}`
6484664846
].join(os.EOL));
6484764847
}
64848-
if (utils_1.IS_LINUX) {
64849-
const libPath = process.env.LD_LIBRARY_PATH
64850-
? `:${process.env.LD_LIBRARY_PATH}`
64851-
: '';
64852-
const pyLibPath = path.join(installDir, 'lib');
64853-
if (!libPath.split(':').includes(pyLibPath)) {
64854-
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
64855-
}
64856-
}
6485764848
const _binDir = binDir(installDir);
6485864849
const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : '';
6485964850
const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`);
@@ -65241,6 +65232,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6524165232
return (mod && mod.__esModule) ? mod : { "default": mod };
6524265233
};
6524365234
Object.defineProperty(exports, "__esModule", ({ value: true }));
65235+
exports.logWarning = void 0;
6524465236
const core = __importStar(__nccwpck_require__(2186));
6524565237
const finder = __importStar(__nccwpck_require__(9996));
6524665238
const finderPyPy = __importStar(__nccwpck_require__(4003));
@@ -65263,29 +65255,39 @@ function resolveVersionInput() {
6526365255
let version = core.getInput('python-version');
6526465256
let versionFile = core.getInput('python-version-file');
6526565257
if (version && versionFile) {
65266-
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used');
65258+
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used.');
6526765259
}
6526865260
if (version) {
6526965261
return version;
6527065262
}
65271-
versionFile = versionFile || '.python-version';
65272-
if (!fs_1.default.existsSync(versionFile)) {
65273-
throw new Error(`The specified python version file at: ${versionFile} does not exist`);
65263+
if (versionFile) {
65264+
if (!fs_1.default.existsSync(versionFile)) {
65265+
logWarning(`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`);
65266+
versionFile = '.python-version';
65267+
if (!fs_1.default.existsSync(versionFile)) {
65268+
throw new Error(`The ${versionFile} doesn't exist.`);
65269+
}
65270+
}
65271+
version = fs_1.default.readFileSync(versionFile, 'utf8');
65272+
core.info(`Resolved ${versionFile} as ${version}`);
65273+
return version;
6527465274
}
65275-
version = fs_1.default.readFileSync(versionFile, 'utf8');
65276-
core.info(`Resolved ${versionFile} as ${version}`);
65275+
core.warning("Neither 'python-version' nor 'python-version-file' inputs were supplied.");
6527765276
return version;
6527865277
}
6527965278
function run() {
6528065279
var _a;
6528165280
return __awaiter(this, void 0, void 0, function* () {
65282-
if ((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim()) {
65283-
core.debug(`Python is expected to be installed into AGENT_TOOLSDIRECTORY=${process.env['AGENT_TOOLSDIRECTORY']}`);
65281+
// According to the README windows binaries do not require to be installed
65282+
// in the specific location, but Mac and Linux do
65283+
if (!utils_1.IS_WINDOWS && !((_a = process.env.AGENT_TOOLSDIRECTORY) === null || _a === void 0 ? void 0 : _a.trim())) {
65284+
if (utils_1.IS_LINUX)
65285+
process.env['AGENT_TOOLSDIRECTORY'] = '/opt/hostedtoolcache';
65286+
else
65287+
process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
6528465288
process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
6528565289
}
65286-
else {
65287-
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE==${process.env['RUNNER_TOOL_CACHE']}`);
65288-
}
65290+
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}`);
6528965291
try {
6529065292
const version = resolveVersionInput();
6529165293
if (version) {
@@ -65318,6 +65320,11 @@ function run() {
6531865320
}
6531965321
});
6532065322
}
65323+
function logWarning(message) {
65324+
const warningPrefix = '[warning]';
65325+
core.info(`${warningPrefix}${message}`);
65326+
}
65327+
exports.logWarning = logWarning;
6532165328
run();
6532265329

6532365330

src/find-python.ts

-11
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ export async function useCpythonVersion(
7070
);
7171
}
7272

73-
if (IS_LINUX) {
74-
const libPath = process.env.LD_LIBRARY_PATH
75-
? `:${process.env.LD_LIBRARY_PATH}`
76-
: '';
77-
const pyLibPath = path.join(installDir, 'lib');
78-
79-
if (!libPath.split(':').includes(pyLibPath)) {
80-
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
81-
}
82-
}
83-
8473
const _binDir = binDir(installDir);
8574
const binaryExtension = IS_WINDOWS ? '.exe' : '';
8675
const pythonPath = path.join(

src/setup-python.ts

+34-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path';
55
import * as os from 'os';
66
import fs from 'fs';
77
import {getCacheDistributor} from './cache-distributions/cache-factory';
8-
import {isCacheFeatureAvailable} from './utils';
8+
import {isCacheFeatureAvailable, IS_LINUX, IS_WINDOWS} from './utils';
99

1010
function isPyPyVersion(versionSpec: string) {
1111
return versionSpec.startsWith('pypy');
@@ -28,37 +28,49 @@ function resolveVersionInput(): string {
2828

2929
if (version && versionFile) {
3030
core.warning(
31-
'Both python-version and python-version-file inputs are specified, only python-version will be used'
31+
'Both python-version and python-version-file inputs are specified, only python-version will be used.'
3232
);
3333
}
3434

3535
if (version) {
3636
return version;
3737
}
3838

39-
versionFile = versionFile || '.python-version';
40-
if (!fs.existsSync(versionFile)) {
41-
throw new Error(
42-
`The specified python version file at: ${versionFile} does not exist`
43-
);
39+
if (versionFile) {
40+
if (!fs.existsSync(versionFile)) {
41+
logWarning(
42+
`The specified python version file at: ${versionFile} doesn't exist. Attempting to find .python-version file.`
43+
);
44+
versionFile = '.python-version';
45+
if (!fs.existsSync(versionFile)) {
46+
throw new Error(`The ${versionFile} doesn't exist.`);
47+
}
48+
}
49+
50+
version = fs.readFileSync(versionFile, 'utf8');
51+
core.info(`Resolved ${versionFile} as ${version}`);
52+
53+
return version;
4454
}
45-
version = fs.readFileSync(versionFile, 'utf8');
46-
core.info(`Resolved ${versionFile} as ${version}`);
55+
56+
core.warning(
57+
"Neither 'python-version' nor 'python-version-file' inputs were supplied."
58+
);
4759

4860
return version;
4961
}
5062

5163
async function run() {
52-
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
53-
core.debug(
54-
`Python is expected to be installed into AGENT_TOOLSDIRECTORY=${process.env['AGENT_TOOLSDIRECTORY']}`
55-
);
64+
// According to the README windows binaries do not require to be installed
65+
// in the specific location, but Mac and Linux do
66+
if (!IS_WINDOWS && !process.env.AGENT_TOOLSDIRECTORY?.trim()) {
67+
if (IS_LINUX) process.env['AGENT_TOOLSDIRECTORY'] = '/opt/hostedtoolcache';
68+
else process.env['AGENT_TOOLSDIRECTORY'] = '/Users/runner/hostedtoolcache';
5669
process.env['RUNNER_TOOL_CACHE'] = process.env['AGENT_TOOLSDIRECTORY'];
57-
} else {
58-
core.debug(
59-
`Python is expected to be installed into RUNNER_TOOL_CACHE==${process.env['RUNNER_TOOL_CACHE']}`
60-
);
6170
}
71+
core.debug(
72+
`Python is expected to be installed into RUNNER_TOOL_CACHE=${process.env['RUNNER_TOOL_CACHE']}`
73+
);
6274
try {
6375
const version = resolveVersionInput();
6476
if (version) {
@@ -101,4 +113,9 @@ async function run() {
101113
}
102114
}
103115

116+
export function logWarning(message: string): void {
117+
const warningPrefix = '[warning]';
118+
core.info(`${warningPrefix}${message}`);
119+
}
120+
104121
run();

0 commit comments

Comments
 (0)