Skip to content

Commit

Permalink
6.0.0 (#33)
Browse files Browse the repository at this point in the history
* build: update dependencies

* build: update dependencies

* chore: update package version

* build: update dependencies

* fix: fatal error while processing GitHub workflow runs after creating merge commit

* fix: better expression processing GitHub workflow runs

* style: better expression processing GitHub workflow runs

* lint: update eslint

* fix: typescript-eslint/no-unused-vars

* build: update dependencies

* build: update dependencies

* build: update dependencies

* build: update dependencies

* lint: update ESLint

* fix: stylistic/comma-dangle

* ci: add Dependency Review

* build: update dependencies

* style: use SplitElementsIntoSubArrayLength insead of built-in function

* update dependencies

* build: update dependencies

* chore: update npm dependencies to latest versions

* style: use es-toolkit for array chunking

* build: update dependencies

* fix: lint command error
  • Loading branch information
piquark6046 authored Sep 1, 2024
1 parent fbb7f9e commit 987ae08
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 88 deletions.
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
}

0 comments on commit 987ae08

Please sign in to comment.