Merge pull request #273 from balena-io/ab77/patch

Only delete your (matrix) own test instance
This commit is contained in:
Anton Belodedenko 2024-07-02 13:47:56 -07:00 committed by GitHub
commit 9fde727b80
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 # always destroy test EC2 instances even if the workflow is cancelled
- name: destroy AWS test device(s) - name: destroy AWS test device(s)
if: always() if: always() && matrix.target == 'balena-public-pki'
run: | run: |
set -ue set -ue
@ -1024,14 +1024,36 @@ jobs:
--instance-ids ${{ steps.balena-sut.outputs.instance_id }} --instance-ids ${{ steps.balena-sut.outputs.instance_id }}
fi fi
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 if [[ -n '${{ steps.ubuntu-sut.outputs.instance_id }}' ]]; then
with_backoff aws ec2 terminate-instances \ with_backoff aws ec2 terminate-instances \
--instance-ids ${{ steps.ubuntu-sut.outputs.instance_id }} --instance-ids ${{ steps.ubuntu-sut.outputs.instance_id }}
fi fi
with_backoff aws ec2 describe-instances --filters Name=tag:GITHUB_SHA,Values=${GITHUB_SHA}-tests \ env:
| jq -r .Reservations[].Instances[].InstanceId \ AWS_DEFAULT_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
| xargs --no-run-if-empty aws ec2 terminate-instances --instance-ids
# 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) stale_instances=$(mktemp)
aws ec2 describe-instances --filters \ aws ec2 describe-instances --filters \