Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc67fad700 | ||
|
|
67a28beebc | ||
|
|
ab07c6ee52 | ||
|
|
1ebaf7335e | ||
|
|
b85449155b | ||
|
|
950d5c5a19 | ||
|
|
4f5c0cdd7c | ||
|
|
d790b19dfe | ||
|
|
8e5fadaee0 | ||
|
|
1590065a78 | ||
|
|
2e1b37d8fb | ||
|
|
3dc747dce1 | ||
|
|
2573e7f4c0 | ||
|
|
5059fd86e9 | ||
|
|
4ebf07e899 | ||
|
|
d722849477 | ||
|
|
d7ee0471b0 | ||
|
|
40314b1002 | ||
|
|
b95ff7bca1 | ||
|
|
9f9136cb72 | ||
|
|
16530875f9 | ||
|
|
955386a494 | ||
|
|
de77530ea5 | ||
|
|
2d1351cb35 | ||
|
|
11da833829 | ||
|
|
823190d895 | ||
|
|
1b71c03ec0 | ||
|
|
579f64ca0a | ||
|
|
3f29bdade4 | ||
|
|
8b56ea036f | ||
|
|
2e2fadf6e3 | ||
|
|
015b1b5f51 | ||
|
|
4b1a4bb484 | ||
|
|
3ba533f0ff | ||
|
|
f866d47eb4 | ||
|
|
03ca5ee9b4 | ||
|
|
a57cec0ff6 | ||
|
|
2a3abf56ec | ||
|
|
9e64bda1bc | ||
|
|
dd732b0272 | ||
|
|
24d9720e95 | ||
|
|
74d5634479 | ||
|
|
f92370924c | ||
|
|
32a61cce5a | ||
|
|
4a4792c2ca |
2
.github/workflows/automerge-dependabot.yml
vendored
2
.github/workflows/automerge-dependabot.yml
vendored
@@ -6,7 +6,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- uses: peter-evans/enable-pull-request-automerge@v2
|
||||
- uses: peter-evans/enable-pull-request-automerge@v3
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
pull-request-number: ${{ github.event.pull_request.number }}
|
||||
|
||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -92,7 +92,7 @@ jobs:
|
||||
name: dist
|
||||
path: dist
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v4
|
||||
uses: peter-evans/create-pull-request@v5
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
commit-message: 'build: update distribution'
|
||||
|
||||
@@ -31,7 +31,7 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
|
||||
#### Content limits
|
||||
|
||||
DockerHub has content limits.
|
||||
The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 characters.
|
||||
The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 bytes.
|
||||
This action truncates content to prevent the request being rejected.
|
||||
If the content has been truncated a warning will be issued in the run log.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {completeRelativeUrls, truncateToBytes} from '../src/readme-helper'
|
||||
import {completeRelativeUrls} from '../src/readme-helper'
|
||||
|
||||
describe('complete relative urls tests', () => {
|
||||
const GITHUB_SERVER_URL = process.env['GITHUB_SERVER_URL']
|
||||
@@ -333,12 +333,3 @@ describe('complete relative urls tests', () => {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('truncate to bytes tests', () => {
|
||||
test('unicode aware truncation to a number of bytes', async () => {
|
||||
expect(truncateToBytes('test string to be truncated', 10)).toEqual(
|
||||
'test strin'
|
||||
)
|
||||
expect(truncateToBytes('😀😁😂🤣😃😄😅', 10)).toEqual('😀😁')
|
||||
})
|
||||
})
|
||||
|
||||
10
__test__/utils.unit.test.ts
Normal file
10
__test__/utils.unit.test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import {truncateToBytes} from '../src/utils'
|
||||
|
||||
describe('truncate to bytes tests', () => {
|
||||
test('unicode aware truncation to a number of bytes', async () => {
|
||||
expect(truncateToBytes('test string to be truncated', 10)).toEqual(
|
||||
'test strin'
|
||||
)
|
||||
expect(truncateToBytes('😀😁😂🤣😃😄😅', 10)).toEqual('😀😁')
|
||||
})
|
||||
})
|
||||
60
dist/index.js
vendored
60
dist/index.js
vendored
@@ -42,7 +42,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.updateRepositoryDescription = exports.getToken = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const fetch = __importStar(__nccwpck_require__(467));
|
||||
const DESCRIPTION_MAX_CHARS = 100;
|
||||
function getToken(username, password) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const body = {
|
||||
@@ -69,7 +68,7 @@ function updateRepositoryDescription(token, repository, description, fullDescrip
|
||||
full_description: fullDescription
|
||||
};
|
||||
if (description) {
|
||||
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS);
|
||||
body['description'] = description;
|
||||
}
|
||||
yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||
method: 'patch',
|
||||
@@ -238,12 +237,9 @@ const core = __importStar(__nccwpck_require__(2186));
|
||||
const inputHelper = __importStar(__nccwpck_require__(5480));
|
||||
const dockerhubHelper = __importStar(__nccwpck_require__(1812));
|
||||
const readmeHelper = __importStar(__nccwpck_require__(3367));
|
||||
const utils = __importStar(__nccwpck_require__(918));
|
||||
const util_1 = __nccwpck_require__(3837);
|
||||
function getErrorMessage(error) {
|
||||
if (error instanceof Error)
|
||||
return error.message;
|
||||
return String(error);
|
||||
}
|
||||
const SHORT_DESCRIPTION_MAX_BYTES = 100;
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -254,17 +250,23 @@ function run() {
|
||||
core.info('Reading description source file');
|
||||
const readmeContent = yield readmeHelper.getReadmeContent(inputs.readmeFilepath, inputs.enableUrlCompletion, inputs.imageExtensions);
|
||||
core.debug(readmeContent);
|
||||
// Truncate the short description if it is too long
|
||||
const truncatedShortDescription = utils.truncateToBytes(inputs.shortDescription, SHORT_DESCRIPTION_MAX_BYTES);
|
||||
if (truncatedShortDescription.length !== inputs.shortDescription.length) {
|
||||
core.warning(`The short description exceeds DockerHub's limit and has been truncated to ${SHORT_DESCRIPTION_MAX_BYTES} bytes.`);
|
||||
}
|
||||
core.debug(`Truncated short description: ${truncatedShortDescription}`);
|
||||
// Acquire a token for the Docker Hub API
|
||||
core.info('Acquiring token');
|
||||
const token = yield dockerhubHelper.getToken(inputs.username, inputs.password);
|
||||
// Send a PATCH request to update the description of the repository
|
||||
core.info('Sending PATCH request');
|
||||
yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, inputs.shortDescription, readmeContent);
|
||||
yield dockerhubHelper.updateRepositoryDescription(token, inputs.repository, truncatedShortDescription, readmeContent);
|
||||
core.info('Request successful');
|
||||
}
|
||||
catch (error) {
|
||||
core.debug((0, util_1.inspect)(error));
|
||||
core.setFailed(getErrorMessage(error));
|
||||
core.setFailed(utils.getErrorMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -311,10 +313,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.completeRelativeUrls = exports.getReadmeContent = exports.truncateToBytes = exports.ENABLE_URL_COMPLETION_DEFAULT = exports.IMAGE_EXTENSIONS_DEFAULT = exports.README_FILEPATH_DEFAULT = void 0;
|
||||
exports.completeRelativeUrls = exports.getReadmeContent = exports.ENABLE_URL_COMPLETION_DEFAULT = exports.IMAGE_EXTENSIONS_DEFAULT = exports.README_FILEPATH_DEFAULT = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
const unicodeSubstring = __nccwpck_require__(6986);
|
||||
const utils = __importStar(__nccwpck_require__(918));
|
||||
exports.README_FILEPATH_DEFAULT = './README.md';
|
||||
exports.IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp';
|
||||
exports.ENABLE_URL_COMPLETION_DEFAULT = false;
|
||||
@@ -323,14 +325,6 @@ const REPOSITORY_URL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHU
|
||||
const BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`;
|
||||
const RAW_PREFIX = `${REPOSITORY_URL}/raw/${process.env['GITHUB_REF_NAME']}/`;
|
||||
const MAX_BYTES = 25000;
|
||||
function truncateToBytes(s, n) {
|
||||
let len = n;
|
||||
while (Buffer.byteLength(s) > n) {
|
||||
s = unicodeSubstring(s, 0, len--);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
exports.truncateToBytes = truncateToBytes;
|
||||
function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Fetch the readme content
|
||||
@@ -338,7 +332,7 @@ function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions)
|
||||
encoding: 'utf8'
|
||||
});
|
||||
readmeContent = completeRelativeUrls(readmeContent, readmeFilepath, enableUrlCompletion, imageExtensions);
|
||||
const truncatedReadmeContent = truncateToBytes(readmeContent, MAX_BYTES);
|
||||
const truncatedReadmeContent = utils.truncateToBytes(readmeContent, MAX_BYTES);
|
||||
if (truncatedReadmeContent.length !== readmeContent.length) {
|
||||
core.warning(`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`);
|
||||
}
|
||||
@@ -446,6 +440,32 @@ function getRelativeUrlRules() {
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 918:
|
||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.truncateToBytes = exports.getErrorMessage = void 0;
|
||||
const unicodeSubstring = __nccwpck_require__(6986);
|
||||
function getErrorMessage(error) {
|
||||
if (error instanceof Error)
|
||||
return error.message;
|
||||
return String(error);
|
||||
}
|
||||
exports.getErrorMessage = getErrorMessage;
|
||||
function truncateToBytes(s, n) {
|
||||
let len = n;
|
||||
while (Buffer.byteLength(s) > n) {
|
||||
s = unicodeSubstring(s, 0, len--);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
exports.truncateToBytes = truncateToBytes;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7351:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/bin/sh -l
|
||||
set -eo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# Execute the action code and output to file
|
||||
node index.js > action.log 2>&1
|
||||
node /index.js > action.log 2>&1
|
||||
exit_code=$?
|
||||
|
||||
# Remove lines containing sensitive information from the log
|
||||
sed -i '/::debug::/d' ./action.log
|
||||
@@ -11,3 +11,6 @@ sed -i '/::add-mask::/d' ./action.log
|
||||
|
||||
# Output the log
|
||||
cat action.log
|
||||
|
||||
# Exit using the exit code of the node command
|
||||
exit $exit_code
|
||||
|
||||
195
package-lock.json
generated
195
package-lock.json
generated
@@ -10,21 +10,21 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"node-fetch": "^2.6.9",
|
||||
"node-fetch": "^2.6.11",
|
||||
"unicode-substring": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.18.14",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"@types/node": "^16.18.36",
|
||||
"@typescript-eslint/parser": "^5.59.11",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.35.0",
|
||||
"eslint-plugin-github": "^4.6.1",
|
||||
"eslint": "^8.43.0",
|
||||
"eslint-plugin-github": "^4.8.0",
|
||||
"eslint-plugin-jest": "^25.7.0",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^27.5.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.8.4",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^27.1.5",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
@@ -683,15 +683,39 @@
|
||||
"integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@eslint-community/eslint-utils": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.2.0.tgz",
|
||||
"integrity": "sha512-gB8T4H4DEfX2IV9zGDJPOBgP1e/DbfCPDTtEqUMckpvzS1OYtva8JdFYBqMwYk7xAQ429WGF/UPqn8uQ//h2vQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"eslint": "^6.0.0 || ^7.0.0 || >=8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint-community/regexpp": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.4.0.tgz",
|
||||
"integrity": "sha512-A9983Q0LnDGdLPjxyXQ00sbV+K+O+ko2Dr+CZigbHWtX9pNfxlaBkMR8X1CztI73zuEyEBXTVjx7CE+/VSwDiQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.0.0 || ^14.0.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/eslintrc": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.0.tgz",
|
||||
"integrity": "sha512-fluIaaV+GyV24CCu/ggiHdV+j4RNh85yQnAYS/G2mZODZgGmmlrgCydjUcV3YvxCm9x8nMAfThsqTni4KiXT4A==",
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.3.tgz",
|
||||
"integrity": "sha512-+5gy6OQfk+xx3q0d6jGZZC3f3KzAkXc/IanVxd1is/VIIziRqqt3ongQz0FiTUXqTk0c7aDB3OaFuKnuSoJicQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"ajv": "^6.12.4",
|
||||
"debug": "^4.3.2",
|
||||
"espree": "^9.4.0",
|
||||
"espree": "^9.5.2",
|
||||
"globals": "^13.19.0",
|
||||
"ignore": "^5.2.0",
|
||||
"import-fresh": "^3.2.1",
|
||||
@@ -707,9 +731,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@eslint/js": {
|
||||
"version": "8.35.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.35.0.tgz",
|
||||
"integrity": "sha512-JXdzbRiWclLVoD8sNUjR443VVlYqiYmDVT6rGUEIEHU5YJW0gaVZwV2xgM7D4arkvASqD0IlLUVjHiFuxaftRw==",
|
||||
"version": "8.43.0",
|
||||
"resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.43.0.tgz",
|
||||
"integrity": "sha512-s2UHCoiXfxMvmfzqoN+vrQ84ahUSYde9qNO1MdxmoEhyHWsfmwOpFlwYV+ePJEVc7gFnATGUi376WowX1N7tFg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@@ -722,9 +746,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@humanwhocodes/config-array": {
|
||||
"version": "0.11.8",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
|
||||
"integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==",
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.10.tgz",
|
||||
"integrity": "sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@humanwhocodes/object-schema": "^1.2.1",
|
||||
@@ -1270,9 +1294,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.18.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.14.tgz",
|
||||
"integrity": "sha512-wvzClDGQXOCVNU4APPopC2KtMYukaF1MN/W3xAmslx22Z4/IF1/izDMekuyoUlwfnDHYCIZGaj7jMwnJKBTxKw==",
|
||||
"version": "16.18.36",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.36.tgz",
|
||||
"integrity": "sha512-8egDX8dE50XyXWH6C6PRCNkTP106DuUrvdrednFouDSmCi7IOvrqr0frznfZaHifHH/3aq/7a7v9N4wdXMqhBQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/prettier": {
|
||||
@@ -1381,14 +1405,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser": {
|
||||
"version": "5.54.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.54.0.tgz",
|
||||
"integrity": "sha512-aAVL3Mu2qTi+h/r04WI/5PfNWvO6pdhpeMRWk9R7rEV4mwJNzoWf5CCU5vDKBsPIFQFjEq1xg7XBI2rjiMXQbQ==",
|
||||
"version": "5.59.11",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.59.11.tgz",
|
||||
"integrity": "sha512-s9ZF3M+Nym6CAZEkJJeO2TFHHDsKAM3ecNkLuH4i4s8/RCPnF5JRip2GyviYkeEAcwGMJxkqG9h2dAsnA1nZpA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "5.54.0",
|
||||
"@typescript-eslint/types": "5.54.0",
|
||||
"@typescript-eslint/typescript-estree": "5.54.0",
|
||||
"@typescript-eslint/scope-manager": "5.59.11",
|
||||
"@typescript-eslint/types": "5.59.11",
|
||||
"@typescript-eslint/typescript-estree": "5.59.11",
|
||||
"debug": "^4.3.4"
|
||||
},
|
||||
"engines": {
|
||||
@@ -1408,13 +1432,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/scope-manager": {
|
||||
"version": "5.54.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.54.0.tgz",
|
||||
"integrity": "sha512-VTPYNZ7vaWtYna9M4oD42zENOBrb+ZYyCNdFs949GcN8Miwn37b8b7eMj+EZaq7VK9fx0Jd+JhmkhjFhvnovhg==",
|
||||
"version": "5.59.11",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.59.11.tgz",
|
||||
"integrity": "sha512-dHFOsxoLFtrIcSj5h0QoBT/89hxQONwmn3FOQ0GOQcLOOXm+MIrS8zEAhs4tWl5MraxCY3ZJpaXQQdFMc2Tu+Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.54.0",
|
||||
"@typescript-eslint/visitor-keys": "5.54.0"
|
||||
"@typescript-eslint/types": "5.59.11",
|
||||
"@typescript-eslint/visitor-keys": "5.59.11"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@@ -1425,9 +1449,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/types": {
|
||||
"version": "5.54.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.54.0.tgz",
|
||||
"integrity": "sha512-nExy+fDCBEgqblasfeE3aQ3NuafBUxZxgxXcYfzYRZFHdVvk5q60KhCSkG0noHgHRo/xQ/BOzURLZAafFpTkmQ==",
|
||||
"version": "5.59.11",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.59.11.tgz",
|
||||
"integrity": "sha512-epoN6R6tkvBYSc+cllrz+c2sOFWkbisJZWkOE+y3xHtvYaOE6Wk6B8e114McRJwFRjGvYdJwLXQH5c9osME/AA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@@ -1438,13 +1462,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/typescript-estree": {
|
||||
"version": "5.54.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.54.0.tgz",
|
||||
"integrity": "sha512-X2rJG97Wj/VRo5YxJ8Qx26Zqf0RRKsVHd4sav8NElhbZzhpBI8jU54i6hfo9eheumj4oO4dcRN1B/zIVEqR/MQ==",
|
||||
"version": "5.59.11",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.59.11.tgz",
|
||||
"integrity": "sha512-YupOpot5hJO0maupJXixi6l5ETdrITxeo5eBOeuV7RSKgYdU3G5cxO49/9WRnJq9EMrB7AuTSLH/bqOsXi7wPA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.54.0",
|
||||
"@typescript-eslint/visitor-keys": "5.54.0",
|
||||
"@typescript-eslint/types": "5.59.11",
|
||||
"@typescript-eslint/visitor-keys": "5.59.11",
|
||||
"debug": "^4.3.4",
|
||||
"globby": "^11.1.0",
|
||||
"is-glob": "^4.0.3",
|
||||
@@ -1465,12 +1489,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@typescript-eslint/parser/node_modules/@typescript-eslint/visitor-keys": {
|
||||
"version": "5.54.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.54.0.tgz",
|
||||
"integrity": "sha512-xu4wT7aRCakGINTLGeyGqDn+78BwFlggwBjnHa1ar/KaGagnmwLYmlrXIrgAaQ3AE1Vd6nLfKASm7LrFHNbKGA==",
|
||||
"version": "5.59.11",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.59.11.tgz",
|
||||
"integrity": "sha512-KGYniTGG3AMTuKF9QBD7EIrvufkB6O6uX3knP73xbKLMpH+QRPcgnCxjWXSHjMRuOxFLovljqQgQpR0c7GvjoA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/types": "5.54.0",
|
||||
"@typescript-eslint/types": "5.59.11",
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -2605,14 +2629,16 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint": {
|
||||
"version": "8.35.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.35.0.tgz",
|
||||
"integrity": "sha512-BxAf1fVL7w+JLRQhWl2pzGeSiGqbWumV4WNvc9Rhp6tiCtm4oHnyPBSEtMGZwrQgudFQ+otqzWoPB7x+hxoWsw==",
|
||||
"version": "8.43.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.43.0.tgz",
|
||||
"integrity": "sha512-aaCpf2JqqKesMFGgmRPessmVKjcGXqdlAYLLC3THM8t5nBRZRQ+st5WM/hoJXkdioEXLLbXgclUpM0TXo5HX5Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@eslint/eslintrc": "^2.0.0",
|
||||
"@eslint/js": "8.35.0",
|
||||
"@humanwhocodes/config-array": "^0.11.8",
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.4.0",
|
||||
"@eslint/eslintrc": "^2.0.3",
|
||||
"@eslint/js": "8.43.0",
|
||||
"@humanwhocodes/config-array": "^0.11.10",
|
||||
"@humanwhocodes/module-importer": "^1.0.1",
|
||||
"@nodelib/fs.walk": "^1.2.8",
|
||||
"ajv": "^6.10.0",
|
||||
@@ -2621,10 +2647,9 @@
|
||||
"debug": "^4.3.2",
|
||||
"doctrine": "^3.0.0",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"eslint-scope": "^7.1.1",
|
||||
"eslint-utils": "^3.0.0",
|
||||
"eslint-visitor-keys": "^3.3.0",
|
||||
"espree": "^9.4.0",
|
||||
"eslint-scope": "^7.2.0",
|
||||
"eslint-visitor-keys": "^3.4.1",
|
||||
"espree": "^9.5.2",
|
||||
"esquery": "^1.4.2",
|
||||
"esutils": "^2.0.2",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
@@ -2632,13 +2657,12 @@
|
||||
"find-up": "^5.0.0",
|
||||
"glob-parent": "^6.0.2",
|
||||
"globals": "^13.19.0",
|
||||
"grapheme-splitter": "^1.0.4",
|
||||
"graphemer": "^1.4.0",
|
||||
"ignore": "^5.2.0",
|
||||
"import-fresh": "^3.0.0",
|
||||
"imurmurhash": "^0.1.4",
|
||||
"is-glob": "^4.0.0",
|
||||
"is-path-inside": "^3.0.3",
|
||||
"js-sdsl": "^4.1.4",
|
||||
"js-yaml": "^4.1.0",
|
||||
"json-stable-stringify-without-jsonify": "^1.0.1",
|
||||
"levn": "^0.4.1",
|
||||
@@ -2646,7 +2670,6 @@
|
||||
"minimatch": "^3.1.2",
|
||||
"natural-compare": "^1.4.0",
|
||||
"optionator": "^0.9.1",
|
||||
"regexpp": "^3.2.0",
|
||||
"strip-ansi": "^6.0.1",
|
||||
"strip-json-comments": "^3.1.0",
|
||||
"text-table": "^0.2.0"
|
||||
@@ -2771,9 +2794,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-plugin-github": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.6.1.tgz",
|
||||
"integrity": "sha512-AjCxE+2JmT+ppq3AVNra3iJ0BTAj6rYmtHJtkEcIEtrBHVi9xmCl5ZdIYLh7U/YKGT2cttdcYvbe59HEYW67KA==",
|
||||
"version": "4.8.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-plugin-github/-/eslint-plugin-github-4.8.0.tgz",
|
||||
"integrity": "sha512-1qu1qcyac4FfZmT9KNPr5250DwWzwp6uy6xAqHD2boE4OquUpeTni05yPn1b6y6vUYm/q8+npTdyYiRSqvg+BQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@github/browserslist-config": "^1.0.0",
|
||||
@@ -2973,9 +2996,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-scope": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz",
|
||||
"integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==",
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz",
|
||||
"integrity": "sha512-DYj5deGlHBfMt15J7rdtyKNq/Nqlv5KfU4iodrQ019XESsRnwXH9KAE0y3cwtUHDo2ob7CypAnCqefh6vioWRw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"esrecurse": "^4.3.0",
|
||||
@@ -2983,6 +3006,9 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-utils": {
|
||||
@@ -3013,12 +3039,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-visitor-keys": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz",
|
||||
"integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==",
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.1.tgz",
|
||||
"integrity": "sha512-pZnmmLwYzf+kWaM/Qgrvpen51upAktaaiI01nsJD/Yr3lMOdNtq0cxkrrg16w64VtisN6okbs7Q8AfGqj4c9fA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/eslint/node_modules/find-up": {
|
||||
@@ -3104,14 +3133,14 @@
|
||||
}
|
||||
},
|
||||
"node_modules/espree": {
|
||||
"version": "9.4.1",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-9.4.1.tgz",
|
||||
"integrity": "sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==",
|
||||
"version": "9.5.2",
|
||||
"resolved": "https://registry.npmjs.org/espree/-/espree-9.5.2.tgz",
|
||||
"integrity": "sha512-7OASN1Wma5fum5SrNhFMAMJxOUAbhyfQ8dQ//PJaJbNw0URTPWqIghHWt1MmAANKhHZIYOHruW4Kw4ruUWOdGw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"acorn": "^8.8.0",
|
||||
"acorn-jsx": "^5.3.2",
|
||||
"eslint-visitor-keys": "^3.3.0"
|
||||
"eslint-visitor-keys": "^3.4.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
@@ -3571,10 +3600,10 @@
|
||||
"integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/grapheme-splitter": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz",
|
||||
"integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==",
|
||||
"node_modules/graphemer": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz",
|
||||
"integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/has": {
|
||||
@@ -4926,16 +4955,6 @@
|
||||
"url": "https://github.com/chalk/supports-color?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/js-sdsl": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.2.0.tgz",
|
||||
"integrity": "sha512-dyBIzQBDkCqCu+0upx25Y2jGdbTGxE9fshMsCdK0ViOongpV+n5tXRcZY9v7CaVQ79AGS9KA1KHtojxiM7aXSQ==",
|
||||
"dev": true,
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/js-sdsl"
|
||||
}
|
||||
},
|
||||
"node_modules/js-tokens": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||
@@ -5308,9 +5327,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.6.9",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz",
|
||||
"integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==",
|
||||
"version": "2.6.11",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.11.tgz",
|
||||
"integrity": "sha512-4I6pdBY1EthSqDmJkiNk3JIT8cswwR9nfeW/cPdUagJYEQG7R95WRH74wpz7ma8Gh/9dI9FP+OU+0E4FvtA55w==",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
@@ -5685,9 +5704,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "2.8.4",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.4.tgz",
|
||||
"integrity": "sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==",
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"prettier": "bin-prettier.js"
|
||||
|
||||
12
package.json
12
package.json
@@ -28,21 +28,21 @@
|
||||
"homepage": "https://github.com/peter-evans/dockerhub-description#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"node-fetch": "^2.6.9",
|
||||
"node-fetch": "^2.6.11",
|
||||
"unicode-substring": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.18.14",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"@types/node": "^16.18.36",
|
||||
"@typescript-eslint/parser": "^5.59.11",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"eslint": "^8.35.0",
|
||||
"eslint-plugin-github": "^4.6.1",
|
||||
"eslint": "^8.43.0",
|
||||
"eslint-plugin-github": "^4.8.0",
|
||||
"eslint-plugin-jest": "^25.7.0",
|
||||
"jest": "^27.5.1",
|
||||
"jest-circus": "^27.5.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.8.4",
|
||||
"prettier": "^2.8.8",
|
||||
"ts-jest": "^27.1.5",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fetch from 'node-fetch'
|
||||
|
||||
const DESCRIPTION_MAX_CHARS = 100
|
||||
|
||||
export async function getToken(
|
||||
username: string,
|
||||
password: string
|
||||
@@ -36,7 +34,7 @@ export async function updateRepositoryDescription(
|
||||
full_description: fullDescription
|
||||
}
|
||||
if (description) {
|
||||
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS)
|
||||
body['description'] = description
|
||||
}
|
||||
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||
method: 'patch',
|
||||
|
||||
22
src/main.ts
22
src/main.ts
@@ -2,12 +2,10 @@ import * as core from '@actions/core'
|
||||
import * as inputHelper from './input-helper'
|
||||
import * as dockerhubHelper from './dockerhub-helper'
|
||||
import * as readmeHelper from './readme-helper'
|
||||
import * as utils from './utils'
|
||||
import {inspect} from 'util'
|
||||
|
||||
function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
const SHORT_DESCRIPTION_MAX_BYTES = 100
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
@@ -25,6 +23,18 @@ async function run(): Promise<void> {
|
||||
)
|
||||
core.debug(readmeContent)
|
||||
|
||||
// Truncate the short description if it is too long
|
||||
const truncatedShortDescription = utils.truncateToBytes(
|
||||
inputs.shortDescription,
|
||||
SHORT_DESCRIPTION_MAX_BYTES
|
||||
)
|
||||
if (truncatedShortDescription.length !== inputs.shortDescription.length) {
|
||||
core.warning(
|
||||
`The short description exceeds DockerHub's limit and has been truncated to ${SHORT_DESCRIPTION_MAX_BYTES} bytes.`
|
||||
)
|
||||
}
|
||||
core.debug(`Truncated short description: ${truncatedShortDescription}`)
|
||||
|
||||
// Acquire a token for the Docker Hub API
|
||||
core.info('Acquiring token')
|
||||
const token = await dockerhubHelper.getToken(
|
||||
@@ -36,13 +46,13 @@ async function run(): Promise<void> {
|
||||
await dockerhubHelper.updateRepositoryDescription(
|
||||
token,
|
||||
inputs.repository,
|
||||
inputs.shortDescription,
|
||||
truncatedShortDescription,
|
||||
readmeContent
|
||||
)
|
||||
core.info('Request successful')
|
||||
} catch (error) {
|
||||
core.debug(inspect(error))
|
||||
core.setFailed(getErrorMessage(error))
|
||||
core.setFailed(utils.getErrorMessage(error))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fs from 'fs'
|
||||
import unicodeSubstring = require('unicode-substring')
|
||||
import * as utils from './utils'
|
||||
|
||||
export const README_FILEPATH_DEFAULT = './README.md'
|
||||
export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'
|
||||
@@ -28,14 +28,6 @@ type Rule = {
|
||||
absUrlPrefix: string
|
||||
}
|
||||
|
||||
export function truncateToBytes(s: string, n: number): string {
|
||||
let len = n
|
||||
while (Buffer.byteLength(s) > n) {
|
||||
s = unicodeSubstring(s, 0, len--)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
export async function getReadmeContent(
|
||||
readmeFilepath: string,
|
||||
enableUrlCompletion: boolean,
|
||||
@@ -53,7 +45,7 @@ export async function getReadmeContent(
|
||||
imageExtensions
|
||||
)
|
||||
|
||||
const truncatedReadmeContent = truncateToBytes(readmeContent, MAX_BYTES)
|
||||
const truncatedReadmeContent = utils.truncateToBytes(readmeContent, MAX_BYTES)
|
||||
if (truncatedReadmeContent.length !== readmeContent.length) {
|
||||
core.warning(
|
||||
`The README content exceeds DockerHub's limit and has been truncated to ${MAX_BYTES} bytes.`
|
||||
|
||||
14
src/utils.ts
Normal file
14
src/utils.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import unicodeSubstring = require('unicode-substring')
|
||||
|
||||
export function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
export function truncateToBytes(s: string, n: number): string {
|
||||
let len = n
|
||||
while (Buffer.byteLength(s) > n) {
|
||||
s = unicodeSubstring(s, 0, len--)
|
||||
}
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user