Acceptance Tests #758
This file contains 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: Acceptance Tests | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
slashCommand: | |
name: SlashCommand | |
runs-on: ubuntu-latest | |
if: (github.event.issue.author_association == 'MEMBER') && | |
github.event.issue.pull_request && | |
startsWith(github.event.comment.body, '/testacc ') | |
steps: | |
- name: Extract Command | |
id: command | |
uses: xt0rted/slash-command-action@v2 | |
with: | |
repo-token: ${{ secrets.TESTACC_PAT }} | |
command: testacc | |
reaction: "true" | |
reaction-type: "rocket" | |
allow-edits: "false" | |
permission-level: write | |
test: | |
name: Terraform Provider Acceptance Tests | |
needs: slashCommand | |
runs-on: ubuntu-latest | |
timeout-minutes: 35 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: refs/pull/${{ github.event.issue.number }}/head | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.3.* | |
terraform_wrapper: false | |
- run: go mod download | |
- name : Run Terraform Acceptance Tests | |
env: | |
TF_ACC: "1" | |
CLOUDAVENUE_ORG: ${{ secrets.CLOUDAVENUE_ORG }} | |
CLOUDAVENUE_USER: ${{ secrets.CLOUDAVENUE_USER }} | |
CLOUDAVENUE_PASSWORD: ${{ secrets.CLOUDAVENUE_PASSWORD }} | |
CLOUDAVENUE_URL : ${{ secrets.CLOUDAVENUE_URL }} | |
CLOUDAVENUE_VDC : ${{ secrets.CLOUDAVENUE_VDC }} | |
run: | | |
TEST_NAME=$(echo "${{ github.event.comment.body }}" | cut -d " " -f2) | |
CATEGORY=$(grep -rilE "$TEST_NAME" * | sed 's![^/]*$!!' | head -1) | |
if [ -d "$CATEGORY" ]; then | |
go test -timeout 30m -v ./$CATEGORY -run $TEST_NAME > 'test_output.txt' | |
else | |
echo "[no tests to run]" > 'test_output.txt' | |
fi | |
timeout-minutes: 30 | |
- name: Comment PR with test results | |
uses: actions/[email protected] | |
if: always() # This ensures the step always runs, even if the test step failed | |
with: | |
github-token: ${{ secrets.TESTACC_PAT }} | |
script: | | |
const fs = require('fs'); | |
let output = fs.readFileSync('test_output.txt', 'utf8'); // Read the test output file | |
let comment = ""; | |
if (output.includes('[no tests to run]')) { | |
comment = "Ressource not found, please check the name of the ressource"; | |
} else if (output.includes('--- PASS')) { | |
comment = "## :rocket: Acceptance Test passed \n\n" + output; | |
} else { | |
comment = "## :bangbang: Acceptance Test failed \n\n" + output; | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment | |
}); |