Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.0.0 #33

Merged
merged 24 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0fc9c05
build: update dependencies
piquark6046 Mar 5, 2024
c28b8eb
build: update dependencies
piquark6046 Mar 7, 2024
b438166
chore: update package version
piquark6046 Mar 9, 2024
390db29
build: update dependencies
piquark6046 Mar 9, 2024
3fdb1ea
fix: fatal error while processing GitHub workflow runs after creating…
piquark6046 Mar 9, 2024
e51bae4
fix: better expression processing GitHub workflow runs
piquark6046 Mar 10, 2024
b345896
style: better expression processing GitHub workflow runs
piquark6046 Mar 11, 2024
1ad460d
lint: update eslint
piquark6046 Mar 12, 2024
2547f40
fix: typescript-eslint/no-unused-vars
piquark6046 Mar 12, 2024
6ad51ab
build: update dependencies
piquark6046 Mar 12, 2024
0dbf9c5
build: update dependencies
piquark6046 Mar 16, 2024
6c2d2b3
build: update dependencies
piquark6046 Mar 18, 2024
b37161e
build: update dependencies
piquark6046 Mar 22, 2024
4986a53
lint: update ESLint
piquark6046 Mar 24, 2024
ee88298
fix: stylistic/comma-dangle
piquark6046 Mar 24, 2024
8763d45
ci: add Dependency Review
piquark6046 Mar 25, 2024
53889d4
build: update dependencies
piquark6046 Apr 7, 2024
a9b9e17
style: use SplitElementsIntoSubArrayLength insead of built-in function
piquark6046 Apr 9, 2024
da40801
update dependencies
piquark6046 May 5, 2024
dadac42
build: update dependencies
piquark6046 Jun 4, 2024
011a0ea
chore: update npm dependencies to latest versions
piquark6046 Jul 6, 2024
5afbd2a
style: use es-toolkit for array chunking
piquark6046 Jul 6, 2024
b620d9f
build: update dependencies
piquark6046 Sep 1, 2024
4056b8f
fix: lint command error
piquark6046 Sep 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions .eslintrc.cjs

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/dependency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v4
27 changes: 27 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import tsPlugin from "@typescript-eslint/eslint-plugin"
import tsParser from "@typescript-eslint/parser"

const config = [
{
files: ["**/*.ts", "**/*.tsx"], // Target TypeScript files
languageOptions: {
parser: tsParser,
sourceType: "module",
},
plugins: {
"@typescript-eslint": tsPlugin,
},
rules: {
...tsPlugin.configs.recommended.rules,
"semi": ["error", "never"],
"quotes": ["error", "single"],
"@typescript-eslint/no-unused-vars": "warn",
'@typescript-eslint/naming-convention': ['error', {
selector: ['variableLike', 'parameterProperty', 'classProperty', 'typeProperty'],
format: ['PascalCase']
}]
}
}
]

