Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- convert to TypeScript
  • Loading branch information
StephenHodgson authored Aug 15, 2024
1 parent 6e5263a commit 5389f07
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 83 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [macos-latest, windows-latest, ubuntu-latest]

steps:
- uses: actions/checkout@v4
Expand All @@ -30,20 +30,17 @@ jobs:
auth-token: ${{ secrets.UPM_AUTH_TOKEN }}

- run: |
# macOS and Linux '~/.upmconfig.toml'
# windows '%USERPROFILE%\.upmconfig.toml'
if [[ "$OSTYPE" == "msys" ]]; then
upmconfig="$USERPROFILE\\.upmconfig.toml"
else
upmconfig="$HOME/.upmconfig.toml"
fi
if [[ ! -f "$upmconfig" ]]; then
echo ".upmconfig.toml does not exist"
exit 1
fi
echo "upmconfig: $upmconfig"
cat "$upmconfig"
chmod +w "$upmconfig"
rm "$upmconfig"
shell: bash
Expand All @@ -56,20 +53,17 @@ jobs:
password: ${{ secrets.UPM_PASSWORD }}

- run: |
# macOS and Linux '~/.upmconfig.toml'
# windows '%USERPROFILE%\.upmconfig.toml'
if [[ "$OSTYPE" == "msys" ]]; then
upmconfig="$USERPROFILE\\.upmconfig.toml"
else
upmconfig="$HOME/.upmconfig.toml"
fi
if [[ ! -f "$upmconfig" ]]; then
echo ".upmconfig.toml does not exist"
exit 1
fi
echo "upmconfig: $upmconfig"
cat "$upmconfig"
chmod +w "$upmconfig"
rm "$upmconfig"
shell: bash
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Buildalon: Automate Unity
Copyright (c) 2024 Virtual Maker Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ steps:
| `username` | The username for the private scoped registry. | Required if auth-token is not provided. |
| `password` | The password for the private scoped registry. | Required if auth-token is not provided. |
| `always-auth` | Whether to always authenticate with the private scoped registry. Defaults to `true`. | false |
| `overwrite` | Whether to overwrite the existing configuration file. | false |
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ inputs:
description: 'Whether to always authenticate with the private scoped registry. Defaults to true.'
required: false
default: 'true'

overwrite:
description: 'Whether to overwrite the existing configuration file. Defaults to false.'
required: false
runs:
using: 'node20'
main: 'dist/index.js'
86 changes: 48 additions & 38 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26147,20 +26147,23 @@ exports["default"] = _default;

/***/ }),

/***/ 867:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
/***/ 2409:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Run = Run;
const core = __nccwpck_require__(2186);
const exec = __nccwpck_require__(1514);
const path = __nccwpck_require__(1017);
const fs = __nccwpck_require__(3292);

const fs = __nccwpck_require__(7147);
async function Run() {
const registry_url = core.getInput('registry-url', { required: true });
const registry_url = core.getInput('registry-url', { required: true }).trim();
let auth_token = core.getInput('auth-token');
if (!auth_token) {
const username = core.getInput('username', { required: true });
const password = core.getInput('password', { required: true });
const username = core.getInput('username', { required: true }).trim();
const password = core.getInput('password', { required: true }).trim();
auth_token = await authenticate(registry_url, username, password);
}
else {
Expand All @@ -26171,12 +26174,9 @@ async function Run() {
await validate_auth_token(registry_url, auth_token);
await save_upm_config(registry_url, auth_token);
}

module.exports = { Run };

async function authenticate(registry_url, username, password) {
core.debug('Authenticating...');
const ascii_auth = `${username}:${password}`.toString('ascii');
const ascii_auth = Buffer.from(`${username}:${password}`).toString('ascii');
const base64_auth = Buffer.from(ascii_auth).toString('base64');
core.setSecret(base64_auth);
const payload = {
Expand Down Expand Up @@ -26205,11 +26205,11 @@ async function authenticate(registry_url, username, password) {
const auth_token = response.token;
core.setSecret(auth_token);
return auth_token;
} else {
}
else {
throw new Error(response.error);
}
}

async function validate_auth_token(registry_url, auth_token) {
core.debug('Validating the auth token...');
let output = '';
Expand All @@ -26233,28 +26233,42 @@ async function validate_auth_token(registry_url, auth_token) {
throw new Error(response.error);
}
}

async function save_upm_config(registry_url, auth_token) {
core.debug('Saving .upmconfig.toml...');
const upm_config_toml_path = get_upm_config_toml_path();
core.debug(`upm_config_toml_path: "${upm_config_toml_path}"`);
const overwrite = core.getInput('overwrite') === 'true';
try {
await fs.access(upm_config_toml_path);
} catch (error) {
await fs.writeFile(upm_config_toml_path, '');
const fileHandle = await fs.promises.open(upm_config_toml_path, 'r');
try {
if (overwrite) {
await fs.promises.writeFile(upm_config_toml_path, '');
}
}
finally {
fileHandle.close();
}
}
catch (error) {
await fs.promises.writeFile(upm_config_toml_path, '');
}
if (process.platform !== 'win32') {
await fs.chmod(upm_config_toml_path, 0o777);
await fs.promises.chmod(upm_config_toml_path, 0o777);
}
const upm_config_toml = await fs.readFile(upm_config_toml_path, 'utf-8');
const upm_config_toml = await fs.promises.readFile(upm_config_toml_path, 'utf-8');
if (!upm_config_toml.includes(registry_url)) {
const alwaysAuth = core.getInput('always-auth') === 'true';
await fs.appendFile(upm_config_toml_path, `registry_url = "${registry_url}"\nauth_token = "${auth_token}"\nalwaysAuth = ${alwaysAuth}\n`);
await fs.promises.appendFile(upm_config_toml_path, `[npmAuth."${registry_url}"]\ntoken = "${auth_token}"\nalwaysAuth = ${alwaysAuth}\n`);
}
const fileHandle = await fs.promises.open(upm_config_toml_path, 'r');
try {
const content = await fileHandle.readFile({ encoding: 'utf-8' });
core.debug(`.upmconfig.toml:\n${content}`);
}
finally {
fileHandle.close();
}
}

function get_upm_config_toml_path() {
// macOS and Linux '~/.upmconfig.toml'
// winodows '%USERPROFILE%\.upmconfig.toml'
switch (process.platform) {
case 'win32':
return path.join(process.env.USERPROFILE, '.upmconfig.toml');
Expand All @@ -26263,6 +26277,7 @@ function get_upm_config_toml_path() {
}
}


/***/ }),

/***/ 4978:
Expand Down Expand Up @@ -26345,14 +26360,6 @@ module.exports = require("fs");

/***/ }),

/***/ 3292:
/***/ ((module) => {

"use strict";
module.exports = require("fs/promises");

/***/ }),

/***/ 3685:
/***/ ((module) => {

Expand Down Expand Up @@ -28177,20 +28184,23 @@ module.exports = parseParams
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
(() => {
const core = __nccwpck_require__(2186);
const upm_config = __nccwpck_require__(867);
"use strict";
var exports = __webpack_exports__;

Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __nccwpck_require__(2186);
const upm_config = __nccwpck_require__(2409);
const main = async () => {
try {
await upm_config.Run();
} catch (error) {
}
catch (error) {
core.setFailed(error);
process.exit(1);
}
}

};
main();

})();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 5389f07

Please sign in to comment.