Skip to content

Commit

Permalink
Update purget test resources to fix the workflow failures
Browse files Browse the repository at this point in the history
Signed-off-by: ytimocin <[email protected]>
  • Loading branch information
ytimocin committed May 10, 2024
1 parent bc43e42 commit 10e98b7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/purge-test-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ name: Purge test resources
on:
schedule:
- cron: "30 0,12 * * *"
pull_request:
types: [opened, synchronize, reopened]
branches:
- v*.*
- edge
env:
AZURE_RG_DELETE_LIST_FILE: "az_rg_list.txt"
VALID_RESOURCE_WINDOW: 6*60*60
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
purge_azure_resources:
name: Azure resources clean-ups
Expand All @@ -26,9 +32,10 @@ jobs:
current_time=$(date +%s)
hours_ago=$((current_time - ${{ env.VALID_RESOURCE_WINDOW }}))
echo "Hours ago: $hours_ago"
jq -r '.[] | select(.creationTime == null || .creationTime < '$hours_ago') | .Name' resource_groups.json > ${{ env.AZURE_RG_DELETE_LIST_FILE}}
jq -r '.[] | {name: .Name, creationTime: .creationTime // "None"}' resource_groups.json > $GITHUB_STEP_SUMMARY
jq -r '.[] | select(.creationTime == null or .creationTime < '$hours_ago') | .Name' resource_groups.json > ${{ env.AZURE_RG_DELETE_LIST_FILE}}
jq -r '.[] | "\(.Name) \(.creationTime // "None")"' resource_groups.json > $GITHUB_STEP_SUMMARY
- name: Delete Azure Resource Groups
run: |
Expand All @@ -40,8 +47,8 @@ jobs:
done
- name: Create GitHub issue on failure
if: ${{ failure() }}
if: failure() && github.event_name == 'schedule'
run: |
gh issue create --title "Samples purge test resources failed \
gh issue create --title "Samples purge test resources failed" \
--body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." \
s--repo ${{ github.repository }}
--repo ${{ github.repository }}
3 changes: 3 additions & 0 deletions .github/workflows/test/other_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group1 1000
group2 2000
group3 3000
23 changes: 23 additions & 0 deletions .github/workflows/test/test-purge-test-resources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Create a mock resource_groups.json file
echo '[{"Name": "group1", "creationTime": 1000}, {"Name": "group2", "creationTime": 2000}, {"Name": "group3", "creationTime": 3000}]' > resource_groups.json

# Set the hours_ago variable to a known value
hours_ago=1500

echo "hours_ago: $hours_ago"

# Run the command
jq -r '.[] | select(.creationTime == null or .creationTime < '$hours_ago') | .Name' resource_groups.json > output.txt
jq -r '.[] | "\(.Name) \(.creationTime // "None")"' resource_groups.json > other_output.txt

# Check the output
if [[ $(cat output.txt) == "group1" ]]; then
echo "Test passed"
else
echo "Test failed"
fi

# Clean up
rm resource_groups.json output.txt

0 comments on commit 10e98b7

Please sign in to comment.