-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial work on adding UI tests for eShop on AWS
- Loading branch information
Showing
4 changed files
with
175 additions
and
29 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: Purge AWS Test Resources | ||
on: | ||
schedule: | ||
- cron: "30 0,12 * * *" | ||
env: | ||
VALID_RESOURCE_WINDOW: 6*60*60 | ||
AWS_REGION: us-east-2 | ||
jobs: | ||
purge_aws_resources: | ||
name: AWS Test Resources Clean-up | ||
runs-on: [self-hosted, 1ES.Pool=1ES-Radius] | ||
steps: | ||
- name: Checkout Code | ||
uses: actions/checkout@v3 | ||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
- name: List EKS Clusters | ||
id: list-clusters | ||
run: | | ||
CLUSTERS=$(eksctl get clusters --region ${{ env.AWS_REGION }} --output json | jq -r '.[].metadata.name') | ||
echo "::set-output name=clusters::$CLUSTERS" | ||
- name: Filter Old Clusters | ||
id: filter-clusters | ||
run: | | ||
OLD_CLUSTERS="" | ||
for CLUSTER in ${{ steps.list-clusters.outputs.clusters }}; do | ||
CREATED_AT=$(aws eks describe-cluster --name $CLUSTER --region ${{ env.AWS_REGION }} --query 'cluster.createdAt' --output text) | ||
CREATED_TIMESTAMP=$(date -d $CREATED_AT +%s) | ||
CURRENT_TIMESTAMP=$(date +%s) | ||
ELAPSED_TIME=$((CURRENT_TIMESTAMP - CREATED_TIMESTAMP)) | ||
if [[ $ELAPSED_TIME -gt ${{ env.VALID_RESOURCE_WINDOW }} ]]; then | ||
OLD_CLUSTERS="$OLD_CLUSTERS $CLUSTER" | ||
fi | ||
done | ||
echo "::set-output name=old-clusters::$OLD_CLUSTERS" | ||
- name: Delete Old Clusters | ||
if: steps.filter-clusters.outputs.old-clusters != '' | ||
run: | | ||
for CLUSTER in ${{ steps.filter-clusters.outputs.old-clusters }}; do | ||
eksctl delete cluster --name $CLUSTER --region ${{ env.AWS_REGION }} --wait | ||
done | ||
- name: Delete Old Resources | ||
run: | | ||
RESOURCE_IDS=$(aws resourcegroupstaggingapi get-resources --tag-filters "Key=environment,Values=functional-test" --query 'ResourceTagMappingList[?((`date +%s` - (CreationTime | tonumber)) > ${{ env.VALID_RESOURCE_WINDOW }})].ResourceARN' --output text) | ||
for RESOURCE_ID in $RESOURCE_IDS; do | ||
echo "Deleting resource: $RESOURCE_ID" | ||
aws cloudformation delete-stack --stack-name $RESOURCE_ID --wait | ||
done | ||
- name: Create GitHub issue on failure | ||
if: ${{ failure() }} | ||
run: | | ||
gh issue create --title "Samples purge AWS 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." \ | ||
--repo ${{ github.repository }} |
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
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