Skip to content

Commit

Permalink
feat(delete-action-workflow): remove old action, update new function
Browse files Browse the repository at this point in the history
  • Loading branch information
Long18 committed Mar 11, 2024
1 parent a92f39e commit 590684e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
30 changes: 30 additions & 0 deletions .github/actions/cleaner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

org="$1"
repo="$2"

echo "Deleting workflow runs for $org/$repo"

workflows_temp=$(mktemp)

gh api repos/$org/$repo/actions/workflows | jq -r '.workflows[] | [.id, .path] | @tsv' >"$workflows_temp"
cat "$workflows_temp"

workflows_names=$(awk '{print $2}' "$workflows_temp" | grep -v "main")

if [ -z "$workflows_names" ]; then
echo "All workflows are either successful or failed. Nothing to remove"
else
echo "Removing all the workflows that are not successful or failed"
for workflow_name in $workflows_names; do
workflow_filename=$(basename "$workflow_name")
echo "Deleting |$workflow_filename|, please wait..."
gh run list --limit 500 --workflow "$workflow_filename" --json databaseId |
jq -r '.[] | .databaseId' |
xargs -I{} gh run delete {}
done
fi

rm -rf "$workflows_temp"

echo "Done."
30 changes: 0 additions & 30 deletions .github/actions/ghcr-clean/delete_workflows.sh

This file was deleted.

22 changes: 10 additions & 12 deletions .github/workflows/delete.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
name: Remove expired workflow runs
name: Remove Expired Workflow Runs
on:
schedule: [{ cron: "30 1 * * *" }] # Schedule to run the workflow every day at 1:30 AM
workflow_dispatch:

jobs:
delete:
clean:
name: Clean Expired Workflow Runs
runs-on: ubuntu-latest

steps:
- name: Checkout repository
if: ${{ success() || failure() }}
uses: actions/checkout@v3

- name: Run script
if: ${{ success() || failure() }}
working-directory: .github/actions/ghcr-clean
run: sh ./delete_workflows.sh long18 long18
- name: Checkout Action Code
uses: actions/checkout@v2

- name: Run Cleaner Script
run: sh ./cleaner.sh long18 long18
working-directory: .github/actions
env:
GITHUB_TOKEN: ${{ secrets.METRICS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/

0 comments on commit 590684e

Please sign in to comment.