diff --git a/.github/workflows/shared-terraform-chatops.yml b/.github/workflows/shared-terraform-chatops.yml index a0a0edf..3365e14 100644 --- a/.github/workflows/shared-terraform-chatops.yml +++ b/.github/workflows/shared-terraform-chatops.yml @@ -29,8 +29,8 @@ jobs: permission: run_terratest user: ${{ github.event.comment.user.login }} - pr: - name: PR Info + context: + name: Context needs: [access] if: ${{ needs.access.outputs.granted == 'true' }} runs-on: ${{ fromJSON(inputs.runs-on) }} @@ -40,6 +40,23 @@ jobs: with: id: ${{ github.event.issue.number }} + - uses: actions/github-script@v7 + id: properties + with: + result-encoding: string + script: | + const properites = await github.request('GET /repos/{owner}/{repo}/properties/values', { + owner: context.repo.owner, + repo: context.repo.repo, + headers: { + 'X-GitHub-Api-Version': '2022-11-28' + } + }) + + properites.data.forEach((element) => + core.setOutput(element.property_name, element.value) + ); + outputs: base: ${{ fromJSON(steps.pr.outputs.json).base.sha }} base_repo_owner: ${{ fromJSON(steps.pr.outputs.json).base.repo.owner.login }} @@ -57,22 +74,24 @@ jobs: merged_at: ${{ steps.pr.outputs.merged_at }} closed_at: ${{ steps.pr.outputs.closed_at }} labels: ${{ steps.pr.outputs.labels }} + terratest_aws_role: ${{ steps.properties.outputs.test-aws-role || 'arn:aws:iam::799847381734:role/cptest-test-ue2-sandbox-gha-iam-terratest' }} + terratest_skip_concurrency: ${{ steps.properties.outputs.test-skip-concurrency }} ack: if: github.event.comment.id != '' - needs: [pr] + needs: [context] runs-on: ${{ fromJSON(inputs.runs-on) }} steps: - name: "Add reaction" uses: peter-evans/create-or-update-comment@v4 with: - repository: ${{ needs.pr.outputs.base_repo_owner }}/${{ needs.pr.outputs.base_repo_name }} + repository: ${{ needs.context.outputs.base_repo_owner }}/${{ needs.context.outputs.base_repo_name }} comment-id: ${{ github.event.comment.id }} token: ${{ github.token }} reactions: '+1' pending: - needs: [pr] + needs: [context] runs-on: ${{ fromJSON(inputs.runs-on) }} steps: - name: "Update GitHub Status for pending" @@ -80,9 +99,9 @@ jobs: with: args: >- -action update_state - -ref "${{ needs.pr.outputs.head_sha }}" - -owner "${{ needs.pr.outputs.base_repo_owner }}" - -repo "${{ needs.pr.outputs.base_repo_name }}" + -ref "${{ needs.context.outputs.head_sha }}" + -owner "${{ needs.context.outputs.base_repo_owner }}" + -repo "${{ needs.context.outputs.base_repo_name }}" -state pending -context "test/terratest" -description "Tests started by @${{ github.actor }}" @@ -94,14 +113,14 @@ jobs: container: cloudposse/test-harness:latest runs-on: ${{ fromJSON(inputs.runs-on) }} environment: terratest - needs: [pr, pending] + needs: [context, pending] env: MAKE_INCLUDES: Makefile AWS_REGION: us-east-2 - AWS_ROLE_TO_ASSUME: arn:aws:iam::799847381734:role/cptest-test-ue2-sandbox-gha-iam-terratest + AWS_ROLE_TO_ASSUME: ${{ needs.context.outputs.terratest_aws_role }} continue-on-error: false strategy: - max-parallel: 10 + max-parallel: ${{ needs.context.outputs.terratest_skip_concurrency == 'true' && 1 || 10 }} fail-fast: false # Don't fail fast to avoid locking TF State matrix: platform: [terraform, opentofu] @@ -109,17 +128,17 @@ jobs: - name: "Checkout code for ChatOps" uses: actions/checkout@v4 with: - repository: ${{ needs.pr.outputs.head_repo_owner }}/${{ needs.pr.outputs.head_repo_name }} - ref: ${{ needs.pr.outputs.head_sha }} + repository: ${{ needs.context.outputs.head_repo_owner }}/${{ needs.context.outputs.head_repo_name }} + ref: ${{ needs.context.outputs.head_sha }} - name: "Update GitHub Status for pending" uses: docker://cloudposse/github-status-updater with: args: >- -action update_state - -ref "${{ needs.pr.outputs.head_sha }}" - -owner "${{ needs.pr.outputs.base_repo_owner }}" - -repo "${{ needs.pr.outputs.base_repo_name }}" + -ref "${{ needs.context.outputs.head_sha }}" + -owner "${{ needs.context.outputs.base_repo_owner }}" + -repo "${{ needs.context.outputs.base_repo_name }}" -state pending -context "test/terratest/${{ matrix.platform }}" -description "Tests started by @${{ github.actor }}" @@ -167,8 +186,8 @@ jobs: fi env: # Pull request target branch - BASE_REF: ${{ needs.pr.outputs.base }} - LABELS: ${{ needs.pr.outputs.labels }} + BASE_REF: ${{ needs.context.outputs.base }} + LABELS: ${{ needs.context.outputs.labels }} - name: "Determine required opentofu version" if: ${{ matrix.platform == 'opentofu' }} @@ -183,8 +202,8 @@ jobs: fi env: # Pull request target branch - BASE_REF: ${{ needs.pr.outputs.base }} - LABELS: ${{ needs.pr.outputs.labels }} + BASE_REF: ${{ needs.context.outputs.base }} + LABELS: ${{ needs.context.outputs.labels }} - name: "Initialize terratest Go project" run: | @@ -196,26 +215,26 @@ jobs: id: config env: USES_GITHUB: >- - ${{ contains(needs.pr.outputs.base_repo_name, '-github-') - || contains(needs.pr.outputs.labels, 'terraform-github-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, '-github-') + || contains(needs.context.outputs.labels, 'terraform-github-provider') }} USES_OPSGENIE: >- - ${{ contains(needs.pr.outputs.base_repo_name, 'terraform-opsgenie-') - || contains(needs.pr.outputs.labels, 'terraform-opsgenie-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, 'terraform-opsgenie-') + || contains(needs.context.outputs.labels, 'terraform-opsgenie-provider') }} USES_AWS: >- - ${{ contains(needs.pr.outputs.base_repo_name, 'terraform-aws-') - || contains(needs.pr.outputs.labels, 'terraform-aws-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, 'terraform-aws-') + || contains(needs.context.outputs.labels, 'terraform-aws-provider') }} USES_SPOTINST: >- - ${{ contains(needs.pr.outputs.base_repo_name, '-spotinst-') - || contains(needs.pr.outputs.labels, 'terraform-spotinst-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, '-spotinst-') + || contains(needs.context.outputs.labels, 'terraform-spotinst-provider') }} USES_DATADOG: >- - ${{ contains(needs.pr.outputs.base_repo_name, '-datadog-') - || contains(needs.pr.outputs.labels, 'terraform-datadog-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, '-datadog-') + || contains(needs.context.outputs.labels, 'terraform-datadog-provider') }} USES_TFE: >- - ${{ contains(needs.pr.outputs.base_repo_name, '-tfe-') - || contains(needs.pr.outputs.labels, 'terraform-tfe-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, '-tfe-') + || contains(needs.context.outputs.labels, 'terraform-tfe-provider') }} USES_CLOUDFLARE: >- - ${{ contains(needs.pr.outputs.base_repo_name, '-cloudflare-') - || contains(needs.pr.outputs.labels, 'terraform-cloudflare-provider') }} + ${{ contains(needs.context.outputs.base_repo_name, '-cloudflare-') + || contains(needs.context.outputs.labels, 'terraform-cloudflare-provider') }} run: |- echo "uses_github=${USES_GITHUB}" >> $GITHUB_OUTPUT echo "uses_opsgenie=${USES_OPSGENIE}" >> $GITHUB_OUTPUT @@ -295,9 +314,9 @@ jobs: with: args: >- -action update_state - -ref "${{ needs.pr.outputs.head_sha }}" - -owner "${{ needs.pr.outputs.base_repo_owner }}" - -repo "${{ needs.pr.outputs.base_repo_name }}" + -ref "${{ needs.context.outputs.head_sha }}" + -owner "${{ needs.context.outputs.base_repo_owner }}" + -repo "${{ needs.context.outputs.base_repo_name }}" -state failure -context "test/terratest/${{ matrix.platform }}" -description "Tests failed" @@ -310,9 +329,9 @@ jobs: with: args: >- -action update_state - -ref "${{ needs.pr.outputs.head_sha }}" - -owner "${{ needs.pr.outputs.base_repo_owner }}" - -repo "${{ needs.pr.outputs.base_repo_name }}" + -ref "${{ needs.context.outputs.head_sha }}" + -owner "${{ needs.context.outputs.base_repo_owner }}" + -repo "${{ needs.context.outputs.base_repo_name }}" -state success -context "test/terratest/${{ matrix.platform }}" -description "Tests passed" @@ -326,9 +345,9 @@ jobs: with: args: >- -action update_state - -ref "${{ needs.pr.outputs.head_sha }}" - -owner "${{ needs.pr.outputs.base_repo_owner }}" - -repo "${{ needs.pr.outputs.base_repo_name }}" + -ref "${{ needs.context.outputs.head_sha }}" + -owner "${{ needs.context.outputs.base_repo_owner }}" + -repo "${{ needs.context.outputs.base_repo_name }}" -state error -context "test/terratest/${{ matrix.platform }}" -description "Tests cancelled" @@ -338,8 +357,8 @@ jobs: finalize: runs-on: ${{ fromJSON(inputs.runs-on) }} - needs: [terratest, pr] - if: ${{ always() && needs.pr.result != 'skipped' }} + needs: [terratest, context] + if: ${{ always() && needs.context.result != 'skipped' }} steps: - shell: bash id: status @@ -362,9 +381,9 @@ jobs: with: args: >- -action update_state - -ref "${{ needs.pr.outputs.head_sha }}" - -owner "${{ needs.pr.outputs.base_repo_owner }}" - -repo "${{ needs.pr.outputs.base_repo_name }}" + -ref "${{ needs.context.outputs.head_sha }}" + -owner "${{ needs.context.outputs.base_repo_owner }}" + -repo "${{ needs.context.outputs.base_repo_name }}" -state ${{ steps.status.outputs.result }} -context "test/terratest" -description "Tests started by @${{ github.actor }}"