export default config
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var ChangedFiles: Array<{Branch: string; Filename: string}> = []
for (const Branch of Branches.Branches) {
const CommitManagerInstance = new CommitManager(ProgramOptions)
// eslint-disable-next-line no-await-in-loop
const CommitSHA = await CommitManagerInstance.GetCommitSHAFromLatestWorkflowTime(LatestWorkflowRunTime, Branch).then(CommitSHA => CommitSHA)
const CommitSHA = await CommitManagerInstance.GetCommitSHAFromLatestWorkflowTime(LatestWorkflowRunTime).then(CommitSHA => CommitSHA)
if (CommitSHA.length === 0) {
continue
}
Expand Down
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsdelivr-purge",
"version": "5.6.0",
"version": "6.0.0",
"author": {
"name": "PiQuark6046",
"email": "[email protected]",
Expand All @@ -18,27 +18,25 @@
"type": "module",
"scripts": {
"ci": "tsx index.ts",
"lint": "tsc && eslint . --ext .ts"
"lint": "tsc --noEmit && eslint ."
},
"dependencies": {
"@actions/core": "^1.10.1",
"@octokit/rest": "^20.0.2",
"@octokit/rest": "^21.0.2",
"@types/luxon": "^3.4.2",
"@types/node": "^20.11.24",
"commander": "^12.0.0",
"got": "^14.2.0",
"@types/node": "^22.5.1",
"commander": "^12.1.0",
"es-toolkit": "^1.17.0",
"got": "^14.4.2",
"ip-regex": "^5.0.0",
"luxon": "^3.4.4",
"luxon": "^3.5.0",
"p-queue": "^8.0.1",
"simple-git": "^3.22.0",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
"simple-git": "^3.25.0",
"tsx": "^4.19.0",
"typescript": "^5.5.4"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"eslint": "^8.57.0",
"eslint-config-xo": "^0.44.0",
"eslint-config-xo-typescript": "^3.0.0"
"eslint": "^9.9.1",
"typescript-eslint": "^8.3.0"
}
}
29 changes: 22 additions & 7 deletions sources/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@ import * as GitHub from '@octokit/rest'
import {DateTime} from 'luxon'
import type {ProgramOptionsType} from './types.js'

async function ListWorkflowRuns(ProgramOptions: ProgramOptionsType, EventType: string) {
const GitHubInstance = new GitHub.Octokit({auth: ProgramOptions.ghToken})
const [RepoOwner, RepoName] = ProgramOptions.repo.split('/')
const WorkflowRuns = await GitHubInstance.actions.listWorkflowRuns({
event: EventType,
owner: RepoOwner, repo: RepoName,
workflow_id: /(?<=^[A-Za-z0-9-_.]+\/[A-Za-z0-9-_.]+\/\.github\/workflows\/).+\.yml(?=@refs\/)/.exec(ProgramOptions.workflowRef)[0]
}).then(WorkflowRuns => WorkflowRuns.data.workflow_runs)
return WorkflowRuns
}

/**
* @name GetLatestWorkflowTime
* @description Get the latest workflow time.
* @param {ProgramOptionsType} ProgramOptions The program options.
* @returns {Promise<number>} The latest workflow time in milliseconds.
*/
export async function GetLatestWorkflowTime(ProgramOptions: ProgramOptionsType): Promise<number> {
const GitHubInstance = new GitHub.Octokit({auth: ProgramOptions.ghToken})
const [RepoOwner, RepoName] = ProgramOptions.repo.split('/')
var LatestWorkflowRunTime = 0
const WorkflowRuns = await GitHubInstance.actions.listWorkflowRuns({
owner: RepoOwner, repo: RepoName,
workflow_id: /(?<=^[A-Za-z0-9-_.]+\/[A-Za-z0-9-_.]+\/\.github\/workflows\/).+\.yml(?=@refs\/)/.exec(ProgramOptions.workflowRef)[0],
}).then(WorkflowRuns => WorkflowRuns.data.workflow_runs)
for (const WorkflowRun of WorkflowRuns) {
let WorkflowRuns: ReturnType<typeof ListWorkflowRuns> = null
for (const EventType of ['push', 'release']) {
if (WorkflowRuns === null) {
WorkflowRuns = ListWorkflowRuns(ProgramOptions, EventType)
} else {
// eslint-disable-next-line no-await-in-loop
(await WorkflowRuns).push(...await ListWorkflowRuns(ProgramOptions, EventType))
}
}

for (const WorkflowRun of await WorkflowRuns) {
if (WorkflowRun.status === 'completed' && WorkflowRun.conclusion === 'success'
&& DateTime.fromISO(WorkflowRun.updated_at).toMillis() > LatestWorkflowRunTime) {
LatestWorkflowRunTime = DateTime.fromISO(WorkflowRun.updated_at).toMillis()
Expand Down
2 changes: 1 addition & 1 deletion sources/branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function CreateGitInstance(BasePath: string): Git.SimpleGit {
export async function ListBranches(ProgramOptions: Types.ProgramOptionsType): Promise<{Branches: string[]; Default: string}> {
var Branches: {Branches: string[]; Default: string} = {
Branches: [],
Default: '',
Default: ''
}
const GitInstance = CreateGitInstance(ProgramOptions.ciWorkspacePath)
Branches.Default = await GitInstance.branchLocal().then(Branches => Branches.current)
Expand Down
2 changes: 1 addition & 1 deletion sources/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CommitManager {
* @param {string} Branch The branch or tag name.
* @returns {Promise<Types.CommitSHA>} SHA of the latest commit.
*/
async GetCommitSHAFromLatestWorkflowTime(LatestWorkflowRunTime: number, Branch: string): Promise<Types.CommitSHA> {
async GetCommitSHAFromLatestWorkflowTime(LatestWorkflowRunTime: number): Promise<Types.CommitSHA> {
var MatchedCommitTimeAddress = 0
const GitInstance = CreateGitInstance(this.ProgramOptions.ciWorkspacePath)
const GitLog = (await GitInstance.log(['--date=iso-strict'])).all
Expand Down
6 changes: 3 additions & 3 deletions sources/ipcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export async function GetIPAddress(): Promise<string> {
const ResponseRAW = await got('https://checkip.amazonaws.com/', {
https: {
minVersion: 'TLSv1.3',
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256',
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'
},
http2: true,
headers: {
'user-agent': 'jsdelivr-purge',
},
'user-agent': 'jsdelivr-purge'
}
}).text()

return (ipRegex().exec(ResponseRAW))?.[0] ?? 'UNKNWON'
Expand Down
14 changes: 7 additions & 7 deletions sources/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ async function GetCDNResponse(ProgramOptions: Types.ProgramOptionsType, ID: stri
const ResponseRaw: Types.CDNStatusResponseType = await got(`https://purge.jsdelivr.net/status/${ID}`, {
https: {
minVersion: 'TLSv1.3',
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256',
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'
},
http2: true,
headers: {
'user-agent': 'jsdelivr-purge',
},
'user-agent': 'jsdelivr-purge'
}
}).json()

for (const [Key, Value] of Object.entries(ResponseRaw.paths)) {
Expand All @@ -34,16 +34,16 @@ async function PostPurgeRequest(ProgramOptions: Types.ProgramOptionsType, Branch
const ResponseRaw: Types.CDNPostResponseType = await got.post('https://purge.jsdelivr.net/', {
headers: {
'cache-control': 'no-cache',
'user-agent': 'jsdelivr-purge',
'user-agent': 'jsdelivr-purge'
},
json: {
path: new Array(Filenames.length).fill(null, 0, Filenames.length).map((Filename, Index) => `/gh/${ProgramOptions.repo}@${BranchOrTag[Index]}/${Filenames[Index]}`),
path: new Array(Filenames.length).fill(null, 0, Filenames.length).map((Filename, Index) => `/gh/${ProgramOptions.repo}@${BranchOrTag[Index]}/${Filenames[Index]}`)
} satisfies Types.CDNPostRequestType,
https: {
minVersion: 'TLSv1.3',
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256',
ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256'
},
http2: true,
http2: true
}).json()
Actions.startGroup(`PostPurgeRequest called: ${ResponseRaw.id}`)
Actions.info(JSON.stringify(ResponseRaw))
Expand Down
20 changes: 6 additions & 14 deletions sources/utility.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {chunk} from 'es-toolkit'
import type * as Types from './types.js'

/**
Expand Down Expand Up @@ -38,30 +39,21 @@ export function IncludePropertiesInObject(CustomObjectArray: unknown[], CompareO
return CustomObjectArray.some(CustomObject => Object.entries(CompareObject).every(([Key, Value]) => CustomObject[Key] === Value))
}

function GroupObjectByNumber(StringOrObject: unknown[], GroupSize: number): unknown[][] {
const SplittedArray = new Array<unknown[]>(Math.ceil(StringOrObject.length / GroupSize))
for (var I = 0; I < SplittedArray.length; I++) {
SplittedArray[I] = StringOrObject.slice(I === 0 ? I : I * GroupSize, (I + 1) * GroupSize > StringOrObject.length ? StringOrObject.length : (I + 1) * GroupSize)
}

return SplittedArray
}

/**
* @name GroupStringsByNumber
* @description Groups a RemainingFilenamesArray into subarrays based on a specified group size. A group with latest tag will be separated from others.
* @param {Types.RemainingFilenamesArrayType[]} RemainingObjectArray A RemainingFilenamesArray to group.
* @param {number} GroupSize The maximum number of elements in each subarray.
* @param {number} {Count} The maximum number of elements in each subarray.
* @returns {Types.RemainingFilenamesArrayType[][]} A RemainingFilenamesArray of subarrays.
*/
export function GroupRequestsByNumberWithBranch(RemainingObjectArray: Types.RemainingFilenamesArrayType[], GroupSize: number): Types.RemainingFilenamesArrayType[][] {
export function GroupRequestsByNumberWithBranch(RemainingObjectArray: Types.RemainingFilenamesArrayType[], Count: number): Types.RemainingFilenamesArrayType[][] {
if (RemainingObjectArray.every(RemainingObject => RemainingObject.BranchOrTag === RemainingObjectArray[0].BranchOrTag)) {
return GroupObjectByNumber(RemainingObjectArray, GroupSize) as Types.RemainingFilenamesArrayType[][]
return chunk(RemainingObjectArray, Count) as Types.RemainingFilenamesArrayType[][]
}

const SplittedArray: Types.RemainingFilenamesArrayType[][] = []
SplittedArray.push(...GroupObjectByNumber(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag === 'latest'), GroupSize) as Types.RemainingFilenamesArrayType[][])
SplittedArray.push(...GroupObjectByNumber(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag !== 'latest'), GroupSize) as Types.RemainingFilenamesArrayType[][])
SplittedArray.push(...chunk(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag === 'latest'), Count) as Types.RemainingFilenamesArrayType[][])
SplittedArray.push(...chunk(RemainingObjectArray.filter(RemainingObject => RemainingObject.BranchOrTag !== 'latest'), Count) as Types.RemainingFilenamesArrayType[][])

return SplittedArray
}