Skip to content

Test - CloudFormation #123

Test - CloudFormation

Test - CloudFormation #123

name: Test - CloudFormation
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
permissions:
id-token: write
contents: read
jobs:
test:
if: github.repository == 'aws-samples/eks-workshop-v2'
name: run-tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set cluster ID
env:
RUN_ID: "${{ github.job }}"
AWS_REGION: "${{ secrets.AWS_REGION }}"
run: |
CLUSTER_ID=$(echo $RANDOM | md5sum | head -c 8)
echo "Using cluster ID ${CLUSTER_ID}"
echo "CLUSTER_ID=$CLUSTER_ID" >> $GITHUB_ENV
- name: Set branch name
run: echo "TEST_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
- name: Get AWS credentials
uses: aws-actions/configure-aws-credentials@v4.0.2
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
role-duration-seconds: 3600
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: GithubActionsSession-${{ env.CLUSTER_ID }}
- name: Deploy
id: deploy
env:
AWS_REGION: "${{ secrets.AWS_REGION }}"
run: |
aws cloudformation deploy --stack-name cfn-test-${CLUSTER_ID}-${TEST_BRANCH} \
--template-file ./lab/cfn/eks-workshop-ide-cfn.yaml \
--parameter-overrides RepositoryRef=${TEST_BRANCH} \
--capabilities CAPABILITY_NAMED_IAM
- name: Cleanup
if: always()
env:
AWS_REGION: "${{ secrets.AWS_REGION }}"
run: |
aws cloudformation delete-stack --stack-name cfn-test-${CLUSTER_ID}-${TEST_BRANCH}
aws cloudformation wait stack-delete-complete --stack-name cfn-test-${CLUSTER_ID}-${TEST_BRANCH}