Compare commits
114 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e98e4d1628 | ||
|
|
487b4536f5 | ||
|
|
f4367f9cb8 | ||
|
|
48ae68f5cc | ||
|
|
dfc61b859a | ||
|
|
74967fba19 | ||
|
|
7ea9d275c7 | ||
|
|
7bc76ab4eb | ||
|
|
5a219e72c3 | ||
|
|
fb37f44de8 | ||
|
|
090662666b | ||
|
|
7d9d33d1ad | ||
|
|
ede0e66c26 | ||
|
|
2eb6c2156a | ||
|
|
d749f34910 | ||
|
|
cbbf63cd44 | ||
|
|
c493b0c24f | ||
|
|
aef47f645f | ||
|
|
17e01bee3e | ||
|
|
5862ccd54c | ||
|
|
2d9834711c | ||
|
|
da6824c6fa | ||
|
|
447f37b1fb | ||
|
|
c3746eb94a | ||
|
|
3ed1138da6 | ||
|
|
12031e44df | ||
|
|
c14f7ff9e9 | ||
|
|
057ee23e8c | ||
|
|
312671fa99 | ||
|
|
8f8b8c99b1 | ||
|
|
5ad1124f4f | ||
|
|
9453e52a44 | ||
|
|
a99d66e8ec | ||
|
|
5c90d1ad12 | ||
|
|
dcf0a8fff6 | ||
|
|
73a580a1ae | ||
|
|
b1e39fd19f | ||
|
|
39bf3f4c11 | ||
|
|
62ba2ea0d3 | ||
|
|
3861b4b5c8 | ||
|
|
fbf02e87a8 | ||
|
|
ae2ba76d87 | ||
|
|
66dd6ac11f | ||
|
|
ce7ff9a828 | ||
|
|
15a517c06a | ||
|
|
7e13e37804 | ||
|
|
28ce628a86 | ||
|
|
52be71e834 | ||
|
|
85196c34e2 | ||
|
|
a7d6e3d9c6 | ||
|
|
c8ed26e537 | ||
|
|
6515ba32ab | ||
|
|
fd35f43fb8 | ||
|
|
6b24b4e0ae | ||
|
|
1156718ef8 | ||
|
|
14b47e3ff1 | ||
|
|
c3e7977d85 | ||
|
|
e02df362e0 | ||
|
|
3812f14543 | ||
|
|
2c2024be8b | ||
|
|
de56f90828 | ||
|
|
05b1c514cd | ||
|
|
1f52e08716 | ||
|
|
b8a53936ac | ||
|
|
a39ad46df2 | ||
|
|
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 | ||
|
|
202973a37c | ||
|
|
728b36f7bb | ||
|
|
3f60feb215 | ||
|
|
812a4d0496 |
2
.github/workflows/automerge-dependabot.yml
vendored
2
.github/workflows/automerge-dependabot.yml
vendored
@@ -6,7 +6,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.actor == 'dependabot[bot]'
|
if: github.actor == 'dependabot[bot]'
|
||||||
steps:
|
steps:
|
||||||
- uses: peter-evans/enable-pull-request-automerge@v2
|
- uses: peter-evans/enable-pull-request-automerge@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
pull-request-number: ${{ github.event.pull_request.number }}
|
pull-request-number: ${{ github.event.pull_request.number }}
|
||||||
|
|||||||
22
.github/workflows/ci.yml
vendored
22
.github/workflows/ci.yml
vendored
@@ -19,21 +19,21 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 20.x
|
||||||
cache: npm
|
cache: npm
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm run format-check
|
- run: npm run format-check
|
||||||
- run: npm run lint
|
- run: npm run lint
|
||||||
- run: npm run test
|
- run: npm run test
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
path: dist
|
path: dist
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: action.yml
|
name: action.yml
|
||||||
path: action.yml
|
path: action.yml
|
||||||
@@ -46,14 +46,14 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
target: [built, committed]
|
target: [built, committed]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
path: dist
|
path: dist
|
||||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||||
uses: actions/download-artifact@v3
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: action.yml
|
name: action.yml
|
||||||
path: .
|
path: .
|
||||||
@@ -86,13 +86,13 @@ jobs:
|
|||||||
needs: [test]
|
needs: [test]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/download-artifact@v3
|
- uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
path: dist
|
path: dist
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v4
|
uses: peter-evans/create-pull-request@v5
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
commit-message: 'build: update distribution'
|
commit-message: 'build: update distribution'
|
||||||
|
|||||||
2
.github/workflows/dockerhub-description.yml
vendored
2
.github/workflows/dockerhub-description.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
|||||||
dockerHubDescription:
|
dockerHubDescription:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Modify readme for DockerHub
|
- name: Modify readme for DockerHub
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
2
.github/workflows/publish-docker.yml
vendored
2
.github/workflows/publish-docker.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
|||||||
publish:
|
publish:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Docker Hub login
|
- name: Docker Hub login
|
||||||
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
|
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
|
||||||
|
|||||||
31
.github/workflows/update-major-version.yml
vendored
Normal file
31
.github/workflows/update-major-version.yml
vendored
Normal 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:
|
||||||
|
- v4
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tag:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
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
|
||||||
22
README.md
22
README.md
@@ -8,8 +8,10 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Docker Hub Description
|
- name: Docker Hub Description
|
||||||
uses: peter-evans/dockerhub-description@v3
|
uses: peter-evans/dockerhub-description@v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
@@ -30,8 +32,10 @@ This is useful if you `docker push` your images to Docker Hub. It provides an ea
|
|||||||
|
|
||||||
#### Content limits
|
#### 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.
|
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.
|
||||||
|
|
||||||
#### Specifying the file path
|
#### Specifying the file path
|
||||||
|
|
||||||
@@ -40,7 +44,7 @@ If this is not the case the path can be specified with the `readme-filepath` inp
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Docker Hub Description
|
- name: Docker Hub Description
|
||||||
uses: peter-evans/dockerhub-description@v3
|
uses: peter-evans/dockerhub-description@v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
@@ -54,7 +58,7 @@ The GitHub repository description can be used for the Docker Hub `short-descript
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Docker Hub Description
|
- name: Docker Hub Description
|
||||||
uses: peter-evans/dockerhub-description@v3
|
uses: peter-evans/dockerhub-description@v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
@@ -79,10 +83,10 @@ jobs:
|
|||||||
dockerHubDescription:
|
dockerHubDescription:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Docker Hub Description
|
- name: Docker Hub Description
|
||||||
uses: peter-evans/dockerhub-description@v3
|
uses: peter-evans/dockerhub-description@v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
@@ -100,10 +104,10 @@ jobs:
|
|||||||
dockerHubDescription:
|
dockerHubDescription:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Docker Hub Description
|
- name: Docker Hub Description
|
||||||
uses: peter-evans/dockerhub-description@v3
|
uses: peter-evans/dockerhub-description@v4
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||||
|
|||||||
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('😀😁')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -27,7 +27,7 @@ inputs:
|
|||||||
File extensions that will be treated as images
|
File extensions that will be treated as images
|
||||||
Default: `bmp,gif,jpg,jpeg,png,svg,webp`
|
Default: `bmp,gif,jpg,jpeg,png,svg,webp`
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
branding:
|
branding:
|
||||||
icon: 'upload'
|
icon: 'upload'
|
||||||
|
|||||||
124
dist/index.js
vendored
124
dist/index.js
vendored
@@ -42,7 +42,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.updateRepositoryDescription = exports.getToken = void 0;
|
exports.updateRepositoryDescription = exports.getToken = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2186));
|
const core = __importStar(__nccwpck_require__(2186));
|
||||||
const fetch = __importStar(__nccwpck_require__(467));
|
const fetch = __importStar(__nccwpck_require__(467));
|
||||||
const DESCRIPTION_MAX_CHARS = 100;
|
|
||||||
function getToken(username, password) {
|
function getToken(username, password) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const body = {
|
const body = {
|
||||||
@@ -69,7 +68,7 @@ function updateRepositoryDescription(token, repository, description, fullDescrip
|
|||||||
full_description: fullDescription
|
full_description: fullDescription
|
||||||
};
|
};
|
||||||
if (description) {
|
if (description) {
|
||||||
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS);
|
body['description'] = description;
|
||||||
}
|
}
|
||||||
yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
yield fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||||
method: 'patch',
|
method: 'patch',
|
||||||
@@ -238,12 +237,9 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||||||
const inputHelper = __importStar(__nccwpck_require__(5480));
|
const inputHelper = __importStar(__nccwpck_require__(5480));
|
||||||
const dockerhubHelper = __importStar(__nccwpck_require__(1812));
|
const dockerhubHelper = __importStar(__nccwpck_require__(1812));
|
||||||
const readmeHelper = __importStar(__nccwpck_require__(3367));
|
const readmeHelper = __importStar(__nccwpck_require__(3367));
|
||||||
|
const utils = __importStar(__nccwpck_require__(918));
|
||||||
const util_1 = __nccwpck_require__(3837);
|
const util_1 = __nccwpck_require__(3837);
|
||||||
function getErrorMessage(error) {
|
const SHORT_DESCRIPTION_MAX_BYTES = 100;
|
||||||
if (error instanceof Error)
|
|
||||||
return error.message;
|
|
||||||
return String(error);
|
|
||||||
}
|
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
@@ -254,17 +250,23 @@ function run() {
|
|||||||
core.info('Reading description source file');
|
core.info('Reading description source file');
|
||||||
const readmeContent = yield readmeHelper.getReadmeContent(inputs.readmeFilepath, inputs.enableUrlCompletion, inputs.imageExtensions);
|
const readmeContent = yield readmeHelper.getReadmeContent(inputs.readmeFilepath, inputs.enableUrlCompletion, inputs.imageExtensions);
|
||||||
core.debug(readmeContent);
|
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
|
// Acquire a token for the Docker Hub API
|
||||||
core.info('Acquiring token');
|
core.info('Acquiring token');
|
||||||
const token = yield dockerhubHelper.getToken(inputs.username, inputs.password);
|
const token = yield dockerhubHelper.getToken(inputs.username, inputs.password);
|
||||||
// Send a PATCH request to update the description of the repository
|
// Send a PATCH request to update the description of the repository
|
||||||
core.info('Sending PATCH request');
|
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');
|
core.info('Request successful');
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.debug((0, util_1.inspect)(error));
|
core.debug((0, util_1.inspect)(error));
|
||||||
core.setFailed(getErrorMessage(error));
|
core.setFailed(utils.getErrorMessage(error));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -314,6 +316,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;
|
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 core = __importStar(__nccwpck_require__(2186));
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
|
const utils = __importStar(__nccwpck_require__(918));
|
||||||
exports.README_FILEPATH_DEFAULT = './README.md';
|
exports.README_FILEPATH_DEFAULT = './README.md';
|
||||||
exports.IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp';
|
exports.IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp';
|
||||||
exports.ENABLE_URL_COMPLETION_DEFAULT = false;
|
exports.ENABLE_URL_COMPLETION_DEFAULT = false;
|
||||||
@@ -321,6 +324,7 @@ const TITLE_REGEX = `(?: +"[^"]+")?`;
|
|||||||
const REPOSITORY_URL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHUB_REPOSITORY']}`;
|
const REPOSITORY_URL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHUB_REPOSITORY']}`;
|
||||||
const BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`;
|
const BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`;
|
||||||
const RAW_PREFIX = `${REPOSITORY_URL}/raw/${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) {
|
function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Fetch the readme content
|
// Fetch the readme content
|
||||||
@@ -328,7 +332,11 @@ function getReadmeContent(readmeFilepath, enableUrlCompletion, imageExtensions)
|
|||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
});
|
});
|
||||||
readmeContent = completeRelativeUrls(readmeContent, readmeFilepath, enableUrlCompletion, imageExtensions);
|
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;
|
exports.getReadmeContent = getReadmeContent;
|
||||||
@@ -432,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:
|
/***/ 7351:
|
||||||
@@ -991,7 +1025,7 @@ class OidcClient {
|
|||||||
.catch(error => {
|
.catch(error => {
|
||||||
throw new Error(`Failed to get ID Token. \n
|
throw new Error(`Failed to get ID Token. \n
|
||||||
Error Code : ${error.statusCode}\n
|
Error Code : ${error.statusCode}\n
|
||||||
Error Message: ${error.result.message}`);
|
Error Message: ${error.message}`);
|
||||||
});
|
});
|
||||||
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
|
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
|
||||||
if (!id_token) {
|
if (!id_token) {
|
||||||
@@ -3566,10 +3600,6 @@ function getNodeRequestOptions(request) {
|
|||||||
agent = agent(parsedURL);
|
agent = agent(parsedURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!headers.has('Connection') && !agent) {
|
|
||||||
headers.set('Connection', 'close');
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTP-network fetch step 4.2
|
// HTTP-network fetch step 4.2
|
||||||
// chunked encoding is handled by Node.js
|
// chunked encoding is handled by Node.js
|
||||||
|
|
||||||
@@ -3943,8 +3973,11 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
|
|||||||
|
|
||||||
if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) {
|
if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) {
|
||||||
response.once('close', function (hadError) {
|
response.once('close', function (hadError) {
|
||||||
|
// tests for socket presence, as in some situations the
|
||||||
|
// the 'socket' event is not triggered for the request
|
||||||
|
// (happens in deno), avoids `TypeError`
|
||||||
// if a data listener is still present we didn't end cleanly
|
// if a data listener is still present we didn't end cleanly
|
||||||
const hasDataListener = socket.listenerCount('data') > 0;
|
const hasDataListener = socket && socket.listenerCount('data') > 0;
|
||||||
|
|
||||||
if (hasDataListener && !hadError) {
|
if (hasDataListener && !hadError) {
|
||||||
const err = new Error('Premature close');
|
const err = new Error('Premature close');
|
||||||
@@ -3986,6 +4019,7 @@ exports.Headers = Headers;
|
|||||||
exports.Request = Request;
|
exports.Request = Request;
|
||||||
exports.Response = Response;
|
exports.Response = Response;
|
||||||
exports.FetchError = FetchError;
|
exports.FetchError = FetchError;
|
||||||
|
exports.AbortError = AbortError;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -6430,6 +6464,64 @@ if (process.env.NODE_DEBUG && /\btunnel\b/.test(process.env.NODE_DEBUG)) {
|
|||||||
exports.debug = debug; // for test
|
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:
|
/***/ 5840:
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#!/bin/sh -l
|
#!/bin/sh -l
|
||||||
set -eo pipefail
|
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
# Execute the action code and output to file
|
# 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
|
# Remove lines containing sensitive information from the log
|
||||||
sed -i '/::debug::/d' ./action.log
|
sed -i '/::debug::/d' ./action.log
|
||||||
@@ -11,3 +11,6 @@ sed -i '/::add-mask::/d' ./action.log
|
|||||||
|
|
||||||
# Output the log
|
# Output the log
|
||||||
cat action.log
|
cat action.log
|
||||||
|
|
||||||
|
# Exit using the exit code of the node command
|
||||||
|
exit $exit_code
|
||||||
|
|||||||
6459
package-lock.json
generated
6459
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dockerhub-description",
|
"name": "dockerhub-description",
|
||||||
"version": "3.0.0",
|
"version": "4.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "An action to update a Docker Hub repository description from README.md",
|
"description": "An action to update a Docker Hub repository description from README.md",
|
||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
@@ -27,21 +27,23 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/peter-evans/dockerhub-description#readme",
|
"homepage": "https://github.com/peter-evans/dockerhub-description#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.1",
|
||||||
"node-fetch": "^2.6.9"
|
"node-fetch": "^2.7.0",
|
||||||
|
"unicode-substring": "^0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.3",
|
"@types/jest": "^27.0.3",
|
||||||
"@types/node": "^16.18.12",
|
"@types/node": "^16.18.73",
|
||||||
"@typescript-eslint/parser": "^5.53.0",
|
"@typescript-eslint/parser": "^5.62.0",
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"eslint": "^8.35.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-plugin-github": "^4.6.1",
|
"eslint-plugin-github": "^4.10.1",
|
||||||
"eslint-plugin-jest": "^25.7.0",
|
"eslint-plugin-jest": "^25.7.0",
|
||||||
|
"eslint-plugin-prettier": "^5.1.3",
|
||||||
"jest": "^27.5.1",
|
"jest": "^27.5.1",
|
||||||
"jest-circus": "^27.5.1",
|
"jest-circus": "^27.5.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^3.2.4",
|
||||||
"ts-jest": "^27.1.5",
|
"ts-jest": "^27.1.5",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as fetch from 'node-fetch'
|
import * as fetch from 'node-fetch'
|
||||||
|
|
||||||
const DESCRIPTION_MAX_CHARS = 100
|
|
||||||
|
|
||||||
export async function getToken(
|
export async function getToken(
|
||||||
username: string,
|
username: string,
|
||||||
password: string
|
password: string
|
||||||
@@ -36,7 +34,7 @@ export async function updateRepositoryDescription(
|
|||||||
full_description: fullDescription
|
full_description: fullDescription
|
||||||
}
|
}
|
||||||
if (description) {
|
if (description) {
|
||||||
body['description'] = description.slice(0, DESCRIPTION_MAX_CHARS)
|
body['description'] = description
|
||||||
}
|
}
|
||||||
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||||
method: 'patch',
|
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 inputHelper from './input-helper'
|
||||||
import * as dockerhubHelper from './dockerhub-helper'
|
import * as dockerhubHelper from './dockerhub-helper'
|
||||||
import * as readmeHelper from './readme-helper'
|
import * as readmeHelper from './readme-helper'
|
||||||
|
import * as utils from './utils'
|
||||||
import {inspect} from 'util'
|
import {inspect} from 'util'
|
||||||
|
|
||||||
function getErrorMessage(error: unknown) {
|
const SHORT_DESCRIPTION_MAX_BYTES = 100
|
||||||
if (error instanceof Error) return error.message
|
|
||||||
return String(error)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -25,6 +23,18 @@ async function run(): Promise<void> {
|
|||||||
)
|
)
|
||||||
core.debug(readmeContent)
|
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
|
// Acquire a token for the Docker Hub API
|
||||||
core.info('Acquiring token')
|
core.info('Acquiring token')
|
||||||
const token = await dockerhubHelper.getToken(
|
const token = await dockerhubHelper.getToken(
|
||||||
@@ -36,13 +46,13 @@ async function run(): Promise<void> {
|
|||||||
await dockerhubHelper.updateRepositoryDescription(
|
await dockerhubHelper.updateRepositoryDescription(
|
||||||
token,
|
token,
|
||||||
inputs.repository,
|
inputs.repository,
|
||||||
inputs.shortDescription,
|
truncatedShortDescription,
|
||||||
readmeContent
|
readmeContent
|
||||||
)
|
)
|
||||||
core.info('Request successful')
|
core.info('Request successful')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.debug(inspect(error))
|
core.debug(inspect(error))
|
||||||
core.setFailed(getErrorMessage(error))
|
core.setFailed(utils.getErrorMessage(error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
import * as utils from './utils'
|
||||||
|
|
||||||
export const README_FILEPATH_DEFAULT = './README.md'
|
export const README_FILEPATH_DEFAULT = './README.md'
|
||||||
export const IMAGE_EXTENSIONS_DEFAULT = 'bmp,gif,jpg,jpeg,png,svg,webp'
|
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 BLOB_PREFIX = `${REPOSITORY_URL}/blob/${process.env['GITHUB_REF_NAME']}/`
|
||||||
const RAW_PREFIX = `${REPOSITORY_URL}/raw/${process.env['GITHUB_REF_NAME']}/`
|
const RAW_PREFIX = `${REPOSITORY_URL}/raw/${process.env['GITHUB_REF_NAME']}/`
|
||||||
|
|
||||||
|
const MAX_BYTES = 25000
|
||||||
|
|
||||||
type Rule = {
|
type Rule = {
|
||||||
/**
|
/**
|
||||||
* all left of the relative url belonging to the markdown image/link
|
* all left of the relative url belonging to the markdown image/link
|
||||||
@@ -42,7 +45,14 @@ export async function getReadmeContent(
|
|||||||
imageExtensions
|
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(
|
export function completeRelativeUrls(
|
||||||
|
|||||||
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