Chore!: Move from TestMain to Test Suites #989
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
# This workflow splits the tests to run across multiple nodes. This significantly reduces the testing time, as the | |
# tests require starting Octopus, MSSQL, and then running Terraform against the Octopus instance. | |
# See # Refer to https://github.com/hashicorp-forge/go-test-split-action for more information on how the tests are split. | |
name: Tests | |
'on': | |
workflow_dispatch: {} | |
pull_request: | |
jobs: | |
tests: | |
name: Test | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
parallel: [ 3 ] | |
index: [ 0, 1, 2 ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Terraform | |
uses: hashicorp/setup-terraform@v2 | |
with: | |
terraform_wrapper: false | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install Python JWT module | |
run: pip install jwt | |
# In order to test git integration, we need a token generated from a JWT. | |
# The first step is to generate a JWT from the GitHub App private key. | |
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-a-json-web-token-jwt-for-a-github-app#example-using-python-to-generate-a-jwt | |
- name: Generate a JWT | |
run: ./github-app-jwt.py >> "$GITHUB_ENV" | |
env: | |
GH_APP_ID: ${{ secrets.GH_APP_ID }} | |
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }} | |
# The next step is to generate an access token from the JWT. | |
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app#generating-an-installation-access-token | |
- name: Generate an access token | |
run: | | |
curl \ | |
--silent \ | |
--request POST \ | |
--url "https://api.github.com/app/installations/${GH_APP_INSTALLATION_ID}/access_tokens" \ | |
--header "Accept: application/vnd.github+json" \ | |
--header "Authorization: Bearer ${{ env.jwt }}" \ | |
--header "X-GitHub-Api-Version: 2022-11-28" | jq -r '"GIT_CREDENTIAL=" + .token' > "$GITHUB_ENV" | |
env: | |
GH_APP_INSTALLATION_ID: ${{ secrets.GH_APP_INSTALLATION_ID }} | |
- name: Download JUnit Summary from Previous Workflow | |
id: download-artifact | |
uses: dawidd6/action-download-artifact@v2 | |
with: | |
workflow_conclusion: success | |
name: junit-test-summary | |
if_no_artifact_found: warn | |
branch: main | |
- name: Split tests | |
id: test_split | |
uses: hashicorp-forge/go-test-split-action@v1 | |
with: | |
index: ${{ matrix.index }} | |
total: ${{ matrix.parallel }} | |
junit-summary: ./junit-test-summary.xml | |
- name: Install Dependencies | |
run: go get ./... | |
shell: bash | |
- name: Build the Terraform provider from source | |
run: go build -o terraform-provider-octopusdeploy | |
- name: Override the location used by Terraform provider | |
run: |- | |
cat <<EOT >> ~/.terraformrc | |
provider_installation { | |
dev_overrides { | |
"octopusdeploylabs/octopusdeploy" = "${{ github.workspace }}" | |
} | |
direct {} | |
} | |
EOT | |
- name: Test | |
run: | | |
GOBIN=$PWD/bin go install gotest.tools/gotestsum@latest | |
./bin/gotestsum --junitfile node-summary.xml --format short-verbose -- -run "${{ steps.test_split.outputs.run }}" -timeout 0 ./... | |
shell: bash | |
env: | |
LICENSE: ${{ secrets.OCTOPUS_SERVER_BASE64_LICENSE }} | |
ECR_ACCESS_KEY: ${{ secrets.ECR_ACCESS_KEY }} | |
ECR_SECRET_KEY: ${{ secrets.ECR_SECRET_KEY }} | |
GIT_USERNAME: x-access-token | |
OCTODISABLEOCTOCONTAINERLOGGING: true | |
OCTOTESTSKIPINIT: true | |
GOMAXPROCS: 1 | |
OCTOTESTVERSION: latest | |
OCTOTESTIMAGEURL: docker.packages.octopushq.com/octopusdeploy/octopusdeploy | |
OCTOTESTRETRYCOUNT: 1 | |
TF_ACC: 1 | |
- name: Upload test artifacts | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: junit-test-summary-${{ matrix.index }} | |
path: node-summary.xml | |
retention-days: 1 | |
tests-combine-summaries: | |
if: always() | |
name: Combine Test Reports | |
needs: [ tests ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
- name: Install junit-report-merger | |
run: npm install -g junit-report-merger | |
- name: Merge reports | |
run: > | |
jrm ./junit-test-summary.xml | |
"junit-test-summary-0/*.xml" | |
"junit-test-summary-1/*.xml" | |
"junit-test-summary-2/*.xml" | |
- name: Upload test artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: junit-test-summary | |
path: ./junit-test-summary.xml | |
- name: Report | |
uses: dorny/test-reporter@v1 | |
with: | |
name: Go Tests | |
path: junit-test-summary.xml | |
reporter: java-junit | |
fail-on-error: 'true' | |
permissions: | |
id-token: write | |
checks: write | |
contents: write |