FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add auth and ci by damccorm · Pull Request #2 · actions/setup-node · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (3) .json  (1) .md  (1) .ts  (3) .workflow  (1) All 5 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 21 additions & 0 deletions .github/main.workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
workflow "CI" {
on = "push"
resolves = ["Format", "Build"]
}

action "Dependencies" {
uses = "actions/npm@v2.0.0"
args = "install"
}

action "Build" {
needs = "Dependencies"
uses = "actions/npm@v2.0.0"
args = "run build"
}

action "Format" {
needs = "Dependencies"
uses = "actions/npm@v2.0.0"
args = "run format-check"
}
13 changes: 12 additions & 1 deletion README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
- TODO: registering problem matchers for error output
- TODO: configuring authentication for npm packages
- optionally configuring authentication for npm packages
- TODO: configuring proxy if the runner is configured to use a proxy (coming with private runners)

# Usage
Expand Down Expand Up @@ -38,6 +38,17 @@ workflow:
- run: npm test
```

Auth:
```yaml
actions:
- uses: actions/setup-node@latest
with:
registryUrl: 'https://mycustomregistry.example.org'
registryToken: $ {{ token }}
authFile: 'optional/path/to/.npmrc/file'
- run: npm publish
```

# License

The scripts and documentation in this project are released under the [MIT License](LICENSE)
Expand Down
40 changes: 40 additions & 0 deletions lib/auth.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
function setNpmrc(registryUrl, registryToken, authFile) {
let projectNpmrc = path.resolve(process.cwd(), '.npmrc');
if (authFile) {
projectNpmrc = path.resolve(process.cwd(), authFile);
}
let newContents = '';
if (fs.existsSync(projectNpmrc)) {
const curContents = fs.readFileSync(projectNpmrc, 'utf8');
curContents.split(os.EOL).forEach(line => {
// Add current contents unless they are setting the registry
if (!line.startsWith('registry')) {
newContents += line + os.EOL;
}
});
}
newContents +=
'registry=' +
registryUrl +
os.EOL +
'always-auth=true' +
os.EOL +
registryUrl +
':_authToken=${NPM_TOKEN}';
fs.writeFileSync(projectNpmrc, newContents);
core.exportSecret('NPM_TOKEN', registryToken);
}
exports.setNpmrc = setNpmrc;
3 changes: 1 addition & 2 deletions lib/installer.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ function getNode(versionSpec) {
//
// prepend the tools path. instructs the agent to prepend for future tasks
//
// TODO - addPath not implemented yet (this should probably actually be in core)
// tc.addPath(toolPath);
core.addPath(toolPath);
});
}
exports.getNode = getNode;
Expand Down
7 changes: 7 additions & 0 deletions lib/setup-node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const auth = __importStar(require("./auth"));
const installer = __importStar(require("./installer"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -29,6 +30,12 @@ function run() {
// TODO: installer doesn't support proxy
yield installer.getNode(version);
}
const registryUrl = core.getInput('registryUrl');
if (registryUrl) {
const registryToken = core.getInput('registryToken', { required: true });
const authFile = core.getInput('authFile');
auth.setNpmrc(registryUrl, registryToken, authFile);
}
// TODO: setup proxy from runner proxy config
// TODO: problem matchers registered
}
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

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

37 changes: 37 additions & 0 deletions src/auth.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as core from '@actions/core';
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';

export function setNpmrc(
registryUrl: string,
registryToken: string,
authFile?: string
) {
let projectNpmrc: string = path.resolve(process.cwd(), '.npmrc');
if (authFile) {
projectNpmrc = path.resolve(process.cwd(), authFile);
}

let newContents = '';
if (fs.existsSync(projectNpmrc)) {
const curContents = fs.readFileSync(projectNpmrc, 'utf8');
curContents.split(os.EOL).forEach(line => {
// Add current contents unless they are setting the registry
if (!line.startsWith('registry')) {
newContents += line + os.EOL;
}
});
}
newContents +=
'registry=' +
registryUrl +
os.EOL +
'always-auth=true' +
os.EOL +
registryUrl +
':_authToken=${NPM_TOKEN}';
fs.writeFileSync(projectNpmrc, newContents);

core.exportSecret('NPM_TOKEN', registryToken);
}
3 changes: 1 addition & 2 deletions src/installer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export async function getNode(versionSpec: string) {
//
// prepend the tools path. instructs the agent to prepend for future tasks
//
// TODO - addPath not implemented yet (this should probably actually be in core)
// tc.addPath(toolPath);
core.addPath(toolPath);
}

async function queryLatestMatch(versionSpec: string): Promise<string> {
Expand Down
8 changes: 8 additions & 0 deletions src/setup-node.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import * as auth from './auth';
import * as installer from './installer';

async function run() {
Expand All @@ -13,6 +14,13 @@ async function run() {
await installer.getNode(version);
}

const registryUrl = core.getInput('registryUrl');
if (registryUrl) {
const registryToken = core.getInput('registryToken', {required: true});
const authFile = core.getInput('authFile');
auth.setNpmrc(registryUrl, registryToken, authFile);
}

// TODO: setup proxy from runner proxy config
// TODO: problem matchers registered
} catch (error) {
Expand Down

Back | FazBrowse Home | New Git URL