diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25e3c6e..d34312f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,6 +24,7 @@ jobs: node-version: ${{ matrix.version }} cache: 'npm' - run: npm ci + - run: npm run build - uses: ./ with: token: ${{ github.token }} diff --git a/index.js b/index.js index fdf5147..ef208af 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ -const core = require('@actions/core'); -const github = require('@actions/github'); -const { Octokit } = require('@octokit/rest'); -const { extract: extractOlderThanInMs, filterWorkflowRuns: filterWorkflowRunsOlderThan} = require('./process_older_than'); +import core from '@actions/core'; +import github from '@actions/github'; +import { Octokit } from '@octokit/rest'; +import { extract as extractOlderThanInMs, filterWorkflowRuns as filterWorkflowRunsOlderThan} from './process_older_than.js'; const getInput = (name, fallback = undefined, extractor = (data) => data) => { try { diff --git a/package.json b/package.json index 2668850..e745865 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "purge-deprecated-workflow-runs", "description": "Delete github workflow runs that don't have a corresponding workflow (anymore) from the current repository. Optionally delete cancelled, failed or skipped workflow runs.", "main": "dist/index.js", + "type": "module", "scripts": { "build": "npx @vercel/ncc build", "postbuild": "sed 's+index.js+dist/index.js+g' action.yml > action.yml.built && mv action.yml.built action.yml", diff --git a/process_older_than.js b/process_older_than.js index 77ee56b..2974f3f 100644 --- a/process_older_than.js +++ b/process_older_than.js @@ -7,7 +7,7 @@ const durationUnitToMs = { y: 31536000000, } -const extract = (data) => { +export const extract = (data) => { const [since, ...nameSlices] = data.split(' ') const workflowName = nameSlices.length ? nameSlices.join(' ') @@ -26,7 +26,7 @@ const extract = (data) => { } } -const filterWorkflowRuns = (workflowRuns, extractedOlderThanList) => { +export const filterWorkflowRuns = (workflowRuns, extractedOlderThanList) => { const now = new Date() const olderThan = extractedOlderThanList .map((since) => ({ @@ -44,8 +44,3 @@ const filterWorkflowRuns = (workflowRuns, extractedOlderThanList) => { }) ) } - -module.exports = { - extract, - filterWorkflowRuns, -}