Skip to content

Commit

Permalink
ci(repo): debugging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Dec 3, 2024
1 parent 4a2d0d8 commit d7e5230
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/cleanup_artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ on:
days_to_keep:
description: "Number of days to keep artifacts"
required: true
default: 30
default: 15
type: number
schedule:
- cron: '0 0 */15 * *' # Runs every 15 days at midnight UTC
- cron: "0 0 */15 * *" # Runs every 15 days at midnight UTC

permissions:
contents: read
Expand All @@ -22,13 +22,22 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check GitHub CLI Authentication
run: gh auth status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run Artifact Cleanup
env:
GH_TOKEN: ${{ secrets.REPO_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.repository }}
REPO_NAME: ${{ github.event.repository.name }}
DAYS_TO_KEEP: ${{ github.event.inputs.days_to_keep || '15' }}
run: |-
# Debug information
echo "Repository Owner: ${REPO_OWNER}"
echo "Repository Name: ${REPO_NAME}"
make cleanup_artifacts \
REPO_OWNER="${REPO_OWNER}" \
REPO_NAME="${REPO_NAME}" \
Expand Down
30 changes: 25 additions & 5 deletions scripts/cleanup_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@ REPO_OWNER="$1"
REPO_NAME="$2"
DAYS_TO_KEEP="$3"

# Debug: Print input parameters
echo "Debug: Script parameters:"
echo " REPO_OWNER: ${REPO_OWNER}"
echo " REPO_NAME: ${REPO_NAME}"
echo " DAYS_TO_KEEP: ${DAYS_TO_KEEP}"

# Ensure gh CLI is installed and authenticated
if ! command -v gh &> /dev/null; then
echo "GitHub CLI (gh) is not installed. Please install it first."
exit 1
fi

if ! gh auth status &> /dev/null; then
echo "GitHub CLI is not authenticated. Please run 'gh auth login' first."
exit 1
fi
# Debug: Check gh auth status
echo "Debug: Checking gh auth status..."
gh auth status

# Get the cutoff date
CUTOFF_DATE=$(get_date "$DAYS_TO_KEEP")
Expand All @@ -39,12 +44,26 @@ PAGE=1
while true; do
echo "Processing page $PAGE"

RESPONSE=$(gh api "repos/$REPO_OWNER/$REPO_NAME/actions/artifacts?per_page=100&page=$PAGE" 2>&1)
# Debug: Print API URL being called
API_URL="repos/$REPO_OWNER/$REPO_NAME/actions/artifacts?per_page=100&page=$PAGE"
echo "Debug: Calling API endpoint: $API_URL"

# Debug: Test API call with curl
echo "Debug: Testing API endpoint with curl..."
curl -s -I -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/$API_URL"

RESPONSE=$(gh api "$API_URL" 2>&1)
if [[ $? -ne 0 ]]; then
echo "Error fetching artifacts: $RESPONSE"
echo "Debug: Full API response:"
echo "$RESPONSE"
exit 1
fi

# Debug: Print response structure (without sensitive data)
echo "Debug: Response structure:"
echo "$RESPONSE" | jq 'del(.artifacts[].archive_download_url)' 2> /dev/null || echo "Failed to parse response as JSON"

ART_EXIST=$(echo "$RESPONSE" | jq -r '.artifacts[]')
if [[ -z "$ART_EXIST" ]]; then
echo "No more artifacts found."
Expand All @@ -54,6 +73,7 @@ while true; do
ARTIFACTS=$(echo "$RESPONSE" | jq -r ".artifacts[] | select(.created_at < \"$CUTOFF_DATE\") | .id")

for ARTIFACT_ID in $ARTIFACTS; do
echo "Debug: Processing artifact ID: $ARTIFACT_ID"
ARTIFACT_INFO=$(gh api "repos/$REPO_OWNER/$REPO_NAME/actions/artifacts/$ARTIFACT_ID" 2>&1)
if [[ $? -ne 0 ]]; then
echo "Error fetching artifact info for ID $ARTIFACT_ID: $ARTIFACT_INFO"
Expand Down

0 comments on commit d7e5230

Please sign in to comment.