-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update purge test resources to fix the workflow failures #1552
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ on: | |
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 | ||
|
@@ -22,13 +23,21 @@ jobs: | |
- name: List Test Resource Groups | ||
run: | | ||
echo "## Test resource group list" >> $GITHUB_STEP_SUMMARY | ||
az group list --query "[?starts_with(name, 'samplestest-')].{Name:name, creationTime:tags.creationTime}" -o json > resource_groups.json | ||
az group list --query "[?starts_with(name, 'rg-samplestest-')].{Name:name, creationTime:tags.creationTime}" -o json > resource_groups.json | ||
|
||
current_time=$(date +%s) | ||
hours_ago=$((current_time - ${{ env.VALID_RESOURCE_WINDOW }})) | ||
|
||
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 | ||
# This jq command processes the data in 'resource_groups.json'. | ||
# For each object in the JSON array, it checks if the 'creationTime' property is null or less than the value of 'hours_ago'. | ||
# Note that the 'creationTime' is converted to a number for the comparison. | ||
# Then the name of the resource group is written to the file specified by the 'AZURE_RG_DELETE_LIST_FILE' environment variable. | ||
jq -r '.[] | select(.creationTime == null // (.creationTime | tonumber) < '$hours_ago') | .Name' resource_groups.json > ${{ env.AZURE_RG_DELETE_LIST_FILE}} | ||
|
||
# This jq command also processes the data in 'resource_groups.json'. | ||
# For each object in the JSON array, it outputs a string containing the 'Name' property, and the 'creationTime' property. | ||
# If 'creationTime' is null, it outputs the string "None" instead. | ||
jq -r '.[] | "\(.Name) \(.creationTime // "None")"' resource_groups.json > $GITHUB_STEP_SUMMARY | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comments might be helpful here. We made sure creationTime can be converted to a number and we're changing op format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comments @lakshmimsft |
||
|
||
- name: Delete Azure Resource Groups | ||
run: | | ||
|
@@ -40,8 +49,8 @@ jobs: | |
done | ||
|
||
- name: Create GitHub issue on failure | ||
if: ${{ failure() }} | ||
if: failure() | ||
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 }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is causing this to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was wrong before. We can see that the resource groups we create have a prefix of
rg-samplestest
: https://github.com/radius-project/samples/blob/v0.33/.github/workflows/test.yaml#L122.