Skip to content

Commit 39c08a0

Browse files
author
Danny McCormick
committed
Initial pass
0 parents  commit 39c08a0

File tree

7,242 files changed

+1886006
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,242 files changed

+1886006
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!node_modules/
2+
__tests__/runner/*

.prettierrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": true,
6+
"singleQuote": true,
7+
"trailingComma": "none",
8+
"bracketSpacing": false,
9+
"arrowParens": "avoid",
10+
"parser": "typescript"
11+
}

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2018 GitHub, Inc. and contributors
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Node 12 Template Action
2+
3+
To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/).

__tests__/finder.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import io = require('@actions/io');
2+
import fs = require('fs');
3+
import os = require('os');
4+
import path = require('path');
5+
6+
const toolDir = path.join(
7+
process.cwd(),
8+
'runner',
9+
path.join(
10+
Math.random()
11+
.toString(36)
12+
.substring(7)
13+
),
14+
'tools'
15+
);
16+
const tempDir = path.join(
17+
process.cwd(),
18+
'runner',
19+
path.join(
20+
Math.random()
21+
.toString(36)
22+
.substring(7)
23+
),
24+
'temp'
25+
);
26+
27+
process.env['RUNNER_TOOLSDIRECTORY'] = toolDir;
28+
process.env['RUNNER_TEMPDIRECTORY'] = tempDir;
29+
30+
import * as finder from '../src/find-python';
31+
32+
describe('Finder tests', () => {
33+
it('Finds Python if it is installed', async () => {});
34+
35+
it('Errors if Python is not installed', async () => {});
36+
37+
it('Finds PyPy if it is installed', async () => {});
38+
39+
it('Errors if PyPy is not installed', async () => {});
40+
});

action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Setup Node.js for use with actions'
2+
description: 'Setup a Node.js environment and add it to the PATH, additionally providing proxy support'
3+
author: 'GitHub'
4+
inputs:
5+
version:
6+
description: 'Version range or exact version of a Python version to use, using semver's version range syntax.'
7+
default: '3.x'
8+
architecture:
9+
description: 'The target architecture (x86, x64) of the Python interpreter.'
10+
runs:
11+
using: 'node'
12+
main: 'lib/setup-python.js'

docs/contributors.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributors
2+
3+
### Checkin
4+
5+
- Do checkin source (src)
6+
- Do checkin build output (lib)
7+
- Do checkin runtime node_modules
8+
- Do not checkin devDependency node_modules (husky can help see below)
9+
10+
### devDependencies
11+
12+
In order to handle correctly checking in node_modules without devDependencies, we run [Husky](https://github.com/typicode/husky) before each commit.
13+
This step ensures that formatting and checkin rules are followed and that devDependencies are excluded. To make sure Husky runs correctly, please use the following workflow:
14+
15+
```
16+
npm install # installs all devDependencies including Husky
17+
git add abc.ext # Add the files you've changed. This should include files in src, lib, and node_modules (see above)
18+
git commit -m "Informative commit message" # Commit. This will run Husky
19+
```
20+
21+
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) as well as pruning out devDependencies using `npm prune --production`.
22+
It will also make sure these changes are appropriately included in your commit (no further work is needed)

jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
clearMocks: true,
3+
moduleFileExtensions: ['js', 'ts'],
4+
testEnvironment: 'node',
5+
testMatch: ['**/*.test.ts'],
6+
testRunner: 'jest-circus/runner',
7+
transform: {
8+
'^.+\\.ts$': 'ts-jest'
9+
},
10+
verbose: true
11+
}

