@halospv3/hce.shared-config 2.4.3 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/cjs/dotnet/createDummyNupkg.cjs +26 -0
- package/cjs/dotnet/createDummyNupkg.cjs.map +1 -0
- package/cjs/dotnet/createDummyNupkg.d.ts +2 -0
- package/cjs/dotnet/createDummyNupkg.d.ts.map +1 -0
- package/cjs/dotnet/dotnetGHPR.cjs +119 -30
- package/cjs/dotnet/dotnetGHPR.cjs.map +1 -1
- package/cjs/dotnet/dotnetGHPR.d.ts +26 -3
- package/cjs/dotnet/dotnetGHPR.d.ts.map +1 -1
- package/cjs/dotnet/dotnetGLPR.cjs +7 -7
- package/cjs/dotnet/dotnetGLPR.cjs.map +1 -1
- package/cjs/dotnet/dotnetHelpers.cjs +4 -3
- package/cjs/dotnet/dotnetHelpers.cjs.map +1 -1
- package/cjs/dotnet-wrapper.mjs +1 -1
- package/cjs/dotnet.cjs +6 -4
- package/cjs/dotnet.cjs.map +1 -1
- package/cjs/dotnet.d.ts +3 -2
- package/cjs/dotnet.d.ts.map +1 -1
- package/cjs/envUtils-wrapper.mjs +6 -0
- package/cjs/envUtils.cjs +37 -0
- package/cjs/envUtils.cjs.map +1 -0
- package/cjs/envUtils.d.ts +16 -0
- package/cjs/envUtils.d.ts.map +1 -0
- package/cjs/eslintConfig.cjs +3 -3
- package/cjs/eslintConfig.d.ts.map +1 -1
- package/cjs/semanticReleaseConfig.d.ts.map +1 -1
- package/cjs/semanticReleaseConfigDotnet.cjs +8 -6
- package/cjs/semanticReleaseConfigDotnet.cjs.map +1 -1
- package/cjs/semanticReleaseConfigDotnet.d.ts.map +1 -1
- package/cjs/setupGitPluginSpec.d.ts.map +1 -1
- package/package.json +9 -6
- package/src/dotnet/createDummyNupkg.ts +30 -0
- package/src/dotnet/dotnetGHPR.ts +136 -35
- package/src/dotnet/dotnetGLPR.ts +5 -5
- package/src/dotnet/dotnetHelpers.ts +4 -4
- package/src/dotnet.ts +3 -2
- package/src/envUtils.ts +36 -0
- package/src/eslintConfig.ts +3 -3
- package/src/index.ts +1 -1
- package/src/semantic-release__git.d.ts +1 -1
- package/src/semanticReleaseConfig.ts +2 -2
- package/src/semanticReleaseConfigDotnet.ts +8 -6
- package/src/setupGitPluginSpec.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [2.6.0](https://github.com/halospv3/hce.shared/compare/v2.5.0...v2.6.0) (2024-06-07)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add createDummyNupkg ([ed67d06](https://github.com/halospv3/hce.shared/commit/ed67d06cd06e56a78b0a9ff2e51efb83ddd94386)), closes [#406](https://github.com/halospv3/hce.shared/issues/406)
|
|
6
|
+
* add EnvUtils (getEnvVarValue, getEnv) ([f86562a](https://github.com/halospv3/hce.shared/commit/f86562aa1c19a13a612e6571ba2122bf134ba196))
|
|
7
|
+
|
|
8
|
+
## [2.5.0](https://github.com/halospv3/hce.shared/compare/v2.4.3...v2.5.0) (2024-06-04)
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* overhaul dotnetGHPR; misc refactors ([8d0a1d6](https://github.com/halospv3/hce.shared/commit/8d0a1d657e7f4754881c9a130fd4aa8191fb3e81))
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([e1defcd](https://github.com/halospv3/hce.shared/commit/e1defcd94ba51eda7384c1ca87f33c9928610e20))
|
|
17
|
+
* **deps:** update semantic-release monorepo ([39fcf98](https://github.com/halospv3/hce.shared/commit/39fcf988fe55b894e269d64de1b48c7f8dfb950c))
|
|
18
|
+
|
|
1
19
|
## [2.4.3](https://github.com/halospv3/hce.shared/compare/v2.4.2...v2.4.3) (2024-05-31)
|
|
2
20
|
|
|
3
21
|
|
|
@@ -5,6 +23,13 @@
|
|
|
5
23
|
|
|
6
24
|
* fix error being thrown because an 'else' is missing ([a4ed781](https://github.com/halospv3/hce.shared/commit/a4ed781dd9ebf696deae7b7914d8cf77e2beb5fb))
|
|
7
25
|
|
|
26
|
+
## [2.4.3-develop.1](https://github.com/halospv3/hce.shared/compare/v2.4.2...v2.4.3-develop.1) (2024-06-01)
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* **deps:** update dependency conventional-changelog-conventionalcommits to v8 ([e1defcd](https://github.com/halospv3/hce.shared/commit/e1defcd94ba51eda7384c1ca87f33c9928610e20))
|
|
31
|
+
* **deps:** update semantic-release monorepo ([39fcf98](https://github.com/halospv3/hce.shared/commit/39fcf988fe55b894e269d64de1b48c7f8dfb950c))
|
|
32
|
+
|
|
8
33
|
## [2.4.2](https://github.com/halospv3/hce.shared/compare/v2.4.1...v2.4.2) (2024-05-31)
|
|
9
34
|
|
|
10
35
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_child_process = require('node:child_process');
|
|
4
|
+
const node_fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const tmp = require('tmp');
|
|
7
|
+
function createDummyNupkg() {
|
|
8
|
+
const dirResult = tmp.dirSync({
|
|
9
|
+
unsafeCleanup: true
|
|
10
|
+
});
|
|
11
|
+
const dummyPkgFullPath = path.join(dirResult.name, 'DUMMY.1.0.0.nupkg');
|
|
12
|
+
|
|
13
|
+
// delete old and possibly-poisoned nupkg
|
|
14
|
+
if (node_fs.existsSync(dummyPkgFullPath)) node_fs.unlinkSync(dummyPkgFullPath);
|
|
15
|
+
const options = {
|
|
16
|
+
cwd: dirResult.name,
|
|
17
|
+
encoding: 'utf8'
|
|
18
|
+
};
|
|
19
|
+
node_child_process.execSync('dotnet new console --name DUMMY', options);
|
|
20
|
+
const packOut = node_child_process.execSync(`dotnet pack DUMMY --configuration Release --output ${path.dirname(dummyPkgFullPath)}`, options);
|
|
21
|
+
const createdLine = packOut.replace('\r', '').split('\n').find(line => line.includes('Successfully created package'))?.trim();
|
|
22
|
+
if (!node_fs.existsSync(dummyPkgFullPath)) throw new Error(`The dummy nupkg was created, but could not be found at ${dummyPkgFullPath}. See '${createdLine}'.`);
|
|
23
|
+
return dummyPkgFullPath;
|
|
24
|
+
}
|
|
25
|
+
exports.createDummyNupkg = createDummyNupkg;
|
|
26
|
+
//# sourceMappingURL=createDummyNupkg.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDummyNupkg.cjs","sources":["../../src/dotnet/createDummyNupkg.ts"],"sourcesContent":null,"names":["dirSync","join","existsSync","unlinkSync","execSync","dirname"],"mappings":";;;;;;;AAIO,SAAS,gBAAgB,GAAG;AACnC,EAAE,MAAM,SAAS,GAAGA,WAAO,CAAC;AAC5B,IAAI,aAAa,EAAE,IAAI;AACvB,GAAG,CAAC,CAAC;AACL,EAAE,MAAM,gBAAgB,GAAGC,SAAI,CAAC,SAAS,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;AACrE;AACA;AACA,EAAE,IAAIC,kBAAU,CAAC,gBAAgB,CAAC,EAAEC,kBAAU,CAAC,gBAAgB,CAAC,CAAC;AACjE,EAAE,MAAM,OAAO,GAAG;AAClB,IAAI,GAAG,EAAE,SAAS,CAAC,IAAI;AACvB,IAAI,QAAQ,EAAE,MAAM;AACpB,GAAG,CAAC;AACJ,EAAEC,2BAAQ,CAAC,iCAAiC,EAAE,OAAO,CAAC,CAAC;AACvD,EAAE,MAAM,OAAO,GAAGA,2BAAQ,CAAC,CAAC,mDAAmD,EAAEC,YAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AACvH,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;AAChI,EAAE,IAAI,CAACH,kBAAU,CAAC,gBAAgB,CAAC,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,uDAAuD,EAAE,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1J,EAAE,OAAO,gBAAgB,CAAC;AAC1B;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDummyNupkg.d.ts","sourceRoot":"","sources":["../../src/dotnet/createDummyNupkg.ts"],"names":[],"mappings":"AAKA,wBAAgB,gBAAgB,IAAI,MAAM,CAwBzC"}
|
|
@@ -1,61 +1,150 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const strict = require('node:assert/strict');
|
|
4
|
+
const node_child_process = require('node:child_process');
|
|
5
|
+
const node_util = require('node:util');
|
|
6
|
+
const envUtils = require('../envUtils.cjs');
|
|
7
|
+
const createDummyNupkg = require('./createDummyNupkg.cjs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param tokenEnvVar The name of the environment variable containing the NUGET token
|
|
11
|
+
* @returns `true` if the token can be used to push nupkg to the given Nuget registry
|
|
12
|
+
* @throws
|
|
13
|
+
* - TypeError: The environment variable ${tokenEnvVar} is undefined!
|
|
14
|
+
* - Error:
|
|
15
|
+
* - The value of the token in ${tokenEnvVar} begins with 'github_pat_' which means it's a Fine-Grained token. At the time of writing, GitHub Fine-Grained tokens cannot push packages. If you believe this is statement is outdated, report the issue at https://github.com/halospv3/hce.shared/issues/new. For more information, see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry.
|
|
16
|
+
* - The GitHub API response header lacked "x-oauth-scopes". This indicates the token we provided is not a workflow token nor a Personal Access Token (classic) and can never have permission to push packages.
|
|
17
|
+
*/
|
|
18
|
+
async function tokenCanWritePackages(tokenEnvVar, url) {
|
|
19
|
+
/* double-check the token exists */
|
|
20
|
+
const info = isTokenDefined(tokenEnvVar);
|
|
21
|
+
strict.ok(info.isDefined);
|
|
22
|
+
if (url === undefined) {
|
|
23
|
+
console.debug(`tokenCanWritePackages was called without a NuGet Source URL. Defaulting to use ${`${nugetGitHubUrlBase}/\${GITHUB_REPOSITORY_OWNER}/index.json`} where GITHUB_REPOSITORY_OWNER is '${getOwner()}'`);
|
|
24
|
+
url = getNugetGitHubUrl();
|
|
25
|
+
}
|
|
26
|
+
strict.notDeepStrictEqual(url, undefined);
|
|
27
|
+
strict.notDeepStrictEqual(url, '');
|
|
28
|
+
if (info.fallback) tokenEnvVar = info.fallback;
|
|
29
|
+
const tokenValue = envUtils.getEnvVarValue(tokenEnvVar);
|
|
6
30
|
if (tokenValue === undefined) throw new TypeError(`The environment variable ${tokenEnvVar} is undefined!`);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
if (tokenValue.startsWith('github_pat_')) throw new Error(`The value of the token in ${tokenEnvVar} begins with 'github_pat_' which means it's a Fine-Grained token. At the time of writing, GitHub Fine-Grained tokens cannot push packages. If you believe this is statement is outdated, report the issue at https://github.com/halospv3/hce.shared/issues/new. For more information, see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry.`);
|
|
32
|
+
const dummyNupkgPath = createDummyNupkg.createDummyNupkg();
|
|
33
|
+
const promiseExec = node_util.promisify(node_child_process.exec);
|
|
34
|
+
try {
|
|
35
|
+
const pushResult = await promiseExec(`dotnet nuget push ${dummyNupkgPath} --source ${url} --api-key ${tokenValue} --skip-duplicate`, {
|
|
36
|
+
encoding: 'utf8'
|
|
37
|
+
});
|
|
38
|
+
const errNewline = pushResult.stderr.includes('\r\n') ? '\r\n' : pushResult.stdout.includes('\r') ? '\r' : '\n';
|
|
39
|
+
|
|
40
|
+
// if any *lines* start with "error: " or "Error: ", log stderr
|
|
41
|
+
const errorCount = pushResult.stderr.split(errNewline ?? '\n').filter(line => line.trim().startsWith('error: ') || line.trim().startsWith('Error: ')).length;
|
|
42
|
+
if (errorCount > 0) console.error(pushResult.stderr);
|
|
43
|
+
|
|
44
|
+
// if any lines start with "warn : ", log stdout
|
|
45
|
+
const warningCount = pushResult.stdout.split(errNewline ?? '\n').filter(line => line.trim().startsWith('warn : ')).length;
|
|
46
|
+
if (warningCount > 0) console.warn(pushResult.stdout);
|
|
47
|
+
const hasAuthError = pushResult.stderr.includes('401 (Unauthorized)');
|
|
48
|
+
|
|
49
|
+
// return true is no lines contain error indicators.
|
|
50
|
+
return errorCount === 0 && hasAuthError === false;
|
|
51
|
+
} catch (err) {
|
|
52
|
+
const stdout = err.stdout ?? '';
|
|
53
|
+
console.error(err.stack + '\n' + stdout.split('Usage: dotnet nuget push')[0]);
|
|
54
|
+
return false;
|
|
18
55
|
}
|
|
19
|
-
return false;
|
|
20
56
|
}
|
|
21
|
-
|
|
57
|
+
|
|
58
|
+
/** returns the value of GITHUB_REPOSITORY_OWNER */
|
|
59
|
+
function getOwner() {
|
|
60
|
+
return envUtils.getEnvVarValue('GITHUB_REPOSITORY_OWNER');
|
|
61
|
+
}
|
|
22
62
|
const nugetGitHubUrlBase = 'https://nuget.pkg.github.com';
|
|
23
|
-
|
|
63
|
+
|
|
64
|
+
/** @deprecated use {@link getNugetGitHubUrl()} instead. */
|
|
65
|
+
const nugetGitHubUrl = getNugetGitHubUrl();
|
|
66
|
+
|
|
67
|
+
// todo!: refactor to "return string else throw"
|
|
68
|
+
function getNugetGitHubUrl() {
|
|
69
|
+
const owner = getOwner();
|
|
70
|
+
if (owner) return `${nugetGitHubUrlBase}/${owner}/index.json`;
|
|
71
|
+
console.warn('GITHUB_REPOSITORY_OWNER is undefined! Default NuGet source for GitHub is unavailable.');
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* If tokenEnvVar is NOT 'GITHUB_TOKEN', then test if the token is defined and return the boolean.
|
|
77
|
+
* Else If tokenEnvVar is 'GITHUB_TOKEN' and defined, then return true.
|
|
78
|
+
* Else If tokenEnvVar is 'GITHUB_TOKEN' and undefined, then set tokenEnvVar to 'GH_TOKEN', test if GH_TOKEN is defined, and return the boolean.
|
|
79
|
+
* @param tokenEnvVar the name of the environment variable with the token's value. Defaults to 'GITHUB_TOKEN'. If environment variable 'GITHUB_TOKEN' is undefined, falls back to 'GH_TOKEN'.
|
|
80
|
+
* @returns `{isDefined: true}` if the token is defined. Else, if tokenEnvVar is 'GITHUB_TOKEN' (default) and token is defined, returns `true`. Else, if 'GH_TOKEN' is defined, returns `true`. Else, returns `false`
|
|
81
|
+
*/
|
|
82
|
+
function isTokenDefined(tokenEnvVar = 'GITHUB_TOKEN') {
|
|
83
|
+
let token = envUtils.getEnvVarValue(tokenEnvVar /* custom or GITHUB_TOKEN */);
|
|
84
|
+
if (tokenEnvVar !== 'GITHUB_TOKEN') return {
|
|
85
|
+
isDefined: token !== undefined && token !== 'undefined'
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/* GITHUB_TOKEN */
|
|
89
|
+
if (token !== undefined && token !== 'undefined') return {
|
|
90
|
+
isDefined: true
|
|
91
|
+
};
|
|
92
|
+
token = envUtils.getEnvVarValue('GH_TOKEN');
|
|
93
|
+
return {
|
|
94
|
+
isDefined: token !== undefined && token !== 'undefined',
|
|
95
|
+
fallback: 'GH_TOKEN'
|
|
96
|
+
};
|
|
97
|
+
}
|
|
24
98
|
|
|
25
99
|
/**
|
|
26
100
|
* Get a {@link NuGetRegistryInfo} for pushing to your GitHub Packages NuGet registry.
|
|
27
101
|
* todo: add support for private, custom GitHub instances. Token is only validated against github.com.
|
|
28
102
|
* @export
|
|
29
|
-
* @param {string} [tokenEnvVar="GITHUB_TOKEN"] The name of environment variable storing the GitHub Packages NuGet registry API key. Defaults to `"GITHUB_TOKEN"
|
|
30
|
-
* @param {string} [url=tokenEnvVar] The url of the GitHub Packages NuGet registry. Defaults to {@link
|
|
103
|
+
* @param {string | 'GITHUB_TOKEN' | 'GH_TOKEN'} [tokenEnvVar="GITHUB_TOKEN"] The name of environment variable storing the GitHub Packages NuGet registry API key. Defaults to `"GITHUB_TOKEN"`. If GITHUB_TOKEN is undefined, fallback to GH_TOKEN;
|
|
104
|
+
* @param {string} [url=tokenEnvVar] The url of the GitHub Packages NuGet registry. Defaults to return value of {@link getNugetGitHubUrl()}.
|
|
31
105
|
* @returns {(NuGetRegistryInfo | undefined)} a {@link NuGetRegistryInfo} object if {@link tokenEnvVar} and {@link url} are defined. Else, `undefined`.
|
|
32
106
|
* note: `url` defaults to job's repository owner's GitHub registry in GitHub Actions workflow. If GITHUB_REPOSITORY_OWNER is not defined, then an error will be logged and `undefined` will be returned.
|
|
33
107
|
*/
|
|
34
|
-
async function getGithubNugetRegistryPair(tokenEnvVar = 'GITHUB_TOKEN', url =
|
|
35
|
-
// yes, this is stupid. No, I won't change it.
|
|
36
|
-
const isTokenDefined = process.env[tokenEnvVar] !== undefined;
|
|
37
|
-
const isUrlDefined = url !== undefined;
|
|
38
|
-
const canTokenWritePackages = isTokenDefined ? await tokenCanWritePackages(tokenEnvVar) : false;
|
|
108
|
+
async function getGithubNugetRegistryPair(tokenEnvVar = 'GITHUB_TOKEN', url = getNugetGitHubUrl()) {
|
|
39
109
|
const errors = [];
|
|
40
|
-
|
|
41
|
-
|
|
110
|
+
const _isTokenDefinedInfo = isTokenDefined(tokenEnvVar);
|
|
111
|
+
let canTokenWritePackages = undefined;
|
|
112
|
+
if ((url ??= getNugetGitHubUrl()) === undefined) {
|
|
42
113
|
errors.push(new Error('The url for the GitHub Packages NuGet registry was undefined.\n' + 'If running in a GitHub Actions workflow, something is seriously wrong.\n' + 'If running in a different CI/CD pipeline and you wish to cross-push to GHPR, ensure GITHUB_REPOSITORY_OWNER is set correctly.\n'));
|
|
43
114
|
}
|
|
44
|
-
if (
|
|
115
|
+
if (_isTokenDefinedInfo.isDefined) {
|
|
116
|
+
if (_isTokenDefinedInfo.fallback) tokenEnvVar = _isTokenDefinedInfo.fallback;
|
|
117
|
+
try {
|
|
118
|
+
canTokenWritePackages = await tokenCanWritePackages(tokenEnvVar, url);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if (err instanceof Error) errors.push(err);else errors.push(new Error(String(err)));
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
const errMsg = `The environment variable ${tokenEnvVar} was specified as the source of the token to push a NuGet package to GitHub, but the environment variable does not exist.` + `${_isTokenDefinedInfo.fallback === undefined ? '' : ` The fallback environment variable ${_isTokenDefinedInfo.fallback} is also undefined.`}`;
|
|
124
|
+
errors.push(new Error(errMsg));
|
|
125
|
+
}
|
|
126
|
+
if (canTokenWritePackages === false) {
|
|
45
127
|
// yes, this is a critical error that should be fixed before Semantic Release can succeed.
|
|
46
128
|
// yes, this is incredibly irritating to deal with in local runs.
|
|
47
129
|
errors.push(new Error('The provided GitHub token has insufficient permissions or is a fine-grained permissions token. Only class Personal Access Tokens (classic) or workflow tokens with `repo` or `write:packages` permission can push a package.'));
|
|
48
130
|
}
|
|
49
131
|
|
|
50
132
|
// conditions checked so `url` is certainly defined
|
|
51
|
-
if (
|
|
133
|
+
if (_isTokenDefinedInfo.isDefined && url !== undefined && canTokenWritePackages) return {
|
|
52
134
|
tokenEnvVar,
|
|
53
135
|
url
|
|
54
136
|
};
|
|
55
|
-
|
|
56
|
-
|
|
137
|
+
const aggErr = new Error(`One more more errors occurred when getting GHPR url-token pair. Errors:\n${errors.map(v => v.stack).join('\n')}`);
|
|
138
|
+
if (envUtils.getEnvVarValue('SKIP_TOKEN') === 'true' && aggErr.message.length > 0) {
|
|
139
|
+
console.error('WARN: errors were thrown, but SKIP_TOKEN is defined.\n' + aggErr.stack);
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
throw aggErr;
|
|
57
143
|
}
|
|
58
144
|
exports.getGithubNugetRegistryPair = getGithubNugetRegistryPair;
|
|
145
|
+
exports.getNugetGitHubUrl = getNugetGitHubUrl;
|
|
146
|
+
exports.isTokenDefined = isTokenDefined;
|
|
59
147
|
exports.nugetGitHubUrl = nugetGitHubUrl;
|
|
60
148
|
exports.nugetGitHubUrlBase = nugetGitHubUrlBase;
|
|
149
|
+
exports.tokenCanWritePackages = tokenCanWritePackages;
|
|
61
150
|
//# sourceMappingURL=dotnetGHPR.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotnetGHPR.cjs","sources":["../../src/dotnet/dotnetGHPR.ts"],"sourcesContent":null,"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dotnetGHPR.cjs","sources":["../../src/dotnet/dotnetGHPR.ts"],"sourcesContent":null,"names":["ok","notDeepStrictEqual","getEnvVarValue","createDummyNupkg","promisify","exec"],"mappings":";;;;;;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,qBAAqB,CAAC,WAAW,EAAE,GAAG,EAAE;AAC9D;AACA,EAAE,MAAM,IAAI,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;AAC3C,EAAEA,SAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACrB,EAAE,IAAI,GAAG,KAAK,SAAS,EAAE;AACzB,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,+EAA+E,EAAE,CAAC,EAAE,kBAAkB,CAAC,uCAAuC,CAAC,CAAC,mCAAmC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACvN,IAAI,GAAG,GAAG,iBAAiB,EAAE,CAAC;AAC9B,GAAG;AACH,EAAEC,yBAAkB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;AACrC,EAAEA,yBAAkB,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;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KAAK,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;AAC5E,IAAI,OAAO,CAAC,KAAK,CAAC,wDAAwD,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3F,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,MAAM,MAAM,CAAC;AACf;;;;;;;;;"}
|
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
import type { NuGetRegistryInfo } from './dotnetHelpers.js';
|
|
2
|
+
/**
|
|
3
|
+
* @param tokenEnvVar The name of the environment variable containing the NUGET token
|
|
4
|
+
* @returns `true` if the token can be used to push nupkg to the given Nuget registry
|
|
5
|
+
* @throws
|
|
6
|
+
* - TypeError: The environment variable ${tokenEnvVar} is undefined!
|
|
7
|
+
* - Error:
|
|
8
|
+
* - The value of the token in ${tokenEnvVar} begins with 'github_pat_' which means it's a Fine-Grained token. At the time of writing, GitHub Fine-Grained tokens cannot push packages. If you believe this is statement is outdated, report the issue at https://github.com/halospv3/hce.shared/issues/new. For more information, see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry.
|
|
9
|
+
* - The GitHub API response header lacked "x-oauth-scopes". This indicates the token we provided is not a workflow token nor a Personal Access Token (classic) and can never have permission to push packages.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tokenCanWritePackages(tokenEnvVar: string, url?: string): Promise<boolean>;
|
|
2
12
|
export declare const nugetGitHubUrlBase = "https://nuget.pkg.github.com";
|
|
13
|
+
/** @deprecated use {@link getNugetGitHubUrl()} instead. */
|
|
3
14
|
export declare const nugetGitHubUrl: string | undefined;
|
|
15
|
+
export declare function getNugetGitHubUrl(): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* If tokenEnvVar is NOT 'GITHUB_TOKEN', then test if the token is defined and return the boolean.
|
|
18
|
+
* Else If tokenEnvVar is 'GITHUB_TOKEN' and defined, then return true.
|
|
19
|
+
* Else If tokenEnvVar is 'GITHUB_TOKEN' and undefined, then set tokenEnvVar to 'GH_TOKEN', test if GH_TOKEN is defined, and return the boolean.
|
|
20
|
+
* @param tokenEnvVar the name of the environment variable with the token's value. Defaults to 'GITHUB_TOKEN'. If environment variable 'GITHUB_TOKEN' is undefined, falls back to 'GH_TOKEN'.
|
|
21
|
+
* @returns `{isDefined: true}` if the token is defined. Else, if tokenEnvVar is 'GITHUB_TOKEN' (default) and token is defined, returns `true`. Else, if 'GH_TOKEN' is defined, returns `true`. Else, returns `false`
|
|
22
|
+
*/
|
|
23
|
+
export declare function isTokenDefined(tokenEnvVar?: string): {
|
|
24
|
+
isDefined: boolean;
|
|
25
|
+
fallback?: string;
|
|
26
|
+
};
|
|
4
27
|
/**
|
|
5
28
|
* Get a {@link NuGetRegistryInfo} for pushing to your GitHub Packages NuGet registry.
|
|
6
29
|
* todo: add support for private, custom GitHub instances. Token is only validated against github.com.
|
|
7
30
|
* @export
|
|
8
|
-
* @param {string} [tokenEnvVar="GITHUB_TOKEN"] The name of environment variable storing the GitHub Packages NuGet registry API key. Defaults to `"GITHUB_TOKEN"
|
|
9
|
-
* @param {string} [url=tokenEnvVar] The url of the GitHub Packages NuGet registry. Defaults to {@link
|
|
31
|
+
* @param {string | 'GITHUB_TOKEN' | 'GH_TOKEN'} [tokenEnvVar="GITHUB_TOKEN"] The name of environment variable storing the GitHub Packages NuGet registry API key. Defaults to `"GITHUB_TOKEN"`. If GITHUB_TOKEN is undefined, fallback to GH_TOKEN;
|
|
32
|
+
* @param {string} [url=tokenEnvVar] The url of the GitHub Packages NuGet registry. Defaults to return value of {@link getNugetGitHubUrl()}.
|
|
10
33
|
* @returns {(NuGetRegistryInfo | undefined)} a {@link NuGetRegistryInfo} object if {@link tokenEnvVar} and {@link url} are defined. Else, `undefined`.
|
|
11
34
|
* note: `url` defaults to job's repository owner's GitHub registry in GitHub Actions workflow. If GITHUB_REPOSITORY_OWNER is not defined, then an error will be logged and `undefined` will be returned.
|
|
12
35
|
*/
|
|
13
|
-
export declare function getGithubNugetRegistryPair(tokenEnvVar?: string, url?: string | undefined): Promise<NuGetRegistryInfo | undefined>;
|
|
36
|
+
export declare function getGithubNugetRegistryPair(tokenEnvVar?: string | 'GITHUB_TOKEN' | 'GH_TOKEN', url?: string | undefined): Promise<NuGetRegistryInfo | undefined>;
|
|
14
37
|
//# sourceMappingURL=dotnetGHPR.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotnetGHPR.d.ts","sourceRoot":"","sources":["../../src/dotnet/dotnetGHPR.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dotnetGHPR.d.ts","sourceRoot":"","sources":["../../src/dotnet/dotnetGHPR.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,oBAkD5E;AAOD,eAAO,MAAM,kBAAkB,iCAAiC,CAAC;AAEjE,2DAA2D;AAC3D,eAAO,MAAM,cAAc,EAAE,MAAM,GAAG,SAA+B,CAAC;AAGtE,wBAAgB,iBAAiB,uBAMhC;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,WAAW,SAAiB,GAAG;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAetG;AAED;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAC/C,WAAW,GAAE,MAAM,GAAG,cAAc,GAAG,UAA2B,EAClE,GAAG,GAAE,MAAM,GAAG,SAA+B,GAC3C,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAuDxC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
CI_API_V4_URL =
|
|
6
|
-
CI_PROJECT_ID =
|
|
3
|
+
const envUtils = require('../envUtils.cjs');
|
|
4
|
+
const _envUtils$getEnv = envUtils.getEnv(),
|
|
5
|
+
CI_API_V4_URL = _envUtils$getEnv.CI_API_V4_URL,
|
|
6
|
+
CI_PROJECT_ID = _envUtils$getEnv.CI_PROJECT_ID;
|
|
7
7
|
const nameof = {
|
|
8
8
|
CI_API_V4_URL: 'CI_API_V4_URL',
|
|
9
9
|
CI_PROJECT_ID: 'CI_PROJECT_ID'
|
|
@@ -21,8 +21,8 @@ const nugetGitLabUrl = CI_API_V4_URL && CI_PROJECT_ID ? `${CI_API_V4_URL}/projec
|
|
|
21
21
|
*/
|
|
22
22
|
function getGitlabNugetRegistryPair(tokenEnvVar = GitLabTokenEnvVar, url = nugetGitLabUrl) {
|
|
23
23
|
// yes, this is stupid. No, I won't change it.
|
|
24
|
-
if (!
|
|
25
|
-
|
|
24
|
+
if (!envUtils.getEnvVarValue(tokenEnvVar)) {
|
|
25
|
+
console.error(new Error(`The environment variable ${tokenEnvVar} was specified as the source of the token to push a NuGet package to GitLab, but the environment variable does not exist.`));
|
|
26
26
|
return undefined;
|
|
27
27
|
}
|
|
28
28
|
if (url) {
|
|
@@ -31,7 +31,7 @@ function getGitlabNugetRegistryPair(tokenEnvVar = GitLabTokenEnvVar, url = nuget
|
|
|
31
31
|
url
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
console.error(new Error(`The environment variables ${nameof.CI_API_V4_URL} or ${nameof.CI_PROJECT_ID} do not exist and a custom GitLab Packages NuGet registry URL was not provided.`));
|
|
35
35
|
return undefined;
|
|
36
36
|
}
|
|
37
37
|
exports.GitLabTokenEnvVar = GitLabTokenEnvVar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotnetGLPR.cjs","sources":["../../src/dotnet/dotnetGLPR.ts"],"sourcesContent":null,"names":["
|
|
1
|
+
{"version":3,"file":"dotnetGLPR.cjs","sources":["../../src/dotnet/dotnetGLPR.ts"],"sourcesContent":null,"names":["getEnv","getEnvVarValue"],"mappings":";;;;AACA,MAAM;AACN,EAAE,aAAa;AACf,EAAE,aAAa;AACf,CAAC,GAAGA,eAAM,EAAE,CAAC;AACb,MAAM,MAAM,GAAG;AACf,EAAE,aAAa,EAAE,eAAe;AAChC,EAAE,aAAa,EAAE,eAAe;AAChC,CAAC,CAAC;AACU,MAAC,iBAAiB,GAAG,eAAe;AACpC,MAAC,kBAAkB,GAAG,cAAc;AACpC,MAAC,cAAc,GAAG,aAAa,IAAI,aAAa,GAAG,CAAC,EAAE,aAAa,CAAC,UAAU,EAAE,aAAa,CAAC,0BAA0B,CAAC,GAAG,UAAU;AAClJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,WAAW,GAAG,iBAAiB,EAAE,GAAG,GAAG,cAAc,EAAE;AAClG;AACA,EAAE,IAAI,CAACC,uBAAc,CAAC,WAAW,CAAC,EAAE;AACpC,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,yBAAyB,EAAE,WAAW,CAAC,yHAAyH,CAAC,CAAC,CAAC,CAAC;AACjM,IAAI,OAAO,SAAS,CAAC;AACrB,GAAG;AACH,EAAE,IAAI,GAAG,EAAE;AACX,IAAI,OAAO;AACX,MAAM,WAAW;AACjB,MAAM,GAAG;AACT,KAAK,CAAC;AACN,GAAG;AACH,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,0BAA0B,EAAE,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC,+EAA+E,CAAC,CAAC,CAAC,CAAC;AAC1L,EAAE,OAAO,SAAS,CAAC;AACnB;;;;;;;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const strict = require('node:assert/strict');
|
|
4
|
+
const envUtils = require('../envUtils.cjs');
|
|
5
|
+
const MSBuildProject = require('./MSBuildProject.cjs');
|
|
4
6
|
const dotnetGHPR = require('./dotnetGHPR.cjs');
|
|
5
7
|
const dotnetGLPR = require('./dotnetGLPR.cjs');
|
|
6
|
-
const MSBuildProject = require('./MSBuildProject.cjs');
|
|
7
8
|
function formatDotnetPublish(projectsToPublish, publishProperties) {
|
|
8
9
|
/* Fun Fact: You can define a property and get the evaluated value in the same command!
|
|
9
10
|
```pwsh
|
|
@@ -129,8 +130,8 @@ async function configureDotnetNugetPush(nupkgDir = './publish', registries = [nu
|
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
return registries.map(registry => {
|
|
132
|
-
const tokenValue =
|
|
133
|
-
strict.ok(
|
|
133
|
+
const tokenValue = envUtils.getEnvVarValue(registry.tokenEnvVar);
|
|
134
|
+
strict.ok(envUtils.getEnvVarValue('SKIP_TOKEN') === 'true' || tokenValue, `The environment variable ${registry.tokenEnvVar} is undefined!`);
|
|
134
135
|
`dotnet nuget push ${nupkgDir} --source ${registry.url} --token ${tokenValue ?? '**placeholder**'}`;
|
|
135
136
|
}).join(' && ');
|
|
136
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotnetHelpers.cjs","sources":["../../src/dotnet/dotnetHelpers.ts"],"sourcesContent":null,"names":["MSBuildProject","MSBuildProjectPreDefinedProperties","nugetGitHubUrlBase","getGithubNugetRegistryPair","getGitlabNugetRegistryPair","ok"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dotnetHelpers.cjs","sources":["../../src/dotnet/dotnetHelpers.ts"],"sourcesContent":null,"names":["MSBuildProject","MSBuildProjectPreDefinedProperties","nugetGitHubUrlBase","getGithubNugetRegistryPair","getGitlabNugetRegistryPair","getEnvVarValue","ok"],"mappings":";;;;;;;;AAKA,SAAS,mBAAmB,CAAC,iBAAiB,EAAE,iBAAiB,EAAE;AACnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,C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AClB;;;;;;"}
|
package/cjs/dotnet-wrapper.mjs
CHANGED
package/cjs/dotnet.cjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const MSBuildProject = require('./dotnet/MSBuildProject.cjs');
|
|
4
|
+
const MSBuildProjectProperties = require('./dotnet/MSBuildProjectProperties.cjs');
|
|
5
|
+
const createDummyNupkg$1 = require('./dotnet/createDummyNupkg.cjs');
|
|
3
6
|
const dotnetGHPR$1 = require('./dotnet/dotnetGHPR.cjs');
|
|
4
7
|
const dotnetGLPR$1 = require('./dotnet/dotnetGLPR.cjs');
|
|
5
8
|
const dotnetHelpers$1 = require('./dotnet/dotnetHelpers.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
exports.msbuildProject = MSBuildProject;
|
|
10
|
+
exports.msbuildProjectProperties = MSBuildProjectProperties;
|
|
11
|
+
exports.createDummyNupkg = createDummyNupkg$1;
|
|
8
12
|
exports.dotnetGHPR = dotnetGHPR$1;
|
|
9
13
|
exports.dotnetGLPR = dotnetGLPR$1;
|
|
10
14
|
exports.dotnetHelpers = dotnetHelpers$1;
|
|
11
|
-
exports.msbuildProject = MSBuildProject;
|
|
12
|
-
exports.msbuildProjectProperties = MSBuildProjectProperties;
|
|
13
15
|
//# sourceMappingURL=dotnet.cjs.map
|
package/cjs/dotnet.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotnet.cjs","sources":[],"sourcesContent":null,"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dotnet.cjs","sources":[],"sourcesContent":null,"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
package/cjs/dotnet.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export * as msbuildProject from "./dotnet/MSBuildProject.js";
|
|
2
|
+
export * as msbuildProjectProperties from "./dotnet/MSBuildProjectProperties.js";
|
|
3
|
+
export * as createDummyNupkg from './dotnet/createDummyNupkg.js';
|
|
1
4
|
export * as dotnetGHPR from "./dotnet/dotnetGHPR.js";
|
|
2
5
|
export * as dotnetGLPR from "./dotnet/dotnetGLPR.js";
|
|
3
6
|
export * as dotnetHelpers from "./dotnet/dotnetHelpers.js";
|
|
4
|
-
export * as msbuildProject from "./dotnet/MSBuildProject.js";
|
|
5
|
-
export * as msbuildProjectProperties from "./dotnet/MSBuildProjectProperties.js";
|
|
6
7
|
//# sourceMappingURL=dotnet.d.ts.map
|
package/cjs/dotnet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dotnet.d.ts","sourceRoot":"","sources":["../src/dotnet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"dotnet.d.ts","sourceRoot":"","sources":["../src/dotnet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,cAAc,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,wBAAwB,MAAM,sCAAsC,CAAA;AAChF,OAAO,KAAK,gBAAgB,MAAM,8BAA8B,CAAA;AAChE,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,aAAa,MAAM,2BAA2B,CAAA"}
|
package/cjs/envUtils.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const dotenv = require('dotenv');
|
|
4
|
+
const node_process = require('node:process');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Load a .env file from the CWD with the given options (or defaults), returns the new value of process.env
|
|
8
|
+
* @param dotenvOptions
|
|
9
|
+
* @param overrides
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function getEnv(dotenvOptions, overrides) {
|
|
13
|
+
dotenv.config(dotenvOptions);
|
|
14
|
+
if (overrides) Object.assign(node_process.env, overrides);
|
|
15
|
+
return node_process.env;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get the value from the given env var. If undefined, load .env from CWD and try again or return undefined.
|
|
20
|
+
* @param envVar
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
function getEnvVarValue(envVar) {
|
|
24
|
+
let value = node_process.env[envVar];
|
|
25
|
+
if (!value) {
|
|
26
|
+
try {
|
|
27
|
+
dotenv.config();
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error(String(err));
|
|
30
|
+
}
|
|
31
|
+
value = node_process.env[envVar];
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
exports.getEnv = getEnv;
|
|
36
|
+
exports.getEnvVarValue = getEnvVarValue;
|
|
37
|
+
//# sourceMappingURL=envUtils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envUtils.cjs","sources":["../src/envUtils.ts"],"sourcesContent":null,"names":["loadDotenv","env"],"mappings":";;;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,MAAM,CAAC,aAAa,EAAE,SAAS,EAAE;AACjD,EAAEA,aAAU,CAAC,aAAa,CAAC,CAAC;AAC5B,EAAE,IAAI,SAAS,EAAE,MAAM,CAAC,MAAM,CAACC,gBAAG,EAAE,SAAS,CAAC,CAAC;AAC/C,EAAE,OAAOA,gBAAG,CAAC;AACb,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,MAAM,EAAE;AACvC,EAAE,IAAI,KAAK,GAAGA,gBAAG,CAAC,MAAM,CAAC,CAAC;AAC1B,EAAE,IAAI,CAAC,KAAK,EAAE;AACd,IAAI,IAAI;AACR,MAAMD,aAAU,EAAE,CAAC;AACnB,KAAK,CAAC,OAAO,GAAG,EAAE;AAClB,MAAM,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACjC,KAAK;AACL,IAAI,KAAK,GAAGC,gBAAG,CAAC,MAAM,CAAC,CAAC;AACxB,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf;;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { type DotenvConfigOptions } from "dotenv";
|
|
3
|
+
/**
|
|
4
|
+
* Load a .env file from the CWD with the given options (or defaults), returns the new value of process.env
|
|
5
|
+
* @param dotenvOptions
|
|
6
|
+
* @param overrides
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function getEnv(dotenvOptions?: DotenvConfigOptions, overrides?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
10
|
+
/**
|
|
11
|
+
* Get the value from the given env var. If undefined, load .env from CWD and try again or return undefined.
|
|
12
|
+
* @param envVar
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare function getEnvVarValue(envVar: string): string | undefined;
|
|
16
|
+
//# sourceMappingURL=envUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envUtils.d.ts","sourceRoot":"","sources":["../src/envUtils.ts"],"names":[],"mappings":";AAAA,OAAO,EAAwB,KAAK,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAGxE;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,aAAa,CAAC,EAAE,mBAAmB,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAO5G;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAYjE"}
|
package/cjs/eslintConfig.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const jsonc = require('eslint-plugin-jsonc');
|
|
4
|
-
const tseslint = require('typescript-eslint');
|
|
5
3
|
const eslint = require('@eslint/js');
|
|
4
|
+
const jsonc = require('eslint-plugin-jsonc');
|
|
6
5
|
const node_module = require('node:module');
|
|
6
|
+
const tseslint = require('typescript-eslint');
|
|
7
7
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
8
8
|
const _interopDefault = e => e && e.__esModule ? e : {
|
|
9
9
|
default: e
|
|
10
10
|
};
|
|
11
|
+
const eslint__default = /*#__PURE__*/_interopDefault(eslint);
|
|
11
12
|
const jsonc__default = /*#__PURE__*/_interopDefault(jsonc);
|
|
12
13
|
const tseslint__default = /*#__PURE__*/_interopDefault(tseslint);
|
|
13
|
-
const eslint__default = /*#__PURE__*/_interopDefault(eslint);
|
|
14
14
|
|
|
15
15
|
// CJS compatibility; it started transpiling to a top-level await after upgrading from packemon 4.0.1 to 4.1.0
|
|
16
16
|
const require$1 = node_module.createRequire(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.src || new URL('eslintConfig.cjs', document.baseURI).href);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslintConfig.d.ts","sourceRoot":"","sources":["../src/eslintConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eslintConfig.d.ts","sourceRoot":"","sources":["../src/eslintConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;;AA4BzD,wBA2DE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semanticReleaseConfig.d.ts","sourceRoot":"","sources":["../src/semanticReleaseConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"semanticReleaseConfig.d.ts","sourceRoot":"","sources":["../src/semanticReleaseConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG5D,eAAO,MAAM,cAAc,EAAE,SAAS,UAAU,EAK/C,CAAC;AAEF,eAAO,MAAM,UAAU,SAmCX,CAAC"}
|
|
@@ -8,10 +8,12 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
8
8
|
Object.defineProperty(exports, '__esModule', {
|
|
9
9
|
value: true
|
|
10
10
|
});
|
|
11
|
+
const node_util = require('node:util');
|
|
12
|
+
const debug = require('./debug.cjs');
|
|
11
13
|
const dotnetHelpers = require('./dotnet/dotnetHelpers.cjs');
|
|
14
|
+
const envUtils = require('./envUtils.cjs');
|
|
12
15
|
const semanticReleaseConfig = require('./semanticReleaseConfig.cjs');
|
|
13
16
|
const setupGitPluginSpec = require('./setupGitPluginSpec.cjs');
|
|
14
|
-
const debug = require('./debug.cjs');
|
|
15
17
|
|
|
16
18
|
/** Semantic-Release Config Factory (dotnet)
|
|
17
19
|
* A functional Semantic-Release configuration for dotnet projects
|
|
@@ -81,25 +83,25 @@ function appendPlugins(config, projectsToPublish, projectsToPackAndPush) {
|
|
|
81
83
|
*/
|
|
82
84
|
function getConfig(projectsToPublish = [], projectsToPackAndPush = []) {
|
|
83
85
|
if (debug.enabled) {
|
|
84
|
-
debug('hce.shared-config:\n
|
|
86
|
+
console.debug('hce.shared-config:\n' + node_util.inspect(semanticReleaseConfig.baseConfig, false, Infinity, true));
|
|
85
87
|
}
|
|
86
88
|
const errors = [];
|
|
87
89
|
if (projectsToPublish.length === 0) {
|
|
88
|
-
const _ =
|
|
90
|
+
const _ = envUtils.getEnvVarValue("PROJECTS_TO_PUBLISH");
|
|
89
91
|
if (_ === undefined) errors.push(new Error("projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path."));else projectsToPublish = _.split(';');
|
|
90
92
|
}
|
|
91
93
|
if (projectsToPackAndPush !== false && projectsToPackAndPush.length === 0) {
|
|
92
|
-
const _ =
|
|
94
|
+
const _ = envUtils.getEnvVarValue("PROJECTS_TO_PACK_AND_PUSH");
|
|
93
95
|
if (_ === undefined) errors.push(new Error("projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path."));else projectsToPackAndPush = _.split(';');
|
|
94
96
|
}
|
|
95
97
|
if (errors.length > 0) {
|
|
96
|
-
throw new Error(["getConfig cannot continue. One or more errors occurred.", ...errors.map(v => v.
|
|
98
|
+
throw new Error(["getConfig cannot continue. One or more errors occurred.", ...errors.map(v => v.stack)].join('\n'));
|
|
97
99
|
}
|
|
98
100
|
let config = _objectSpread({}, semanticReleaseConfig.baseConfig);
|
|
99
101
|
config = insertAndEditPlugins(config);
|
|
100
102
|
if (projectsToPublish) config = appendPlugins(config, projectsToPublish, projectsToPackAndPush);
|
|
101
103
|
if (debug.enabled) {
|
|
102
|
-
debug(
|
|
104
|
+
console.debug(`modified plugins array:\n${node_util.inspect(config.plugins, false, Infinity)}`);
|
|
103
105
|
}
|
|
104
106
|
return config;
|
|
105
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semanticReleaseConfigDotnet.cjs","sources":["../src/semanticReleaseConfigDotnet.ts"],"sourcesContent":null,"names":["defaultPlugins","setupGitPluginSpec","configurePrepareCmd","configureDotnetNugetPush","baseConfig"],"mappings":"
|
|
1
|
+
{"version":3,"file":"semanticReleaseConfigDotnet.cjs","sources":["../src/semanticReleaseConfigDotnet.ts"],"sourcesContent":null,"names":["defaultPlugins","setupGitPluginSpec","configurePrepareCmd","configureDotnetNugetPush","inspect","baseConfig","getEnvVarValue"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,oBAAoB,CAAC,MAAM,EAAE;AAC7C;AACA,EAAE,MAAM,CAAC,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,IAAIA,oCAAc,EAAE,CAAC;AAC3D,EAAE,MAAM,CAAC,OAAO,GAAGC,qCAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACtD,E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K,IAAI,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE;AAC7E,IAAI,MAAM,CAAC,GAAGA,uBAAc,CAAC,2BAA2B,CAAC,CAAC;AAC1D,IAAI,IAAI,CAAC,KAAK,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,sHAAsH,CAAC,CAAC,CAAC,KAAK,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAClN,GAAG;AACH,EAAE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;AACzB,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,yDAAyD,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACzH,GAAG;AACH,EAAE,IAAI,MAAM,GAAG;AACf,IAAI,GAAGD,gCAAU;AACjB,GAAG,CAAC;AACJ,EAAE,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;AACxC,EAAE,IAAI,iBAAiB,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;AAClG,EAAE,IAAI,KAAK,CAAC,OAAO,EAAE;AACrB,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,yBAAyB,EAAED,iBAAO,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1F,GAAG;AACH,EAAE,OAAO,MAAM,CAAC;AAChB;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semanticReleaseConfigDotnet.d.ts","sourceRoot":"","sources":["../src/semanticReleaseConfigDotnet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"semanticReleaseConfigDotnet.d.ts","sourceRoot":"","sources":["../src/semanticReleaseConfigDotnet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAc,MAAM,kBAAkB,CAAC;AAO5D;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAO7D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC5B,MAAM,EAAE,OAAO,EACf,iBAAiB,EAAE,MAAM,EAAE,EAC3B,qBAAqB,EAAE,MAAM,EAAE,GAAG,KAAK,GACrC,OAAO,CAgBT;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,iBAAiB,GAAE,MAAM,EAAO,EAAE,qBAAqB,GAAE,MAAM,EAAE,GAAG,KAAU,GAAG,OAAO,CA0CjH;AAED,eAAe,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setupGitPluginSpec.d.ts","sourceRoot":"","sources":["../src/setupGitPluginSpec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setupGitPluginSpec.d.ts","sourceRoot":"","sources":["../src/setupGitPluginSpec.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,WAAW,0BAA0B,CAAC;AACnD,sEAAsE;AACtE,eAAO,MAAM,cAAc;;;CAIL,CAAC;AASvB;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CA+CtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@halospv3/hce.shared-config",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"halo",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"prepare": "husky",
|
|
44
44
|
"presemantic-release": "npm run pack && npm run check",
|
|
45
45
|
"semantic-release": "npx semantic-release",
|
|
46
|
-
"
|
|
46
|
+
"pretest": "npm run build",
|
|
47
|
+
"test": "tsx --test ./tests/**/*.test.ts",
|
|
47
48
|
"type": "tsc --build",
|
|
48
49
|
"validate": "packemon validate",
|
|
49
50
|
"watch": "packemon watch"
|
|
@@ -55,12 +56,12 @@
|
|
|
55
56
|
"@eslint/js": "^9.3.0",
|
|
56
57
|
"@octokit/request": "^9.1.0",
|
|
57
58
|
"@semantic-release/changelog": "^6.0.3",
|
|
58
|
-
"@semantic-release/commit-analyzer": "^
|
|
59
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
59
60
|
"@semantic-release/exec": "^6.0.3",
|
|
60
61
|
"@semantic-release/git": "^10.0.1",
|
|
61
62
|
"@semantic-release/github": "^10.0.4",
|
|
62
63
|
"@semantic-release/npm": "^12.0.0",
|
|
63
|
-
"@semantic-release/release-notes-generator": "^
|
|
64
|
+
"@semantic-release/release-notes-generator": "^14.0.0",
|
|
64
65
|
"@stylistic/eslint-plugin": "^2.1.0",
|
|
65
66
|
"@types/eslint__js": "^8.42.3",
|
|
66
67
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -68,14 +69,14 @@
|
|
|
68
69
|
"@types/semantic-release": "^20.0.6",
|
|
69
70
|
"@typescript-eslint/eslint-plugin": "^7.10.0",
|
|
70
71
|
"@typescript-eslint/parser": "^7.10.0",
|
|
71
|
-
"conventional-changelog-conventionalcommits": "^
|
|
72
|
+
"conventional-changelog-conventionalcommits": "^8.0.0",
|
|
72
73
|
"debug": "^4.3.4",
|
|
73
74
|
"eslint-plugin-jsonc": "^2.15.1",
|
|
74
75
|
"globals": "^15.3.0",
|
|
75
76
|
"husky": "^9.0.11",
|
|
76
77
|
"js-yaml": "^4.1.0",
|
|
77
78
|
"node-fetch": "^3.3.2",
|
|
78
|
-
"semantic-release": "^
|
|
79
|
+
"semantic-release": "^24.0.0",
|
|
79
80
|
"semantic-release-export-data": "^1.0.1",
|
|
80
81
|
"typescript-eslint": "^7.10.0"
|
|
81
82
|
},
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
"@types/tmp": "^0.2.6",
|
|
92
93
|
"ajv": "^8.13.0",
|
|
93
94
|
"ajv-draft-04": "^1.0.0",
|
|
95
|
+
"dotenv": "^16.4.5",
|
|
94
96
|
"eslint": "^8.57.0",
|
|
95
97
|
"node-fetch": "^3.3.2",
|
|
96
98
|
"packemon": "^4.0.1",
|
|
@@ -135,6 +137,7 @@
|
|
|
135
137
|
"commitlintConfig": "src/commitlintConfig.ts",
|
|
136
138
|
"dotnet": "src/dotnet.ts",
|
|
137
139
|
"eslintConfig": "src/eslintConfig.ts",
|
|
140
|
+
"envUtils": "src/envUtils.ts",
|
|
138
141
|
"findStaticConfig": "src/findStaticConfig.ts",
|
|
139
142
|
"index": "src/index.ts",
|
|
140
143
|
"semanticReleaseConfig": "src/semanticReleaseConfig.ts",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { execSync, type ExecSyncOptionsWithStringEncoding } from 'node:child_process';
|
|
2
|
+
import { existsSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { dirSync } from 'tmp';
|
|
5
|
+
|
|
6
|
+
export function createDummyNupkg(): string {
|
|
7
|
+
const dirResult = dirSync({ unsafeCleanup: true });
|
|
8
|
+
const dummyPkgFullPath: string = join(dirResult.name, 'DUMMY.1.0.0.nupkg');
|
|
9
|
+
|
|
10
|
+
// delete old and possibly-poisoned nupkg
|
|
11
|
+
if (existsSync(dummyPkgFullPath))
|
|
12
|
+
unlinkSync(dummyPkgFullPath);
|
|
13
|
+
|
|
14
|
+
const options: ExecSyncOptionsWithStringEncoding = {
|
|
15
|
+
cwd: dirResult.name,
|
|
16
|
+
encoding: 'utf8'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
execSync('dotnet new console --name DUMMY', options);
|
|
20
|
+
const packOut = execSync(`dotnet pack DUMMY --configuration Release --output ${dirname(dummyPkgFullPath)}`, options);
|
|
21
|
+
|
|
22
|
+
const createdLine = packOut.replace('\r', '')
|
|
23
|
+
.split('\n')
|
|
24
|
+
.find(line => line.includes('Successfully created package'))?.trim();
|
|
25
|
+
|
|
26
|
+
if (!existsSync(dummyPkgFullPath))
|
|
27
|
+
throw new Error(`The dummy nupkg was created, but could not be found at ${dummyPkgFullPath}. See '${createdLine}'.`);
|
|
28
|
+
|
|
29
|
+
return dummyPkgFullPath;
|
|
30
|
+
}
|
package/src/dotnet/dotnetGHPR.ts
CHANGED
|
@@ -1,55 +1,132 @@
|
|
|
1
|
+
import { notDeepStrictEqual, ok } from 'node:assert/strict';
|
|
2
|
+
import { exec, type ExecException } from 'node:child_process';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import { getEnvVarValue } from '../envUtils.js';
|
|
5
|
+
import { createDummyNupkg } from './createDummyNupkg.js';
|
|
1
6
|
import type { NuGetRegistryInfo } from './dotnetHelpers.js';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @param tokenEnvVar The name of the environment variable containing the NUGET token
|
|
10
|
+
* @returns `true` if the token can be used to push nupkg to the given Nuget registry
|
|
11
|
+
* @throws
|
|
12
|
+
* - TypeError: The environment variable ${tokenEnvVar} is undefined!
|
|
13
|
+
* - Error:
|
|
14
|
+
* - The value of the token in ${tokenEnvVar} begins with 'github_pat_' which means it's a Fine-Grained token. At the time of writing, GitHub Fine-Grained tokens cannot push packages. If you believe this is statement is outdated, report the issue at https://github.com/halospv3/hce.shared/issues/new. For more information, see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry.
|
|
15
|
+
* - The GitHub API response header lacked "x-oauth-scopes". This indicates the token we provided is not a workflow token nor a Personal Access Token (classic) and can never have permission to push packages.
|
|
16
|
+
*/
|
|
17
|
+
export async function tokenCanWritePackages(tokenEnvVar: string, url?: string) {
|
|
18
|
+
/* double-check the token exists */
|
|
19
|
+
const info = isTokenDefined(tokenEnvVar);
|
|
20
|
+
ok(info.isDefined)
|
|
21
|
+
|
|
22
|
+
if (url === undefined) {
|
|
23
|
+
console.debug(`tokenCanWritePackages was called without a NuGet Source URL. Defaulting to use ${`${nugetGitHubUrlBase}/\${GITHUB_REPOSITORY_OWNER}/index.json`} where GITHUB_REPOSITORY_OWNER is '${getOwner()}'`)
|
|
24
|
+
url = getNugetGitHubUrl();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
notDeepStrictEqual(url, undefined);
|
|
28
|
+
notDeepStrictEqual(url, '');
|
|
29
|
+
|
|
30
|
+
if (info.fallback)
|
|
31
|
+
tokenEnvVar = info.fallback;
|
|
32
|
+
|
|
33
|
+
const tokenValue = getEnvVarValue(tokenEnvVar);
|
|
6
34
|
if (tokenValue === undefined)
|
|
7
35
|
throw new TypeError(`The environment variable ${tokenEnvVar} is undefined!`)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
36
|
+
|
|
37
|
+
if (tokenValue.startsWith('github_pat_'))
|
|
38
|
+
throw new Error(`The value of the token in ${tokenEnvVar} begins with 'github_pat_' which means it's a Fine-Grained token. At the time of writing, GitHub Fine-Grained tokens cannot push packages. If you believe this is statement is outdated, report the issue at https://github.com/halospv3/hce.shared/issues/new. For more information, see https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry.`)
|
|
39
|
+
|
|
40
|
+
const dummyNupkgPath = createDummyNupkg();
|
|
41
|
+
const promiseExec = promisify(exec);
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const pushResult = await promiseExec(`dotnet nuget push ${dummyNupkgPath} --source ${url} --api-key ${tokenValue} --skip-duplicate`, { encoding: 'utf8' })
|
|
45
|
+
const errNewline = pushResult.stderr.includes('\r\n') ? '\r\n' : pushResult.stdout.includes('\r') ? '\r' : '\n';
|
|
46
|
+
|
|
47
|
+
// if any *lines* start with "error: " or "Error: ", log stderr
|
|
48
|
+
const errorCount = pushResult.stderr.split(errNewline ?? '\n').filter(line => line.trim().startsWith('error: ') || line.trim().startsWith('Error: ')).length;
|
|
49
|
+
if (errorCount > 0)
|
|
50
|
+
console.error(pushResult.stderr);
|
|
51
|
+
|
|
52
|
+
// if any lines start with "warn : ", log stdout
|
|
53
|
+
const warningCount = pushResult.stdout.split(errNewline ?? '\n').filter(line => line.trim().startsWith('warn : ')).length;
|
|
54
|
+
if (warningCount > 0)
|
|
55
|
+
console.warn(pushResult.stdout);
|
|
56
|
+
|
|
57
|
+
const hasAuthError = pushResult.stderr.includes('401 (Unauthorized)');
|
|
58
|
+
|
|
59
|
+
// return true is no lines contain error indicators.
|
|
60
|
+
return errorCount === 0 && hasAuthError === false;
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
const stdout = (err as ExecException).stdout ?? '';
|
|
64
|
+
console.error((err as ExecException).stack + '\n' + stdout.split('Usage: dotnet nuget push')[0]);
|
|
65
|
+
return false;
|
|
15
66
|
}
|
|
16
|
-
return false;
|
|
17
67
|
}
|
|
18
68
|
|
|
19
|
-
|
|
69
|
+
/** returns the value of GITHUB_REPOSITORY_OWNER */
|
|
70
|
+
function getOwner(): string | undefined {
|
|
71
|
+
return getEnvVarValue('GITHUB_REPOSITORY_OWNER')
|
|
72
|
+
}
|
|
20
73
|
|
|
21
74
|
export const nugetGitHubUrlBase = 'https://nuget.pkg.github.com';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
75
|
+
|
|
76
|
+
/** @deprecated use {@link getNugetGitHubUrl()} instead. */
|
|
77
|
+
export const nugetGitHubUrl: string | undefined = getNugetGitHubUrl();
|
|
78
|
+
|
|
79
|
+
// todo!: refactor to "return string else throw"
|
|
80
|
+
export function getNugetGitHubUrl() {
|
|
81
|
+
const owner = getOwner();
|
|
82
|
+
if (owner)
|
|
83
|
+
return `${nugetGitHubUrlBase}/${owner}/index.json`;
|
|
84
|
+
console.warn('GITHUB_REPOSITORY_OWNER is undefined! Default NuGet source for GitHub is unavailable.');
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* If tokenEnvVar is NOT 'GITHUB_TOKEN', then test if the token is defined and return the boolean.
|
|
90
|
+
* Else If tokenEnvVar is 'GITHUB_TOKEN' and defined, then return true.
|
|
91
|
+
* Else If tokenEnvVar is 'GITHUB_TOKEN' and undefined, then set tokenEnvVar to 'GH_TOKEN', test if GH_TOKEN is defined, and return the boolean.
|
|
92
|
+
* @param tokenEnvVar the name of the environment variable with the token's value. Defaults to 'GITHUB_TOKEN'. If environment variable 'GITHUB_TOKEN' is undefined, falls back to 'GH_TOKEN'.
|
|
93
|
+
* @returns `{isDefined: true}` if the token is defined. Else, if tokenEnvVar is 'GITHUB_TOKEN' (default) and token is defined, returns `true`. Else, if 'GH_TOKEN' is defined, returns `true`. Else, returns `false`
|
|
94
|
+
*/
|
|
95
|
+
export function isTokenDefined(tokenEnvVar = 'GITHUB_TOKEN'): { isDefined: boolean, fallback?: string } {
|
|
96
|
+
let token = getEnvVarValue(tokenEnvVar /* custom or GITHUB_TOKEN */);
|
|
97
|
+
|
|
98
|
+
if (tokenEnvVar !== 'GITHUB_TOKEN')
|
|
99
|
+
return { isDefined: (token !== undefined && token !== 'undefined') };
|
|
100
|
+
|
|
101
|
+
/* GITHUB_TOKEN */
|
|
102
|
+
if (token !== undefined && token !== 'undefined')
|
|
103
|
+
return { isDefined: true };
|
|
104
|
+
|
|
105
|
+
token = getEnvVarValue('GH_TOKEN');
|
|
106
|
+
return {
|
|
107
|
+
isDefined: (token !== undefined && token !== 'undefined'),
|
|
108
|
+
fallback: 'GH_TOKEN'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
25
111
|
|
|
26
112
|
/**
|
|
27
113
|
* Get a {@link NuGetRegistryInfo} for pushing to your GitHub Packages NuGet registry.
|
|
28
114
|
* todo: add support for private, custom GitHub instances. Token is only validated against github.com.
|
|
29
115
|
* @export
|
|
30
|
-
* @param {string} [tokenEnvVar="GITHUB_TOKEN"] The name of environment variable storing the GitHub Packages NuGet registry API key. Defaults to `"GITHUB_TOKEN"
|
|
31
|
-
* @param {string} [url=tokenEnvVar] The url of the GitHub Packages NuGet registry. Defaults to {@link
|
|
116
|
+
* @param {string | 'GITHUB_TOKEN' | 'GH_TOKEN'} [tokenEnvVar="GITHUB_TOKEN"] The name of environment variable storing the GitHub Packages NuGet registry API key. Defaults to `"GITHUB_TOKEN"`. If GITHUB_TOKEN is undefined, fallback to GH_TOKEN;
|
|
117
|
+
* @param {string} [url=tokenEnvVar] The url of the GitHub Packages NuGet registry. Defaults to return value of {@link getNugetGitHubUrl()}.
|
|
32
118
|
* @returns {(NuGetRegistryInfo | undefined)} a {@link NuGetRegistryInfo} object if {@link tokenEnvVar} and {@link url} are defined. Else, `undefined`.
|
|
33
119
|
* note: `url` defaults to job's repository owner's GitHub registry in GitHub Actions workflow. If GITHUB_REPOSITORY_OWNER is not defined, then an error will be logged and `undefined` will be returned.
|
|
34
120
|
*/
|
|
35
121
|
export async function getGithubNugetRegistryPair(
|
|
36
|
-
tokenEnvVar = 'GITHUB_TOKEN',
|
|
37
|
-
url: string | undefined =
|
|
122
|
+
tokenEnvVar: string | 'GITHUB_TOKEN' | 'GH_TOKEN' = 'GITHUB_TOKEN',
|
|
123
|
+
url: string | undefined = getNugetGitHubUrl(),
|
|
38
124
|
): Promise<NuGetRegistryInfo | undefined> {
|
|
39
|
-
// yes, this is stupid. No, I won't change it.
|
|
40
|
-
const isTokenDefined = process.env[tokenEnvVar] !== undefined;
|
|
41
|
-
const isUrlDefined = url !== undefined;
|
|
42
|
-
const canTokenWritePackages = isTokenDefined ? await tokenCanWritePackages(tokenEnvVar) : false;
|
|
43
|
-
|
|
44
125
|
const errors: Error[] = [];
|
|
126
|
+
const _isTokenDefinedInfo = isTokenDefined(tokenEnvVar);
|
|
127
|
+
let canTokenWritePackages = undefined;
|
|
45
128
|
|
|
46
|
-
if (
|
|
47
|
-
errors.push(
|
|
48
|
-
new Error(
|
|
49
|
-
`The environment variable ${tokenEnvVar} was specified as the source of the token to push a NuGet package to GitHub, but the environment variable does not exist.`,
|
|
50
|
-
),
|
|
51
|
-
);
|
|
52
|
-
if (!isUrlDefined) {
|
|
129
|
+
if ((url ??= getNugetGitHubUrl()) === undefined) {
|
|
53
130
|
errors.push(
|
|
54
131
|
new Error(
|
|
55
132
|
'The url for the GitHub Packages NuGet registry was undefined.\n' +
|
|
@@ -58,7 +135,27 @@ export async function getGithubNugetRegistryPair(
|
|
|
58
135
|
),
|
|
59
136
|
);
|
|
60
137
|
}
|
|
61
|
-
|
|
138
|
+
|
|
139
|
+
if (_isTokenDefinedInfo.isDefined) {
|
|
140
|
+
if (_isTokenDefinedInfo.fallback)
|
|
141
|
+
tokenEnvVar = _isTokenDefinedInfo.fallback;
|
|
142
|
+
try {
|
|
143
|
+
canTokenWritePackages = await tokenCanWritePackages(tokenEnvVar, url);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
if (err instanceof Error)
|
|
147
|
+
errors.push(err);
|
|
148
|
+
else
|
|
149
|
+
errors.push(new Error(String(err)));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const errMsg = `The environment variable ${tokenEnvVar} was specified as the source of the token to push a NuGet package to GitHub, but the environment variable does not exist.`
|
|
154
|
+
+ `${_isTokenDefinedInfo.fallback === undefined ? '' : ` The fallback environment variable ${_isTokenDefinedInfo.fallback} is also undefined.`}`;
|
|
155
|
+
errors.push(new Error(errMsg));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (canTokenWritePackages === false) {
|
|
62
159
|
// yes, this is a critical error that should be fixed before Semantic Release can succeed.
|
|
63
160
|
// yes, this is incredibly irritating to deal with in local runs.
|
|
64
161
|
errors.push(
|
|
@@ -69,10 +166,14 @@ export async function getGithubNugetRegistryPair(
|
|
|
69
166
|
}
|
|
70
167
|
|
|
71
168
|
// conditions checked so `url` is certainly defined
|
|
72
|
-
if (
|
|
169
|
+
if (_isTokenDefinedInfo.isDefined && url !== undefined && canTokenWritePackages)
|
|
73
170
|
return { tokenEnvVar, url };
|
|
74
171
|
|
|
75
|
-
|
|
172
|
+
const aggErr = new Error(`One more more errors occurred when getting GHPR url-token pair. Errors:\n${errors.map(v => v.stack).join('\n')}`);
|
|
173
|
+
|
|
174
|
+
if (getEnvVarValue('SKIP_TOKEN') === 'true' && aggErr.message.length > 0) {
|
|
175
|
+
console.error('WARN: errors were thrown, but SKIP_TOKEN is defined.\n' + aggErr.stack)
|
|
76
176
|
return undefined;
|
|
77
|
-
|
|
177
|
+
}
|
|
178
|
+
throw aggErr;
|
|
78
179
|
}
|
package/src/dotnet/dotnetGLPR.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getEnv, getEnvVarValue } from '../envUtils.js';
|
|
2
2
|
import type { NuGetRegistryInfo } from './dotnetHelpers.js';
|
|
3
3
|
|
|
4
|
-
const { CI_API_V4_URL, CI_PROJECT_ID } =
|
|
4
|
+
const { CI_API_V4_URL, CI_PROJECT_ID } = getEnv();
|
|
5
5
|
const nameof = {
|
|
6
6
|
CI_API_V4_URL: 'CI_API_V4_URL',
|
|
7
7
|
CI_PROJECT_ID: 'CI_PROJECT_ID',
|
|
@@ -26,8 +26,8 @@ export function getGitlabNugetRegistryPair(
|
|
|
26
26
|
url: string | undefined = nugetGitLabUrl,
|
|
27
27
|
): NuGetRegistryInfo | undefined {
|
|
28
28
|
// yes, this is stupid. No, I won't change it.
|
|
29
|
-
if (!
|
|
30
|
-
error(
|
|
29
|
+
if (!getEnvVarValue(tokenEnvVar)) {
|
|
30
|
+
console.error(
|
|
31
31
|
new Error(
|
|
32
32
|
`The environment variable ${tokenEnvVar} was specified as the source of the token to push a NuGet package to GitLab, but the environment variable does not exist.`,
|
|
33
33
|
),
|
|
@@ -37,7 +37,7 @@ export function getGitlabNugetRegistryPair(
|
|
|
37
37
|
if (url) {
|
|
38
38
|
return { tokenEnvVar, url };
|
|
39
39
|
}
|
|
40
|
-
error(
|
|
40
|
+
console.error(
|
|
41
41
|
new Error(
|
|
42
42
|
`The environment variables ${nameof.CI_API_V4_URL} or ${nameof.CI_PROJECT_ID} do not exist and a custom GitLab Packages NuGet registry URL was not provided.`,
|
|
43
43
|
),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ok } from 'node:assert/strict';
|
|
2
|
+
import { getEnvVarValue } from '../envUtils.js';
|
|
3
|
+
import { MSBuildProject, MSBuildProjectPreDefinedProperties } from './MSBuildProject.js';
|
|
2
4
|
import { getGithubNugetRegistryPair, nugetGitHubUrlBase } from './dotnetGHPR.js';
|
|
3
5
|
import { getGitlabNugetRegistryPair } from './dotnetGLPR.js';
|
|
4
|
-
import { MSBuildProject, MSBuildProjectPreDefinedProperties } from './MSBuildProject.js';
|
|
5
|
-
|
|
6
6
|
|
|
7
7
|
function formatDotnetPublish(projectsToPublish: string[], publishProperties: string[]): string {
|
|
8
8
|
/* Fun Fact: You can define a property and get the evaluated value in the same command!
|
|
@@ -175,8 +175,8 @@ export async function configureDotnetNugetPush(
|
|
|
175
175
|
return registries
|
|
176
176
|
.map(
|
|
177
177
|
(registry) => {
|
|
178
|
-
const tokenValue =
|
|
179
|
-
ok(
|
|
178
|
+
const tokenValue = getEnvVarValue(registry.tokenEnvVar);
|
|
179
|
+
ok(getEnvVarValue('SKIP_TOKEN') === 'true' || tokenValue, `The environment variable ${registry.tokenEnvVar} is undefined!`);
|
|
180
180
|
`dotnet nuget push ${nupkgDir} --source ${registry.url} --token ${tokenValue ?? '**placeholder**'}`
|
|
181
181
|
}
|
|
182
182
|
)
|
package/src/dotnet.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export * as msbuildProject from "./dotnet/MSBuildProject.js"
|
|
2
|
+
export * as msbuildProjectProperties from "./dotnet/MSBuildProjectProperties.js"
|
|
3
|
+
export * as createDummyNupkg from './dotnet/createDummyNupkg.js'
|
|
1
4
|
export * as dotnetGHPR from "./dotnet/dotnetGHPR.js"
|
|
2
5
|
export * as dotnetGLPR from "./dotnet/dotnetGLPR.js"
|
|
3
6
|
export * as dotnetHelpers from "./dotnet/dotnetHelpers.js"
|
|
4
|
-
export * as msbuildProject from "./dotnet/MSBuildProject.js"
|
|
5
|
-
export * as msbuildProjectProperties from "./dotnet/MSBuildProjectProperties.js"
|
package/src/envUtils.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { config as loadDotenv, type DotenvConfigOptions } from "dotenv";
|
|
2
|
+
import { env } from 'node:process';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Load a .env file from the CWD with the given options (or defaults), returns the new value of process.env
|
|
6
|
+
* @param dotenvOptions
|
|
7
|
+
* @param overrides
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export function getEnv(dotenvOptions?: DotenvConfigOptions, overrides?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
11
|
+
loadDotenv(dotenvOptions);
|
|
12
|
+
|
|
13
|
+
if (overrides)
|
|
14
|
+
Object.assign(env, overrides);
|
|
15
|
+
|
|
16
|
+
return env;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the value from the given env var. If undefined, load .env from CWD and try again or return undefined.
|
|
21
|
+
* @param envVar
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export function getEnvVarValue(envVar: string): string | undefined {
|
|
25
|
+
let value = env[envVar];
|
|
26
|
+
if (!value) {
|
|
27
|
+
try {
|
|
28
|
+
loadDotenv();
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.error(String(err))
|
|
32
|
+
}
|
|
33
|
+
value = env[envVar];
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
package/src/eslintConfig.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import jsonc from "eslint-plugin-jsonc";
|
|
2
|
-
import tseslint from "typescript-eslint";
|
|
3
|
-
import { type TSESLint } from "@typescript-eslint/utils";
|
|
4
1
|
import eslint from "@eslint/js";
|
|
2
|
+
import { type TSESLint } from "@typescript-eslint/utils";
|
|
3
|
+
import jsonc from "eslint-plugin-jsonc";
|
|
5
4
|
import { createRequire } from "module";
|
|
5
|
+
import tseslint from "typescript-eslint";
|
|
6
6
|
|
|
7
7
|
// CJS compatibility; it started transpiling to a top-level await after upgrading from packemon 4.0.1 to 4.1.0
|
|
8
8
|
const require = createRequire(import.meta.url);
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { Options as GitOptions } from '@semantic-release/git';
|
|
2
|
+
import type { Options as GithubOptions } from '@semantic-release/github';
|
|
1
3
|
import type { Options, PluginSpec } from 'semantic-release';
|
|
2
|
-
import type { Options as GitOptions } from '@semantic-release/git'
|
|
3
|
-
import type { Options as GithubOptions } from '@semantic-release/github'
|
|
4
4
|
import { DefaultOptions } from './setupGitPluginSpec.js';
|
|
5
5
|
|
|
6
6
|
export const defaultPlugins: readonly PluginSpec[] = [
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import { inspect } from 'node:util';
|
|
14
15
|
import type { Options, PluginSpec } from 'semantic-release';
|
|
16
|
+
import debug from './debug.js';
|
|
15
17
|
import { configureDotnetNugetPush, configurePrepareCmd } from './dotnet/dotnetHelpers.js';
|
|
18
|
+
import { getEnvVarValue } from './envUtils.js';
|
|
16
19
|
import { baseConfig, defaultPlugins } from './semanticReleaseConfig.js';
|
|
17
20
|
import { setupGitPluginSpec } from './setupGitPluginSpec.js';
|
|
18
|
-
import debug from './debug.js'
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* TODO: options/params for inserts/edits. NOT ready for production. Currently, this can only add Git plugin's options if undefined or one or more is missing.
|
|
@@ -83,13 +85,13 @@ export function appendPlugins(
|
|
|
83
85
|
*/
|
|
84
86
|
export function getConfig(projectsToPublish: string[] = [], projectsToPackAndPush: string[] | false = []): Options {
|
|
85
87
|
if (debug.enabled) {
|
|
86
|
-
debug('hce.shared-config:\n
|
|
88
|
+
console.debug('hce.shared-config:\n' + inspect(baseConfig, false, Infinity, true));
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
const errors: Error[] = [];
|
|
90
92
|
|
|
91
93
|
if (projectsToPublish.length === 0) {
|
|
92
|
-
const _ =
|
|
94
|
+
const _ = getEnvVarValue("PROJECTS_TO_PUBLISH");
|
|
93
95
|
if (_ === undefined)
|
|
94
96
|
errors.push(new Error("projectsToPublish.length must be > 0 or PROJECTS_TO_PUBLISH must be defined and contain at least one path."));
|
|
95
97
|
else
|
|
@@ -97,7 +99,7 @@ export function getConfig(projectsToPublish: string[] = [], projectsToPackAndPus
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
if (projectsToPackAndPush !== false && projectsToPackAndPush.length === 0) {
|
|
100
|
-
const _ =
|
|
102
|
+
const _ = getEnvVarValue("PROJECTS_TO_PACK_AND_PUSH")
|
|
101
103
|
if (_ === undefined)
|
|
102
104
|
errors.push(new Error("projectsToPackAndPush.length must be > 0 or PROJECTS_TO_PACK_AND_PUSH must be defined and contain at least one path."));
|
|
103
105
|
else
|
|
@@ -108,7 +110,7 @@ export function getConfig(projectsToPublish: string[] = [], projectsToPackAndPus
|
|
|
108
110
|
throw new Error(
|
|
109
111
|
[
|
|
110
112
|
"getConfig cannot continue. One or more errors occurred.",
|
|
111
|
-
...(errors.map(v => v.
|
|
113
|
+
...(errors.map(v => v.stack))
|
|
112
114
|
].join('\n')
|
|
113
115
|
)
|
|
114
116
|
}
|
|
@@ -119,7 +121,7 @@ export function getConfig(projectsToPublish: string[] = [], projectsToPackAndPus
|
|
|
119
121
|
config = appendPlugins(config, projectsToPublish, projectsToPackAndPush);
|
|
120
122
|
|
|
121
123
|
if (debug.enabled) {
|
|
122
|
-
debug(
|
|
124
|
+
console.debug(`modified plugins array:\n${inspect(config.plugins, false, Infinity)}`);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
return config;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PluginSpec } from 'semantic-release';
|
|
2
1
|
import type { AssetEntry, Options as GitOptions } from '@semantic-release/git';
|
|
2
|
+
import type { PluginSpec } from 'semantic-release';
|
|
3
3
|
|
|
4
4
|
export const GitPluginId = '@semantic-release/git';
|
|
5
5
|
/** As specified at https://github.com/semantic-release/git#options */
|