Skip to content

Commit

Permalink
Merge pull request #101 from DonColon/dev
Browse files Browse the repository at this point in the history
Finished cleanup workflow
  • Loading branch information
DonColon authored Mar 17, 2024
2 parents 56efc3c + f96f6df commit d95c463
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
30 changes: 30 additions & 0 deletions .github/scripts/cleanup-deployments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export default async ({ core, context, github }) => {
const { owner, repo } = context.repo;

const parameters = {
owner,
repo,
per_page: 100,
environment: "netlify"
}

for await(const response of github.paginate.iterator(github.rest.repos.listDeployments, parameters)) {
const { data: deployments } = response;

core.info(`${deployments.length} deployments found`);

for(const deployment of deployments) {
try {
await github.rest.repos.deleteDeployment({
owner,
repo,
deployment_id: deployment.id,
});
} catch(error) {
core.info(`Deployment ${deployment.id}: ${error.message}`);
}
}
}

core.info(`Deleted all deployments`);
};
28 changes: 19 additions & 9 deletions .github/scripts/cleanup-workflow-runs.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
export default async ({ core, context, github }) => {
const { owner, repo } = context.repo;

const { data: workflowRuns } = await github.rest.actions.listWorkflowRunsForRepo({
const parameters = {
owner,
repo
});
repo,
per_page: 100,
status: "completed"
}

for await(const response of github.paginate.iterator(github.rest.actions.listWorkflowRunsForRepo, parameters)) {
const { data: workflowRuns } = response;

for(const workflowRun of workflowRuns) {
await github.rest.actions.deleteWorkflowRun({
owner,
repo,
run_id: workflowRun.id,
});
core.info(`${workflowRuns.length} workflow runs found`);

for(const workflowRun of workflowRuns) {
await github.rest.actions.deleteWorkflowRun({
owner,
repo,
run_id: workflowRun.id,
});
}
}

core.info(`Deleted all workflow runs`);
};
6 changes: 6 additions & 0 deletions .github/scripts/publish-latest-release.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import pkg from "../../package.json" assert { type: "json" };

export default async ({ core, context, github, release }) => {
const appVersion = `v${pkg.version}`;
const { owner, repo } = context.repo;

await github.rest.repos.updateRelease({
owner,
repo,
release_id: release.id,
tag_name: appVersion,
name: appVersion,
target_commitish: process.env.GITHUB_SHA,
draft: process.env.GITHUB_REF_NAME.includes("feature"),
prerelease: process.env.GITHUB_REF_NAME === "dev"
});
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/ci-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30

permissions:
actions: write
deployments: write

steps:
- name: Checkout Repository ${{ github.event.repository.name }}
uses: actions/checkout@v4
Expand All @@ -19,4 +23,13 @@ jobs:
script: |
const scriptPath = '${{ github.workspace }}/.github/scripts/cleanup-workflow-runs.js';
const { default: cleanupWorkflowRuns } = await import(scriptPath);
await cleanupWorkflowRuns({ core, context, github });
await cleanupWorkflowRuns({ core, context, github });
- name: Cleanup Deployments
uses: actions/github-script@v7
id: cleanup_deployments
with:
script: |
const scriptPath = '${{ github.workspace }}/.github/scripts/cleanup-deployments.js';
const { default: cleanupDeployments } = await import(scriptPath);
await cleanupDeployments({ core, context, github });

0 comments on commit d95c463

Please sign in to comment.