mirror of https://github.com/actions/checkout
Compare commits
4 Commits
4b1024a61c
...
3a5e6550b9
| Author | SHA1 | Date |
|---|---|---|
|
|
3a5e6550b9 | |
|
|
e8d4307400 | |
|
|
631c942040 | |
|
|
fcdb15c322 |
|
|
@ -1,3 +0,0 @@
|
||||||
dist/
|
|
||||||
lib/
|
|
||||||
node_modules/
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
{
|
|
||||||
"plugins": ["jest", "@typescript-eslint"],
|
|
||||||
"extends": ["plugin:github/recommended"],
|
|
||||||
"parser": "@typescript-eslint/parser",
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": 9,
|
|
||||||
"sourceType": "module",
|
|
||||||
"project": "./tsconfig.json"
|
|
||||||
},
|
|
||||||
"rules": {
|
|
||||||
"eslint-comments/no-use": "off",
|
|
||||||
"import/no-namespace": "off",
|
|
||||||
"no-unused-vars": "off",
|
|
||||||
"@typescript-eslint/no-unused-vars": "error",
|
|
||||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
|
||||||
"@typescript-eslint/no-require-imports": "error",
|
|
||||||
"@typescript-eslint/array-type": "error",
|
|
||||||
"@typescript-eslint/await-thenable": "error",
|
|
||||||
"camelcase": "off",
|
|
||||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
|
||||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
|
||||||
"@typescript-eslint/no-array-constructor": "error",
|
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
|
||||||
"@typescript-eslint/no-explicit-any": "error",
|
|
||||||
"@typescript-eslint/no-extraneous-class": "error",
|
|
||||||
"@typescript-eslint/no-floating-promises": "error",
|
|
||||||
"@typescript-eslint/no-for-in-array": "error",
|
|
||||||
"@typescript-eslint/no-inferrable-types": "error",
|
|
||||||
"@typescript-eslint/no-misused-new": "error",
|
|
||||||
"@typescript-eslint/no-namespace": "error",
|
|
||||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
|
||||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
|
||||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
|
||||||
"@typescript-eslint/no-useless-constructor": "error",
|
|
||||||
"@typescript-eslint/no-var-requires": "error",
|
|
||||||
"@typescript-eslint/prefer-for-of": "warn",
|
|
||||||
"@typescript-eslint/prefer-function-type": "warn",
|
|
||||||
"@typescript-eslint/prefer-includes": "error",
|
|
||||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
|
||||||
"@typescript-eslint/promise-function-async": "error",
|
|
||||||
"@typescript-eslint/require-array-sort-compare": "error",
|
|
||||||
"@typescript-eslint/restrict-plus-operands": "error",
|
|
||||||
"semi": "off",
|
|
||||||
"@typescript-eslint/semi": ["error", "never"],
|
|
||||||
"@typescript-eslint/type-annotation-spacing": "error",
|
|
||||||
"@typescript-eslint/unbound-method": "error"
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"node": true,
|
|
||||||
"es6": true,
|
|
||||||
"jest/globals": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -31,7 +31,7 @@ jobs:
|
||||||
# Use `docker/login-action` to log in to GHCR.io.
|
# Use `docker/login-action` to log in to GHCR.io.
|
||||||
# Once published, the packages are scoped to the account defined here.
|
# Once published, the packages are scoped to the account defined here.
|
||||||
- name: Log in to the ghcr.io container registry
|
- name: Log in to the ghcr.io container registry
|
||||||
uses: docker/login-action@v4.2.0
|
uses: docker/login-action@v4.4.0
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
|
|
@ -48,7 +48,7 @@ jobs:
|
||||||
|
|
||||||
# Use `docker/build-push-action` to build (and optionally publish) the image.
|
# Use `docker/build-push-action` to build (and optionally publish) the image.
|
||||||
- name: Build Docker Image (with optional Push)
|
- name: Build Docker Image (with optional Push)
|
||||||
uses: docker/build-push-action@v7.2.0
|
uses: docker/build-push-action@v7.3.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: images/test-ubuntu-git.Dockerfile
|
file: images/test-ubuntu-git.Dockerfile
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,9 @@ jest.unstable_mockModule('@actions/core', () => ({
|
||||||
// Dynamic imports after mocking
|
// Dynamic imports after mocking
|
||||||
const {RetryHelper} = await import('../src/retry-helper.js')
|
const {RetryHelper} = await import('../src/retry-helper.js')
|
||||||
|
|
||||||
let retryHelper: any
|
|
||||||
|
|
||||||
describe('retry-helper tests', () => {
|
describe('retry-helper tests', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
retryHelper = new RetryHelper(3, 0, 0)
|
// @actions/core is mocked at module load above; nothing to set up here.
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
@ -40,14 +38,22 @@ describe('retry-helper tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('first attempt succeeds', async () => {
|
it('first attempt succeeds', async () => {
|
||||||
|
const retryHelper: any = new RetryHelper(3, 1, 10)
|
||||||
|
const sleep = jest.fn().mockResolvedValue(undefined)
|
||||||
|
retryHelper.sleep = sleep
|
||||||
|
|
||||||
const actual = await retryHelper.execute(async () => {
|
const actual = await retryHelper.execute(async () => {
|
||||||
return 'some result'
|
return 'some result'
|
||||||
})
|
})
|
||||||
expect(actual).toBe('some result')
|
expect(actual).toBe('some result')
|
||||||
expect(info).toHaveLength(0)
|
expect(info).toHaveLength(0)
|
||||||
|
expect(sleep).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('second attempt succeeds', async () => {
|
it('second attempt succeeds', async () => {
|
||||||
|
const retryHelper: any = new RetryHelper(3, 1, 10)
|
||||||
|
const sleep = jest.fn().mockResolvedValue(undefined)
|
||||||
|
retryHelper.sleep = sleep
|
||||||
let attempts = 0
|
let attempts = 0
|
||||||
const actual = await retryHelper.execute(() => {
|
const actual = await retryHelper.execute(() => {
|
||||||
if (++attempts == 1) {
|
if (++attempts == 1) {
|
||||||
|
|
@ -60,10 +66,15 @@ describe('retry-helper tests', () => {
|
||||||
expect(actual).toBe('some result')
|
expect(actual).toBe('some result')
|
||||||
expect(info).toHaveLength(2)
|
expect(info).toHaveLength(2)
|
||||||
expect(info[0]).toBe('some error')
|
expect(info[0]).toBe('some error')
|
||||||
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
|
expect(info[1]).toBe('Waiting 1 seconds before trying again')
|
||||||
|
expect(sleep).toHaveBeenCalledTimes(1)
|
||||||
|
expect(sleep).toHaveBeenCalledWith(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('third attempt succeeds', async () => {
|
it('third attempt succeeds', async () => {
|
||||||
|
const retryHelper: any = new RetryHelper(3, 1, 10)
|
||||||
|
const sleep = jest.fn().mockResolvedValue(undefined)
|
||||||
|
retryHelper.sleep = sleep
|
||||||
let attempts = 0
|
let attempts = 0
|
||||||
const actual = await retryHelper.execute(() => {
|
const actual = await retryHelper.execute(() => {
|
||||||
if (++attempts < 3) {
|
if (++attempts < 3) {
|
||||||
|
|
@ -76,12 +87,18 @@ describe('retry-helper tests', () => {
|
||||||
expect(actual).toBe('some result')
|
expect(actual).toBe('some result')
|
||||||
expect(info).toHaveLength(4)
|
expect(info).toHaveLength(4)
|
||||||
expect(info[0]).toBe('some error 1')
|
expect(info[0]).toBe('some error 1')
|
||||||
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
|
expect(info[1]).toBe('Waiting 1 seconds before trying again')
|
||||||
expect(info[2]).toBe('some error 2')
|
expect(info[2]).toBe('some error 2')
|
||||||
expect(info[3]).toMatch(/Waiting .+ seconds before trying again/)
|
expect(info[3]).toBe('Waiting 2 seconds before trying again')
|
||||||
|
expect(sleep).toHaveBeenCalledTimes(2)
|
||||||
|
expect(sleep).toHaveBeenNthCalledWith(1, 1)
|
||||||
|
expect(sleep).toHaveBeenNthCalledWith(2, 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('all attempts fail succeeds', async () => {
|
it('all attempts fail succeeds', async () => {
|
||||||
|
const retryHelper: any = new RetryHelper(3, 1, 10)
|
||||||
|
const sleep = jest.fn().mockResolvedValue(undefined)
|
||||||
|
retryHelper.sleep = sleep
|
||||||
let attempts = 0
|
let attempts = 0
|
||||||
let error: Error = null as unknown as Error
|
let error: Error = null as unknown as Error
|
||||||
try {
|
try {
|
||||||
|
|
@ -95,8 +112,42 @@ describe('retry-helper tests', () => {
|
||||||
expect(attempts).toBe(3)
|
expect(attempts).toBe(3)
|
||||||
expect(info).toHaveLength(4)
|
expect(info).toHaveLength(4)
|
||||||
expect(info[0]).toBe('some error 1')
|
expect(info[0]).toBe('some error 1')
|
||||||
expect(info[1]).toMatch(/Waiting .+ seconds before trying again/)
|
expect(info[1]).toBe('Waiting 1 seconds before trying again')
|
||||||
expect(info[2]).toBe('some error 2')
|
expect(info[2]).toBe('some error 2')
|
||||||
expect(info[3]).toMatch(/Waiting .+ seconds before trying again/)
|
expect(info[3]).toBe('Waiting 2 seconds before trying again')
|
||||||
|
expect(sleep).toHaveBeenCalledTimes(2)
|
||||||
|
expect(sleep).toHaveBeenNthCalledWith(1, 1)
|
||||||
|
expect(sleep).toHaveBeenNthCalledWith(2, 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('server-side 500 errors are retried with exponential backoff', async () => {
|
||||||
|
const retryHelper: any = new RetryHelper(4, 2, 10)
|
||||||
|
const sleep = jest.fn().mockResolvedValue(undefined)
|
||||||
|
retryHelper.sleep = sleep
|
||||||
|
let attempts = 0
|
||||||
|
|
||||||
|
const actual = await retryHelper.execute(() => {
|
||||||
|
if (++attempts < 3) {
|
||||||
|
const error: Error & {status?: number} = new Error(
|
||||||
|
`server error ${attempts}`
|
||||||
|
)
|
||||||
|
error.status = 500
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve('some result')
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(actual).toBe('some result')
|
||||||
|
expect(attempts).toBe(3)
|
||||||
|
expect(info).toEqual([
|
||||||
|
'server error 1',
|
||||||
|
'Waiting 2 seconds before trying again',
|
||||||
|
'server error 2',
|
||||||
|
'Waiting 4 seconds before trying again'
|
||||||
|
])
|
||||||
|
expect(sleep).toHaveBeenCalledTimes(2)
|
||||||
|
expect(sleep).toHaveBeenNthCalledWith(1, 2)
|
||||||
|
expect(sleep).toHaveBeenNthCalledWith(2, 4)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -35491,7 +35491,7 @@ class retry_helper_RetryHelper {
|
||||||
info(err?.message);
|
info(err?.message);
|
||||||
}
|
}
|
||||||
// Sleep
|
// Sleep
|
||||||
const seconds = this.getSleepAmount();
|
const seconds = this.getSleepAmount(attempt);
|
||||||
info(`Waiting ${seconds} seconds before trying again`);
|
info(`Waiting ${seconds} seconds before trying again`);
|
||||||
await this.sleep(seconds);
|
await this.sleep(seconds);
|
||||||
attempt++;
|
attempt++;
|
||||||
|
|
@ -35499,9 +35499,11 @@ class retry_helper_RetryHelper {
|
||||||
// Last attempt
|
// Last attempt
|
||||||
return await action();
|
return await action();
|
||||||
}
|
}
|
||||||
getSleepAmount() {
|
getSleepAmount(attempt) {
|
||||||
return (Math.floor(Math.random() * (this.maxSeconds - this.minSeconds + 1)) +
|
if (this.minSeconds === 0) {
|
||||||
this.minSeconds);
|
return 0;
|
||||||
|
}
|
||||||
|
return Math.min(this.minSeconds * Math.pow(2, attempt - 1), this.maxSeconds);
|
||||||
}
|
}
|
||||||
async sleep(seconds) {
|
async sleep(seconds) {
|
||||||
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
import github from 'eslint-plugin-github'
|
||||||
|
import jest from 'eslint-plugin-jest'
|
||||||
|
|
||||||
|
const githubConfigs = github.getFlatConfigs()
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
ignores: ['**/node_modules/**', '**/lib/**', '**/dist/**']
|
||||||
|
},
|
||||||
|
githubConfigs.recommended,
|
||||||
|
...githubConfigs.typescript,
|
||||||
|
{
|
||||||
|
files: ['**/*.ts'],
|
||||||
|
languageOptions: {
|
||||||
|
parserOptions: {
|
||||||
|
project: './tsconfig.json'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
'eslint-comments/no-use': 'off',
|
||||||
|
'import/no-namespace': 'off',
|
||||||
|
'no-unused-vars': 'off',
|
||||||
|
'@typescript-eslint/no-unused-vars': 'error',
|
||||||
|
'@typescript-eslint/explicit-member-accessibility': [
|
||||||
|
'error',
|
||||||
|
{accessibility: 'no-public'}
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-require-imports': 'error',
|
||||||
|
'@typescript-eslint/array-type': 'error',
|
||||||
|
'@typescript-eslint/await-thenable': 'error',
|
||||||
|
camelcase: 'off',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': [
|
||||||
|
'error',
|
||||||
|
{allowExpressions: true}
|
||||||
|
],
|
||||||
|
'@typescript-eslint/no-array-constructor': 'error',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'error',
|
||||||
|
'@typescript-eslint/no-extraneous-class': 'error',
|
||||||
|
'@typescript-eslint/no-floating-promises': 'error',
|
||||||
|
'@typescript-eslint/no-for-in-array': 'error',
|
||||||
|
'@typescript-eslint/no-inferrable-types': 'error',
|
||||||
|
'@typescript-eslint/no-misused-new': 'error',
|
||||||
|
'@typescript-eslint/no-namespace': 'error',
|
||||||
|
'@typescript-eslint/no-non-null-assertion': 'warn',
|
||||||
|
'@typescript-eslint/no-unnecessary-qualifier': 'error',
|
||||||
|
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
||||||
|
'@typescript-eslint/no-useless-constructor': 'error',
|
||||||
|
'@typescript-eslint/prefer-for-of': 'warn',
|
||||||
|
'@typescript-eslint/prefer-function-type': 'warn',
|
||||||
|
'@typescript-eslint/prefer-includes': 'error',
|
||||||
|
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
|
||||||
|
'@typescript-eslint/promise-function-async': 'error',
|
||||||
|
'@typescript-eslint/require-array-sort-compare': 'error',
|
||||||
|
'@typescript-eslint/restrict-plus-operands': 'error',
|
||||||
|
'@typescript-eslint/unbound-method': 'error'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
files: ['__test__/**/*.ts'],
|
||||||
|
...jest.configs['flat/recommended']
|
||||||
|
}
|
||||||
|
]
|
||||||
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
|
|
@ -41,12 +41,12 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^29.5.12",
|
||||||
"@types/node": "^24.1.0",
|
"@types/node": "^24.1.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
||||||
"@typescript-eslint/parser": "^7.9.0",
|
"@typescript-eslint/parser": "^8.54.0",
|
||||||
"@vercel/ncc": "^0.44.0",
|
"@vercel/ncc": "^0.44.0",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^9.39.2",
|
||||||
"eslint-plugin-github": "^4.10.2",
|
"eslint-plugin-github": "^6.0.0",
|
||||||
"eslint-plugin-jest": "^28.8.2",
|
"eslint-plugin-jest": "^29.12.1",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"js-yaml": "^4.2.0",
|
"js-yaml": "^4.2.0",
|
||||||
"prettier": "^3.8.4",
|
"prettier": "^3.8.4",
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ export class RetryHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep
|
// Sleep
|
||||||
const seconds = this.getSleepAmount()
|
const seconds = this.getSleepAmount(attempt)
|
||||||
core.info(`Waiting ${seconds} seconds before trying again`)
|
core.info(`Waiting ${seconds} seconds before trying again`)
|
||||||
await this.sleep(seconds)
|
await this.sleep(seconds)
|
||||||
attempt++
|
attempt++
|
||||||
|
|
@ -43,11 +43,12 @@ export class RetryHelper {
|
||||||
return await action()
|
return await action()
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSleepAmount(): number {
|
private getSleepAmount(attempt: number): number {
|
||||||
return (
|
if (this.minSeconds === 0) {
|
||||||
Math.floor(Math.random() * (this.maxSeconds - this.minSeconds + 1)) +
|
return 0
|
||||||
this.minSeconds
|
}
|
||||||
)
|
|
||||||
|
return Math.min(this.minSeconds * Math.pow(2, attempt - 1), this.maxSeconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async sleep(seconds: number): Promise<void> {
|
private async sleep(seconds: number): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue