| 
 | 1 | +name: Main Branch and Release Testing  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  push:  | 
 | 5 | +    branches: ["main"]  | 
 | 6 | +    tags: ["v*.*.*"]  | 
 | 7 | +  # Allows manual testing  | 
 | 8 | +  workflow_dispatch:  | 
 | 9 | + | 
 | 10 | +# TODO:  | 
 | 11 | +# - Github env vars/secrets made available to this repo   | 
 | 12 | +# - CI.tfvars  | 
 | 13 | +# - Prepararing Environment statefile (can be simplified to use s3 state locking)  | 
 | 14 | +# - After full testing, uncomment slack channel status...? Or we don't want slack channel posts?  | 
 | 15 | + | 
 | 16 | +jobs:  | 
 | 17 | +  pre-commit:  | 
 | 18 | +    uses: ./.github/workflows/reusable-precommit.yml  | 
 | 19 | +      | 
 | 20 | +  release-tests:  | 
 | 21 | +    permissions:  | 
 | 22 | +      id-token: write  | 
 | 23 | +      contents: read  | 
 | 24 | +    runs-on: ubuntu-latest  | 
 | 25 | +    env:  | 
 | 26 | +      CI: true  | 
 | 27 | +      STAC_SERVER_TAG: v3.10.0  | 
 | 28 | +    steps:  | 
 | 29 | +      - uses: actions/checkout@v5  | 
 | 30 | + | 
 | 31 | +      - uses: actions/setup-node@v5  | 
 | 32 | +        with:  | 
 | 33 | +          node-version: "18"  | 
 | 34 | + | 
 | 35 | +      # Here we read the terraform version from the .terraform-version file, and then install that version  | 
 | 36 | +      - name: Get Terraform version  | 
 | 37 | +        id: tf_version  | 
 | 38 | +        run: |  | 
 | 39 | +          echo "value=$(cat .terraform-version)" >> $GITHUB_OUTPUT  | 
 | 40 | +      - uses: hashicorp/setup-terraform@v3  | 
 | 41 | +        with:  | 
 | 42 | +          terraform_version: ${{ steps.tf_version.outputs.value }}  | 
 | 43 | + | 
 | 44 | +      - name: Setting Pre-Requisites  | 
 | 45 | +        id: prereqs  | 
 | 46 | +        run: |  | 
 | 47 | +          echo "REPOSITORY_NAME=`echo \"${{  github.ref_name }}\" | tr -d '.' | cut -c1-8`" >> $GITHUB_ENV  | 
 | 48 | +
  | 
 | 49 | +      - name: Prepararing Environment  | 
 | 50 | +        id: prep_env  | 
 | 51 | +        run: |  | 
 | 52 | +          echo "environment = \"git\"" >> ci.tfvars  | 
 | 53 | +          echo "project_name = \"${REPOSITORY_NAME}\"" >> ci.tfvars  | 
 | 54 | +          cat ci.tfvars  | 
 | 55 | +          echo "Creating terraform backend file ..."  | 
 | 56 | +          echo 'terraform {' >> test.s3.backend.tf  | 
 | 57 | +          echo '  backend "s3" {' >> test.s3.backend.tf  | 
 | 58 | +          echo '    encrypt = true' >> test.s3.backend.tf  | 
 | 59 | +          echo "    bucket = \"${{ secrets.TF_STATE_BUCKET }}\"" >> test.s3.backend.tf  | 
 | 60 | +          echo "    dynamodb_table = \"${{ secrets.TF_STATE_LOCK_TABLE }}\"" >> test.s3.backend.tf  | 
 | 61 | +          echo "    key = \"${REPOSITORY_NAME}-github-test.tfstate\"" >> test.s3.backend.tf  | 
 | 62 | +          echo "    region = \"${{ secrets.AWS_REGION }}\"" >> test.s3.backend.tf  | 
 | 63 | +          echo '  }' >> test.s3.backend.tf  | 
 | 64 | +          echo '}' >> test.s3.backend.tf  | 
 | 65 | +          cat test.s3.backend.tf  | 
 | 66 | +
  | 
 | 67 | +      - name: Update stac-server lambdas  | 
 | 68 | +        id: update_stac_lambdas  | 
 | 69 | +        run: ./scripts/update-lambdas.bash  | 
 | 70 | + | 
 | 71 | +      - name: Configure Terraform Init Credentials  | 
 | 72 | +        id: init_creds  | 
 | 73 | +        uses: aws-actions/configure-aws-credentials@v4  | 
 | 74 | +        with:  | 
 | 75 | +          aws-region: ${{ secrets.AWS_REGION }}  | 
 | 76 | +          role-to-assume: ${{ secrets.AWS_ROLE }}  | 
 | 77 | +          role-session-name: GitHubReleaseInit  | 
 | 78 | + | 
 | 79 | +      - name: Terraform Init  | 
 | 80 | +        id: tf_init  | 
 | 81 | +        run: terraform init  | 
 | 82 | + | 
 | 83 | +      - name: Terraform Validate  | 
 | 84 | +        id: tf_validate  | 
 | 85 | +        run: terraform validate  | 
 | 86 | + | 
 | 87 | +      - name: Configure Terraform Plan Credentials  | 
 | 88 | +        id: plan_creds  | 
 | 89 | +        uses: aws-actions/configure-aws-credentials@v4  | 
 | 90 | +        with:  | 
 | 91 | +          aws-region: ${{ secrets.AWS_REGION }}  | 
 | 92 | +          role-to-assume: ${{ secrets.AWS_ROLE }}  | 
 | 93 | +          role-session-name: GitHubReleasePlan  | 
 | 94 | + | 
 | 95 | +      - name: Terraform Plan  | 
 | 96 | +        id: tf_plan  | 
 | 97 | +        run: terraform plan -var-file="ci.tfvars" -out test.tfplan -lock=false  | 
 | 98 | + | 
 | 99 | +      - name: Configure Terraform Apply Credentials  | 
 | 100 | +        id: apply_creds  | 
 | 101 | +        uses: aws-actions/configure-aws-credentials@v4  | 
 | 102 | +        with:  | 
 | 103 | +          aws-region: ${{ secrets.AWS_REGION }}  | 
 | 104 | +          role-to-assume: ${{ secrets.AWS_ROLE }}  | 
 | 105 | +          role-session-name: GitHubReleaseApply  | 
 | 106 | + | 
 | 107 | +      - name: Terraform Apply  | 
 | 108 | +        id: tf_apply  | 
 | 109 | +        continue-on-error: true  | 
 | 110 | +        run: terraform apply -lock=false -input=false test.tfplan  | 
 | 111 | + | 
 | 112 | +      # - name: Post status to Slack channel  | 
 | 113 | +      #   id: tf_apply_successs  | 
 | 114 | +      #   if: steps.tf_apply.outcome == 'success'  | 
 | 115 | +      #   continue-on-error: true  | 
 | 116 | +      #   uses: slackapi/[email protected]  | 
 | 117 | +      #   with:  | 
 | 118 | +      #     channel-id: ${{ secrets.SLACK_CHANNEL_ID }}  | 
 | 119 | +      #     slack-message: ":badger_dance: terraform-aws-stac-server - ${{  github.ref_name }} terraform apply job has succeeded!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"  | 
 | 120 | +      #   env:  | 
 | 121 | +      #     SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}  | 
 | 122 | + | 
 | 123 | +      # - name: Post status to Slack channel  | 
 | 124 | +      #   id: tf_apply_failure  | 
 | 125 | +      #   if: steps.tf_apply.outcome != 'success'  | 
 | 126 | +      #   continue-on-error: true  | 
 | 127 | +      #   uses: slackapi/[email protected]  | 
 | 128 | +      #   with:  | 
 | 129 | +      #     channel-id: ${{ secrets.SLACK_CHANNEL_ID }}  | 
 | 130 | +      #     slack-message: ":sadpanda: terraform-aws-stac-server -${{  github.ref_name }} terraform apply has failed!\n:alert: make sure cleanup job deletes all AWS resources!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"  | 
 | 131 | +      #   env:  | 
 | 132 | +      #     SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}  | 
 | 133 | + | 
 | 134 | +      - name: Configure Terraform Cleanup Check Credentials  | 
 | 135 | +        id: cleanup_check_creds  | 
 | 136 | +        if: always()  | 
 | 137 | +        uses: aws-actions/configure-aws-credentials@v4  | 
 | 138 | +        with:  | 
 | 139 | +          aws-region: ${{ secrets.AWS_REGION }}  | 
 | 140 | +          role-to-assume: ${{ secrets.AWS_ROLE }}  | 
 | 141 | +          role-session-name: GitHubReleaseCleanupCheck  | 
 | 142 | + | 
 | 143 | +      - name: Terraform Destroy Pre-Check  | 
 | 144 | +        id: tf_destroy_plan  | 
 | 145 | +        if: always()  | 
 | 146 | +        run: terraform plan -destroy -var-file="ci.tfvars" -out test-cleanup.tfplan -lock=false  | 
 | 147 | + | 
 | 148 | +      - name: Configure Terraform Cleanup Credentials  | 
 | 149 | +        id: cleanup_creds  | 
 | 150 | +        if: always()  | 
 | 151 | +        uses: aws-actions/configure-aws-credentials@v4  | 
 | 152 | +        with:  | 
 | 153 | +          aws-region: ${{ secrets.AWS_REGION }}  | 
 | 154 | +          role-to-assume: ${{ secrets.AWS_ROLE }}  | 
 | 155 | +          role-session-name: GitHubReleaseCleanup  | 
 | 156 | + | 
 | 157 | +      - name: Terraform Destroy  | 
 | 158 | +        id: tf_destroy_apply  | 
 | 159 | +        if: always()  | 
 | 160 | +        continue-on-error: true  | 
 | 161 | +        run: terraform apply -destroy -lock=false -input=false test-cleanup.tfplan  | 
 | 162 | + | 
 | 163 | +      # - name: Post status to Slack channel  | 
 | 164 | +      #   id: tf_destroy_apply_successs  | 
 | 165 | +      #   if: steps.tf_destroy_apply.outcome == 'success'  | 
 | 166 | +      #   continue-on-error: true  | 
 | 167 | +      #   uses: slackapi/[email protected]  | 
 | 168 | +      #   with:  | 
 | 169 | +      #     channel-id: ${{ secrets.SLACK_CHANNEL_ID }}  | 
 | 170 | +      #     slack-message: ":badger_dance: terraform-aws-stac-server - ${{  github.ref_name }} cleanup job has succeeded!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"  | 
 | 171 | +      #   env:  | 
 | 172 | +      #     SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}  | 
 | 173 | + | 
 | 174 | +      # - name: Post status to Slack channel  | 
 | 175 | +      #   id: tf_destroy_apply_failure  | 
 | 176 | +      #   if: steps.tf_destroy_apply.outcome != 'success'  | 
 | 177 | +      #   continue-on-error: true  | 
 | 178 | +      #   uses: slackapi/[email protected]  | 
 | 179 | +      #   with:  | 
 | 180 | +      #     channel-id: ${{ secrets.SLACK_CHANNEL_ID }}  | 
 | 181 | +      #     slack-message: ":sadpanda: terraform-aws-stac-server -${{  github.ref_name }} cleanup job has failed!\n:alert: make sure AWS resources are deleted!\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"  | 
 | 182 | +      #   env:  | 
 | 183 | +      #     SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}  | 
0 commit comments