Skip to content

start #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# runtime dependencies are checked in
# dev dependencies are *not* checked in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't have to be part of this initial PR, but maybe we should just webpack as part of our build process. Then we can just ignore node modules

Copy link
Contributor

@damccorm damccorm Jun 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note also - this also doesn't really work to not check in dev dependencies. While this doesn't check in the top level dev-deps, nested dependencies will still get checked in. For example, Prettier alone has ~60 dependencies all of which get checked in (not to mention the dependencies of those dependencies).

I think webpack is probably the best path forward here.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we doing this to avoid having to npm install the production dependencies of this tool? If so, there are a few options for vendoring in dependencies that we already use at GitHub. If you can give me a sense of the goal with this, I can advise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runner will run the action from the github graph at runtime per the execution model. That is, it will get the targz of that ref and run it.

Dependencies are vendored in as you noted.

@damccorm - regarding dev dependencies, you can use npm prune before you publish (push).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool - didn't know about npm prune. It looks like that handles all devDependencies though, so we probably don't need those listed in gitignore. It also might be good to enforce that with something like husky

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #5 proposing using husky

node_modules/.bin
node_modules/typescript
node_modules/@types
node_modules/prettier
__tests__/runner/*
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@
This action sets by node environment for use in actions by:

- optionally downloading and caching a version of node - npm by version spec and add to PATH
- registering problem matchers for error output
- configuring authentication for npm packages
- configuring proxy if the runner is configured to use a proxy (coming with private runners)
- TODO: registering problem matchers for error output
- TODO: configuring authentication for npm packages
- TODO: configuring proxy if the runner is configured to use a proxy (coming with private runners)

# Usage

@@ -40,4 +40,8 @@ workflow:

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
The scripts and documentation in this project are released under the [MIT License](LICENSE)

# Contributions

Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
96 changes: 96 additions & 0 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');

const toolDir = path.join(__dirname, 'runner', 'tools');
const tempDir = path.join(__dirname, 'runner', 'temp');

process.env['RUNNER_TOOLSDIRECTORY'] = toolDir;
process.env['RUNNER_TEMPDIRECTORY'] = tempDir;
import * as installer from '../src/installer';

describe('installer tests', () => {
beforeAll(() => {});
beforeAll(async () => {
await io.rmRF(toolDir);
await io.rmRF(tempDir);
});

it('Acquires version of node if no matching version is installed', async () => {
await installer.getNode('10.16.0');
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
}, 100000);

if (process.platform === 'win32') {
it('Falls back to backup location if first one doesnt contain correct version', async () => {
await installer.getNode('5.10.1');
const nodeDir = path.join(toolDir, 'node', '5.10.1', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
}, 100000);

it('Falls back to third location if second one doesnt contain correct version', async () => {
await installer.getNode('0.12.18');
const nodeDir = path.join(toolDir, 'node', '0.12.18', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
}, 100000);
}

it('Throws if no location contains correct node version', async () => {
let thrown = false;
try {
await installer.getNode('1000');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
});

it('Acquires version of node with long paths', async () => {
const toolpath = await installer.getNode('8.8.1');
const nodeDir = path.join(toolDir, 'node', '8.8.1', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
}, 100000);

it('Uses version of node installed in cache', async () => {
const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch());
await io.mkdirP(nodeDir);
fs.writeFileSync(`${nodeDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getNode('250.0.0');
return;
});

it('Doesnt use version of node that was only partially installed in cache', async () => {
const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch());
await io.mkdirP(nodeDir);
let thrown = false;
try {
// This will throw if it doesn't find it in the cache (because no such version exists)
await installer.getNode('251.0.0');
} catch {
thrown = true;
}
expect(thrown).toBe(true);
return;
});

it('Resolves semantic versions of node installed in cache', async () => {
const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch());
await io.mkdirP(nodeDir);
fs.writeFileSync(`${nodeDir}.complete`, 'hello');
// These will throw if it doesn't find it in the cache (because no such version exists)
await installer.getNode('250.0.0');
await installer.getNode('250');
await installer.getNode('250.0');
});
});
5 changes: 1 addition & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -5,9 +5,6 @@ inputs:
version:
description: 'Version Spec of the version to use. Examples: 10.x, 10.15.1, >=10.15.0'
default: '10.x'
checkLatest:
description: 'Always checks online for the latest available version that satisfies the version spec. This is typically false unless you have a specific scenario to always get latest. This will cause it to incur download costs when potentially not necessary, especially with the hosted build pool.'
default: 'false'
runs:
using: 'node'
main: 'usenode.js'
main: 'lib/setup-node.js'
17 changes: 17 additions & 0 deletions docs/contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributors


# Checkin

- Do checkin source (src)
- Do checkin build output (lib)
- Do checkin runtime node_modules
- Do not checkin

# Adding a dev dependency

Remember to update .gitignore.

# Updating toolkit dependency

Until released publically, update tgz packages in toolkit
Binary file added externals/7zr.exe
Binary file not shown.
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}
Loading
Oops, something went wrong.