17 Commits

Author SHA1 Message Date
Peter Evans
4b1a4bb484 feat: truncate short description exceeding the byte limit (#143)
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
* feat: truncate short description exceeding the byte limit

* fix tests
2023-04-07 09:16:46 +09:00
dependabot[bot]
3ba533f0ff build(deps-dev): bump @types/node from 16.18.21 to 16.18.23 (#140)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.21 to 16.18.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 15:02:35 +00:00
dependabot[bot]
f866d47eb4 build(deps-dev): bump eslint from 8.36.0 to 8.37.0 (#141)
Bumps [eslint](https://github.com/eslint/eslint) from 8.36.0 to 8.37.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.36.0...v8.37.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 15:01:15 +00:00
dependabot[bot]
03ca5ee9b4 build(deps-dev): bump @typescript-eslint/parser from 5.56.0 to 5.57.0 (#139)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.56.0 to 5.57.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.57.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-02 15:00:10 +00:00
dependabot[bot]
a57cec0ff6 build(deps-dev): bump @typescript-eslint/parser from 5.55.0 to 5.56.0 (#138)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.55.0 to 5.56.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.56.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:03:44 +00:00
dependabot[bot]
2a3abf56ec build(deps-dev): bump eslint-plugin-github from 4.6.1 to 4.7.0 (#137)
Bumps [eslint-plugin-github](https://github.com/github/eslint-plugin-github) from 4.6.1 to 4.7.0.
- [Release notes](https://github.com/github/eslint-plugin-github/releases)
- [Commits](https://github.com/github/eslint-plugin-github/compare/v4.6.1...v4.7.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-github
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:01:30 +00:00
dependabot[bot]
9e64bda1bc build(deps-dev): bump @types/node from 16.18.16 to 16.18.21 (#136)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.16 to 16.18.21.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:00:56 +00:00
dependabot[bot]
dd732b0272 build(deps-dev): bump prettier from 2.8.4 to 2.8.7 (#135)
Bumps [prettier](https://github.com/prettier/prettier) from 2.8.4 to 2.8.7.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.8.4...2.8.7)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 15:00:32 +00:00
dependabot[bot]
24d9720e95 build(deps): bump peter-evans/enable-pull-request-automerge from 2 to 3 (#134)
Bumps [peter-evans/enable-pull-request-automerge](https://github.com/peter-evans/enable-pull-request-automerge) from 2 to 3.
- [Release notes](https://github.com/peter-evans/enable-pull-request-automerge/releases)
- [Commits](https://github.com/peter-evans/enable-pull-request-automerge/compare/v2...v3)

---
updated-dependencies:
- dependency-name: peter-evans/enable-pull-request-automerge
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-26 14:59:44 +00:00
dependabot[bot]
74d5634479 build(deps-dev): bump @types/node from 16.18.14 to 16.18.16 (#133)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.14 to 16.18.16.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-19 15:04:03 +00:00
dependabot[bot]
f92370924c build(deps-dev): bump @typescript-eslint/parser from 5.54.1 to 5.55.0 (#132)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.54.1 to 5.55.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.55.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-19 15:00:54 +00:00
dependabot[bot]
32a61cce5a build(deps-dev): bump eslint from 8.35.0 to 8.36.0 (#131)
Bumps [eslint](https://github.com/eslint/eslint) from 8.35.0 to 8.36.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.35.0...v8.36.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-12 14:58:50 +00:00
dependabot[bot]
4a4792c2ca build(deps-dev): bump @typescript-eslint/parser from 5.54.0 to 5.54.1 (#130)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.54.0 to 5.54.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.54.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-12 14:58:34 +00:00
Peter Evans
202973a37c feat: truncate content exceeding the byte limit (#129)
Some checks failed
Publish Docker Image / publish (push) Has been cancelled
2023-03-06 12:50:56 +09:00
dependabot[bot]
728b36f7bb build(deps-dev): bump @typescript-eslint/parser from 5.53.0 to 5.54.0 (#128)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 5.53.0 to 5.54.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.54.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-05 15:00:46 +00:00
dependabot[bot]
3f60feb215 build(deps-dev): bump @types/node from 16.18.12 to 16.18.14 (#127)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.18.12 to 16.18.14.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-05 14:58:53 +00:00
Peter Evans
812a4d0496 ci: add workflow to update major version 2023-03-05 11:28:32 +09:00
11 changed files with 287 additions and 5196 deletions

View File

@@ -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 }}

View File

@@ -0,0 +1,31 @@
name: Update Major Version
run-name: Update ${{ github.event.inputs.main_version }} to ${{ github.event.inputs.target }}
on:
workflow_dispatch:
inputs:
target:
description: The target tag or reference
required: true
main_version:
type: choice
description: The major version tag to update
options:
- v3
jobs:
tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
fetch-depth: 0
- name: Git config
run: |
git config user.name actions-bot
git config user.email actions-bot@users.noreply.github.com
- name: Tag new target
run: git tag -f ${{ github.event.inputs.main_version }} ${{ github.event.inputs.target }}
- name: Push new tag
run: git push origin ${{ github.event.inputs.main_version }} --force

View File

@@ -30,8 +30,10 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
#### Content limits
DockerHub has content limits, which if exceeded will result in the content being automatically truncated.
DockerHub has content limits.
The readme content is limited to 25,000 bytes, and `short-description` is limited to 100 characters.
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.
#### Specifying the file path

View 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('😀😁')
})
})

109
dist/index.js vendored
View File

@@ -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,6 +250,11 @@ 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.`);
}
// Acquire a token for the Docker Hub API
core.info('Acquiring token');
const token = yield dockerhubHelper.getToken(inputs.username, inputs.password);
@@ -264,7 +265,7 @@ function run() {
}
catch (error) {
core.debug((0, util_1.inspect)(error));
core.setFailed(getErrorMessage(error));
core.setFailed(utils.getErrorMessage(error));
}
});
}
@@ -314,6 +315,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
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 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;
@@ -321,6 +323,7 @@ const TITLE_REGEX = `(?: +"[^"]+")?`;
const REPOSITORY_URL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHUB_REPOSITORY']}`;
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 getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions) {
return __awaiter(this, void 0, void 0, function* () {
// Fetch the readme content
@@ -328,7 +331,11 @@ function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions)
encoding: 'utf8'
});
readmeContent = completeRelativeUrls(readmeContent, readmeFilepath, enableUrlCompletion, imageExtensions);
return readmeContent;
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.`);
}
return truncatedReadmeContent;
});
}
exports.getReadmeContent = getReadmeContent;
@@ -432,6 +439,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:
@@ -6430,6 +6463,64 @@ if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) {
exports.debug = debug; // for test
/***/ }),
/***/ 6986:
/***/ ((module) => {
"use strict";
function charAt(string, index) {
var first = string.charCodeAt(index);
var second;
if (first >= 55296 && first <= 56319 && string.length > index + 1) {
second = string.charCodeAt(index + 1);
if (second >= 56320 && second <= 57343) {
return string.substring(index, index + 2);
}
}
return string[index];
}
function slice(string, start, end) {
var accumulator = "";
var character;
var stringIndex = 0;
var unicodeIndex = 0;
var length = string.length;
while (stringIndex < length) {
character = charAt(string, stringIndex);
if (unicodeIndex >= start && unicodeIndex < end) {
accumulator += character;
}
stringIndex += character.length;
unicodeIndex += 1;
}
return accumulator;
}
function toNumber(value, fallback) {
if (value === undefined) {
return fallback;
} else {
return Number(value);
}
}
module.exports = function (string, start, end) {
var realStart = toNumber(start, 0);
var realEnd = toNumber(end, string.length);
if (realEnd == realStart) {
return "";
} else if (realEnd > realStart) {
return slice(string, realStart, realEnd);
} else {
return slice(string, realEnd, realStart);
}
};
/***/ }),
/***/ 5840:

5265
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -28,20 +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.9",
"unicode-substring": "^0.1.0"
},
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.18.12",
"@typescript-eslint/parser": "^5.53.0",
"@types/node": "^16.18.23",
"@typescript-eslint/parser": "^5.57.0",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.35.0",
"eslint-plugin-github": "^4.6.1",
"eslint": "^8.37.0",
"eslint-plugin-github": "^4.7.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.7",
"ts-jest": "^27.1.5",
"typescript": "^4.9.5"
}

View File

@@ -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',

View File

@@ -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,17 @@ 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.`
)
}
// Acquire a token for the Docker Hub API
core.info('Acquiring token')
const token = await dockerhubHelper.getToken(
@@ -42,7 +51,7 @@ async function run(): Promise<void> {
core.info('Request successful')
} catch (error) {
core.debug(inspect(error))
core.setFailed(getErrorMessage(error))
core.setFailed(utils.getErrorMessage(error))
}
}

View File

@@ -1,5 +1,6 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import * as utils from './utils'
export const README_FILEPATH_DEFAULT = './README.md'
export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'
@@ -10,6 +11,8 @@ 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
type Rule = {
/**
* all left of the relative url belonging to the markdown image/link
@@ -42,7 +45,14 @@ export async function getReadmeContent(
imageExtensions
)
return readmeContent
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.`
)
}
return truncatedReadmeContent
}
export function completeRelativeUrls(

14
src/utils.ts Normal file
View 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
}