Only delete your (matrix) own test instance

change-type: patch
This commit is contained in:
Anton Belodedenko 2024-07-02 11:04:44 -07:00 committed by GitHub
parent 297fff91c1
commit 96d5617889
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1011,7 +1011,7 @@ jobs:
# always destroy test EC2 instances even if the workflow is cancelled
- name: destroy AWS test device(s)
if: always()
if: always() && matrix.target == 'balena-public-pki'
run: |
set -ue
@ -1024,15 +1024,55 @@ jobs:
--instance-ids ${{ steps.balena-sut.outputs.instance_id }}
fi
with_backoff aws ec2 describe-instances \
--filters Name=tag:GITHUB_SHA,Values=${GITHUB_SHA}-tests \
Name=tag:GITHUB_RUN_ID,Values=${GITHUB_RUN_ID}-tests \
Name=tag:GITHUB_RUN_NUMBER,Values=${GITHUB_RUN_NUMBER}-tests \
Name=tag:GITHUB_RUN_NUMBER,Values=${GITHUB_RUN_NUMBER}-tests \
Name=tag:GITHUB_RUN_ATTEMPT,Values=${GITHUB_RUN_ATTEMPT}-tests \
| jq -r .Reservations[].Instances[].InstanceId \
| xargs --no-run-if-empty aws ec2 terminate-instances --instance-ids
env:
AWS_DEFAULT_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
# always destroy test EC2 instances even if the workflow is cancelled
- name: destroy AWS test device(s)
if: always() && matrix.target == 'compose-private-pki'
run: |
set -ue
[[ '${{ vars.VERBOSE }}' =~ on|On|Yes|yes|true|True ]] && set -x
source src/balena-tests/functions
if [[ -n '${{ steps.ubuntu-sut.outputs.instance_id }}' ]]; then
with_backoff aws ec2 terminate-instances \
--instance-ids ${{ steps.ubuntu-sut.outputs.instance_id }}
fi
with_backoff aws ec2 describe-instances --filters Name=tag:GITHUB_SHA,Values=${GITHUB_SHA}-tests \
with_backoff aws ec2 describe-instances \
--filters Name=tag:GITHUB_SHA,Values=${GITHUB_SHA}-tests \
Name=tag:GITHUB_RUN_ID,Values=${GITHUB_RUN_ID}-tests \
Name=tag:GITHUB_RUN_NUMBER,Values=${GITHUB_RUN_NUMBER}-tests \
Name=tag:GITHUB_RUN_NUMBER,Values=${GITHUB_RUN_NUMBER}-tests \
Name=tag:GITHUB_RUN_ATTEMPT,Values=${GITHUB_RUN_ATTEMPT}-tests \
| jq -r .Reservations[].Instances[].InstanceId \
| xargs --no-run-if-empty aws ec2 terminate-instances --instance-ids
env:
AWS_DEFAULT_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
# always destroy stale test EC2 instances
- name: destroy stale AWS test device(s)
if: always()
run: |
set -ue
[[ '${{ vars.VERBOSE }}' =~ on|On|Yes|yes|true|True ]] && set -x
source src/balena-tests/functions
stale_instances=$(mktemp)
aws ec2 describe-instances --filters \
Name=tag:Name,Values=open-balena-tests \