lib/find-python.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
var __importStar = (this && this.__importStar) || function (mod) {
11+
if (mod && mod.__esModule) return mod;
12+
var result = {};
13+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
14+
result["default"] = mod;
15+
return result;
16+
};
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
const os = __importStar(require("os"));
19+
const path = __importStar(require("path"));
20+
const semver = __importStar(require("semver"));
21+
let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || '';
22+
if (!cacheDirectory) {
23+
let baseLocation;
24+
if (process.platform === 'win32') {
25+
// On windows use the USERPROFILE env variable
26+
baseLocation = process.env['USERPROFILE'] || 'C:\\';
27+
}
28+
else {
29+
if (process.platform === 'darwin') {
30+
baseLocation = '/Users';
31+
}
32+
else {
33+
baseLocation = '/home';
34+
}
35+
}
36+
cacheDirectory = path.join(baseLocation, 'actions', 'cache');
37+
}
38+
const core = __importStar(require("@actions/core"));
39+
const tc = __importStar(require("@actions/tool-cache"));
40+
const IS_WINDOWS = process.platform === 'win32';
41+
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
42+
// This is where pip is, along with anything that pip installs.
43+
// There is a seperate directory for `pip install --user`.
44+
//
45+
// For reference, these directories are as follows:
46+
// macOS / Linux:
47+
// <sys.prefix>/bin (by default /usr/local/bin, but not on hosted agents -- see the `else`)
48+
// (--user) ~/.local/bin
49+
// Windows:
50+
// <Python installation dir>\Scripts
51+
// (--user) %APPDATA%\Python\PythonXY\Scripts
52+
// See https://docs.python.org/3/library/sysconfig.html
53+
function binDir(installDir) {
54+
if (IS_WINDOWS) {
55+
return path.join(installDir, 'Scripts');
56+
}
57+
else {
58+
return path.join(installDir, 'bin');
59+
}
60+
}
61+
// Note on the tool cache layout for PyPy:
62+
// PyPy has its own versioning scheme that doesn't follow the Python versioning scheme.
63+
// A particular version of PyPy may contain one or more versions of the Python interpreter.
64+
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
65+
// We only care about the Python version, so we don't use the PyPy version for the tool cache.
66+
function usePyPy(majorVersion, architecture) {
67+
const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion.toString());
68+
let installDir = findPyPy(architecture);
69+
if (!installDir && IS_WINDOWS) {
70+
// PyPy only precompiles binaries for x86, but the architecture parameter defaults to x64.
71+
// On Hosted VS2017, we only install an x86 version.
72+
// Fall back to x86.
73+
installDir = findPyPy('x86');
74+
}
75+
if (!installDir) {
76+
// PyPy not installed in $(Agent.ToolsDirectory)
77+
throw new Error(`PyPy ${majorVersion} not found`);
78+
}
79+
// For PyPy, Windows uses 'bin', not 'Scripts'.
80+
const _binDir = path.join(installDir, 'bin');
81+
// On Linux and macOS, the Python interpreter is in 'bin'.
82+
// On Windows, it is in the installation root.
83+
const pythonLocation = IS_WINDOWS ? installDir : _binDir;
84+
core.exportVariable('pythonLocation', pythonLocation);
85+
core.addPath(installDir);
86+
core.addPath(_binDir);
87+
}
88+
function useCpythonVersion(version, architecture) {
89+
return __awaiter(this, void 0, void 0, function* () {
90+
const desugaredVersionSpec = desugarDevVersion(version);
91+
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
92+
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
93+
const installDir = tc.find('Python', semanticVersionSpec, architecture);
94+
if (!installDir) {
95+
// Fail and list available versions
96+
const x86Versions = tc
97+
.findAllVersions('Python', 'x86')
98+
.map(s => `${s} (x86)`)
99+
.join(os.EOL);
100+
const x64Versions = tc
101+
.findAllVersions('Python', 'x64')
102+
.map(s => `${s} (x64)`)
103+
.join(os.EOL);
104+
throw new Error([
105+
`Version ${version} with arch ${architecture} not found`,
106+
'Available versions:',
107+
x86Versions,
108+
x64Versions
109+
].join(os.EOL));
110+
}
111+
core.exportVariable('pythonLocation', installDir);
112+
core.addPath(installDir);
113+
core.addPath(binDir(installDir));
114+
if (IS_WINDOWS) {
115+
// Add --user directory
116+
// `installDir` from tool cache should look like $AGENT_TOOLSDIRECTORY/Python/<semantic version>/x64/
117+
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
118+
const version = path.basename(path.dirname(installDir));
119+
const major = semver.major(version);
120+
const minor = semver.minor(version);
121+
const userScriptsDir = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}`, 'Scripts');
122+
core.addPath(userScriptsDir);
123+
}
124+
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
125+
});
126+
}
127+
/** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */
128+
function desugarDevVersion(versionSpec) {
129+
if (versionSpec.endsWith('-dev')) {
130+
const versionRoot = versionSpec.slice(0, -'-dev'.length);
131+
return `>= ${versionRoot}.0-a0`;
132+
}
133+
else {
134+
return versionSpec;
135+
}
136+
}
137+
/**
138+
* Python's prelease versions look like `3.7.0b2`.
139+
* This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
140+
* If the version spec contains prerelease versions, we need to convert them to the semantic version equivalent.
141+
*/
142+
function pythonVersionToSemantic(versionSpec) {
143+
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc)\d*)/g;
144+
return versionSpec.replace(prereleaseVersion, '$1-$2');
145+
}
146+
exports.pythonVersionToSemantic = pythonVersionToSemantic;
147+
function findPythonVersion(version, architecture) {
148+
return __awaiter(this, void 0, void 0, function* () {
149+
switch (version.toUpperCase()) {
150+
case 'PYPY2':
151+
return usePyPy(2, architecture);
152+
case 'PYPY3':
153+
return usePyPy(3, architecture);
154+
default:
155+
return yield useCpythonVersion(version, architecture);
156+
}
157+
});
158+
}
159+
exports.findPythonVersion = findPythonVersion;

lib/setup-python.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3+
return new (P || (P = Promise))(function (resolve, reject) {
4+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7+
step((generator = generator.apply(thisArg, _arguments || [])).next());
8+
});
9+
};
10+
var __importStar = (this && this.__importStar) || function (mod) {
11+
if (mod && mod.__esModule) return mod;
12+
var result = {};
13+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
14+
result["default"] = mod;
15+
return result;
16+
};
17+
Object.defineProperty(exports, "__esModule", { value: true });
18+
const core = __importStar(require("@actions/core"));
19+
const finder = __importStar(require("./find-python"));
20+
function run() {
21+
return __awaiter(this, void 0, void 0, function* () {
22+
const version = core.getInput('version');
23+
if (version) {
24+
const arch = core.getInput('architecture', { required: true });
25+
yield finder.findPythonVersion(version, arch);
26+
}
27+
});
28+
}
29+
run();

node_modules/.bin/acorn

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/acorn.cmd

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/atob

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/atob.cmd

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/escodegen

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)