Skip to content

Commit

Permalink
configure ci processing
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Sep 27, 2024
1 parent 79c9a7d commit b20a240
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import * as Commander from 'commander'
import * as Actions from '@actions/core'
import * as Os from 'node:os'
import * as Fs from 'node:fs'
import PLimit from 'p-limit'
import { RequestNpmPackageMetaData } from './sources/npm-api.js'
import { HistoryManager } from './sources/github.js'
import { PurgeRequestManager } from './sources/requests.js'
import { FileManager } from './sources/file.js'

Actions.info(`Running on ${Os.cpus()[0].model} with ${Os.cpus().length} threads/vCPUs.`)

Expand Down Expand Up @@ -37,3 +41,19 @@ const Options = Program.opts() as {
repo: string
}

const CurrrentTags = (await RequestNpmPackageMetaData(Options.package))['dist-tags']
Fs.writeFileSync('/tmp/dist-tag.json', JSON.stringify(CurrrentTags))
const OlderTags = await new HistoryManager({ Repo: Options.repo, GitHubToken: Options.ghToken, WorkflowRef: Options.workflowRef }).RequestHistory()

const PLimitInstance = PLimit(Os.cpus().length)
const PLimitJobs: Promise<void>[] = []
for (const TargetTag of Options.distTag.split(' ')) {
PLimitJobs.push(PLimitInstance(async () => {
const ChangedFiles = await new FileManager(Options.repo, { A: CurrrentTags[TargetTag], B: OlderTags === null ? undefined : OlderTags[TargetTag] }, `${Options.ciWorkspacePath}/${TargetTag}`).Union()
const PurgeRequestManagerInstance = new PurgeRequestManager(Options.repo)
PurgeRequestManagerInstance.AddURLs(ChangedFiles, TargetTag)
PurgeRequestManagerInstance.Start()
}))
}

await Promise.all(PLimitJobs)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"es-toolkit": "^1.17.0",
"got": "^14.4.2",
"luxon": "^3.5.0",
"p-limit": "^6.1.0",
"tar": "^7.4.3",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
Expand Down
4 changes: 2 additions & 2 deletions sources/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type IHistoryManagerDataJSON = Record<string, string>
export class HistoryManager {
private GitHubInstance: InstanceType<typeof GitHub.Octokit> = null

constructor(private readonly Config: { Repo: string, GitHubToken: string, WorkflowRef: string, DistTags: string }) {
constructor(private readonly Config: { Repo: string, GitHubToken: string, WorkflowRef: string }) {
this.GitHubInstance = new GitHub.Octokit({ auth: this.Config.GitHubToken })
}

Expand Down Expand Up @@ -36,7 +36,7 @@ export class HistoryManager {
return GHResponseRuns.data.total_count > 0
}

private async RequestHistory() {
async RequestHistory() {
if (!await this.CheckWorkflowRunExist()) {
return null
}
Expand Down

0 comments on commit b20a240

Please sign in to comment.