fixing branch name #46
This file contains hidden or 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
| name: Tests and Deploy | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| jobs: | |
| ExecuteTests: | |
| name: ExecuteTests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'maven' | |
| - name: Run Tests | |
| run: mvn test | |
| BootstrapBucketCreation: | |
| name: Bootstrap | |
| runs-on: ubuntu-latest | |
| needs: ExecuteTests | |
| if: github.ref_name == 'dev' | |
| permissions: | |
| id-token: write | |
| contents: read | |
| outputs: | |
| s3_bucket_name: ${{ steps.bootstrap.outputs.s3_bucket_name }} | |
| dynamo_table_name: ${{ steps.bootstrap.outputs.dynamo_table_name }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: 'Configure AWS Credentials' | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: 'us-west-2' | |
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GithubActionsRole | |
| role-session-name: github-action-terraform-deploy | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.6.6 | |
| cli_config_credentials_token: ${{ secrets.TFE_API_TOKEN }} | |
| - name: 'Bootstrap S3 State Bucket' | |
| id: bootstrap | |
| shell: bash | |
| working-directory: ./terraform/bootstrap | |
| run: | | |
| WORKSPACE_NAME="${{ github.event.repository.name }}" | |
| echo "Workspace a ser criado/assegurado: $WORKSPACE_NAME" | |
| BOOTSTRAP_TERRAFORM_KEY="bootstrap/terraform.tfstate" | |
| echo "Key para o bucket: $BOOTSTRAP_TERRAFORM_KEY" | |
| terraform init -backend-config="key=$BOOTSTRAP_TERRAFORM_KEY" | |
| terraform apply -auto-approve \ | |
| -var="project_name=$WORKSPACE_NAME" \ | |
| echo "s3_bucket_name=$(terraform output -raw s3_bucket_name)" >> $GITHUB_OUTPUT | |
| echo "dynamo_table_name=$(terraform output -raw dynamodb_table_name)" >> $GITHUB_OUTPUT | |
| build_java: | |
| name: Build Java Application | |
| runs-on: ubuntu-latest | |
| needs: BootstrapBucketCreation | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: 'maven' | |
| - name: Build Java project with Maven | |
| run: mvn clean package | |
| - name: Upload JAR as Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: battlesnake-lambda-jar | |
| path: target/battlesnake-lambda-1.0.jar | |
| deploy_app: | |
| name: 'Deploy | Deploy Application' | |
| runs-on: ubuntu-latest | |
| needs: [BootstrapBucketCreation, build_java] | |
| permissions: | |
| id-token: write | |
| contents: read | |
| defaults: | |
| run: | |
| working-directory: ./terraform/app | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download JAR Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: battlesnake-lambda-jar | |
| path: target | |
| - name: 'Configure AWS Credentials' | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-region: 'us-west-2' | |
| role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/GithubActionsRole | |
| role-session-name: github-action-terraform-deploy | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: 1.6.6 | |
| cli_config_credentials_token: ${{ secrets.TFE_API_TOKEN }} | |
| - name: Terraform Init with Dynamic Backend | |
| run: | | |
| WORKSPACE_NAME="${{ github.event.repository.name }}" | |
| echo "Workspace a ser criado/assegurado: $WORKSPACE_NAME" | |
| APP_TERRAFORM_KEY="app/${WORKSPACE_NAME}/terraform.tfstate" | |
| echo "Key para o bucket: $APP_TERRAFORM_KEY" | |
| terraform init \ | |
| -backend-config="bucket=${{ needs.BootstrapBucketCreation.outputs.s3_bucket_name }}" \ | |
| -backend-config="dynamodb_table=${{ needs.BootstrapBucketCreation.outputs.dynamo_table_name }}" \ | |
| -backend-config="key=$APP_TERRAFORM_KEY" | |
| - name: Terraform Apply | |
| run: | | |
| terraform apply -auto-approve \ | |
| -var="project_name=${{ github.event.repository.name }}" \ | |
| -var="environment=dev" \ |