Skip to content

Provider | Integration Tests #325

Provider | Integration Tests

Provider | Integration Tests #325

name: Provider | Integration Tests
run-name: Provider | Integration Tests
on:
workflow_dispatch:
inputs:
targets:
description: 'Specify targets to test'
type: string
required: false
default: 'compileonly'
pull_request_target:
types: [opened, synchronize]
paths:
- 'internal/**'
env:
PR: ${{ github.event_name == 'pull_request_target' }}
TARGETS: ${{ inputs.targets }}
jobs:
Run-Integration-Test:
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository }}/provider_testing:latest
environment: ${{ (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'workflow_dispatch') && 'provider-integration-testing-internal' || 'provider-integration-testing-external' }}
concurrency:
group: sandbox_interfacing_testing_environment
cancel-in-progress: false
env:
CLIENT_ID: ${{ secrets.TESTING_CLIENT_ID }}
CLIENT_SEC: ${{ secrets.TESTING_CLIENT_SECRET }}
CLIENT_FQDN: ${{ secrets.TESTING_JAMFPRO_INSTANCE_FQDN }}
REF_TO_CHECKOUT: ${{ github.event_name == 'pull_request_target' && format('refs/pull/{0}/head', github.event.pull_request.number) || github.ref }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
repository: deploymenttheory/terraform-provider-jamfpro
ref: ${{ env.REF_TO_CHECKOUT }}
- name: Compile Provider Binary
working-directory: .
run: |
mkdir -p ~/.terraform.d/plugins/terraform.local/local/jamfpro/0.1.0/linux_amd64/
go build -buildvcs=false
mv ./terraform-provider-jamfpro ~/.terraform.d/plugins/terraform.local/local/jamfpro/0.1.0/linux_amd64/
chmod +x ~/.terraform.d/plugins/terraform.local/local/jamfpro/0.1.0/linux_amd64/terraform-provider-jamfpro
- name: Generate Test Targets
id: generate-test-targets
if: github.event_name == 'pull_request_target' && env.TARGETS != 'compileonly'
working-directory: .
run: |
python3 testing/action_scripts/generate_test_targets.py \
--repo-owner ${{ github.repository_owner }} \
--repo-name ${{ github.event.repository.name }} \
--pr-number ${{ github.event.pull_request.number }} \
--github-token ${{ secrets.GITHUB_TOKEN }}
- name: Set Test Targets Var
id: set-targets
if: env.TARGETS != 'compileonly'
working-directory: .
run: |
if [ -f "targets.txt" ]; then
targets=$(cat targets.txt)
elif [ "$TARGETS" != "all" ] && [ ! -z "$TARGETS" ]; then
targets="$TARGETS"
else
targets="all"
fi
echo $targets
echo "targets=$targets" >> $GITHUB_OUTPUT
- name: Generate UUID
id: generate-uuid
if: env.TARGETS != 'compileonly'
run: |
generated_uuid=$(uuidgen)
echo "uuid=$generated_uuid" >> $GITHUB_OUTPUT
echo "Run ID: $generated_uuid"
- name: Populate Testing Directory
id: generate-test-dir
if: env.TARGETS != 'compileonly'
working-directory: .
run: |
python3 testing/action_scripts/generate_test_directory.py "${{ steps.set-targets.outputs.targets }}"
- name: Build TFVARS File
if: env.TARGETS != 'compileonly'
id: build-tfvars
working-directory: ./testing
run: |
cat <<EOF > terraform.tfvars
jamfpro_instance_fqdn="$CLIENT_FQDN"
jamfpro_auth_method="oauth2"
jamfpro_client_id="$CLIENT_ID"
jamfpro_client_secret="$CLIENT_SEC"
jamfpro_token_refresh_buffer_period_seconds="30"
jamfpro_mandatory_request_delay_milliseconds="100"
testing_id="${{ steps.generate-uuid.outputs.uuid }}"
EOF
- name: Run Tests
working-directory: ./testing
id: run-tests
run: |
chmod +x action_scripts/start_test.sh
action_scripts/start_test.sh "${{ steps.set-targets.outputs.targets }}" "${{ steps.generate-uuid.outputs.uuid }}"
- name: 5s Delay to Allow Jamf API to Settle
run: sleep 5
- name: Cleanup
if: env.TARGETS != 'compileonly'
id: cleanup
working-directory: ./testing
run: |
if [ -d "./data_sources" ]; then rm -rf ./data_sources; fi
python3 action_scripts/cleanup.py -r ${{ steps.generate-uuid.outputs.uuid }}