@@ -2,25 +2,36 @@ name: Integration Testing
22
33on :
44 workflow_dispatch :
5+ # Integration tests are slow, so only run them if relevant files have changed.
6+ # This is done at the workflow level and at the job level.
7+ # Make sure these triggers stay consistent with the 'changed-files' job.
58 push :
69 branches :
7- - " main"
10+ - ' main'
11+ - ' rc'
812 paths :
913 - " .github/workflows/integration-test.yml" # this file
10- - " src/services/ldap-directory.service*" # we only have integration for LDAP testing at the moment
11- - " ./utils/**/*" # any change to test fixtures
12- - " ./docker-compose.yml" # any change to Docker configuration
13- - " ./package.json" # dependencies
14+ - " docker-compose.yml" # any change to Docker configuration
15+ - " package.json" # dependencies
16+ - " utils/**" # any change to test fixtures
17+ - " src/services/sync.service.ts" # core sync service used by all directory services
18+ - " src/services/directory-services/ldap-directory.service*" # LDAP directory service
19+ - " src/services/directory-services/gsuite-directory.service*" # Google Workspace directory service
20+ # Add directory services here as we add test coverage
1421 pull_request :
1522 paths :
1623 - " .github/workflows/integration-test.yml" # this file
17- - " src/services/ldap-directory.service*" # we only have integration for LDAP testing at the moment
18- - " ./utils/**/*" # any change to test fixtures
19- - " ./docker-compose.yml" # any change to Docker configuration
20- - " ./package.json" # dependencies
24+ - " docker-compose.yml" # any change to Docker configuration
25+ - " package.json" # dependencies
26+ - " utils/**" # any change to test fixtures
27+ - " src/services/sync.service.ts" # core sync service used by all directory services
28+ - " src/services/directory-services/ldap-directory.service*" # LDAP directory service
29+ - " src/services/directory-services/gsuite-directory.service*" # Google Workspace directory service
30+ # Add directory services here as we add test coverage
2131permissions :
2232 contents : read
2333 checks : write # required by dorny/test-reporter to upload its results
34+ id-token : write # required to use OIDC to login to Azure Key Vault
2435jobs :
2536 testing :
2637 name : Run tests
@@ -50,23 +61,79 @@ jobs:
5061 - name : Install Node dependencies
5162 run : npm ci
5263
53- - name : Install mkcert
64+ # Get secrets from Azure Key Vault
65+ - name : Azure Login
66+ uses : bitwarden/gh-actions/azure-login@main
67+ with :
68+ subscription_id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
69+ tenant_id : ${{ secrets.AZURE_TENANT_ID }}
70+ client_id : ${{ secrets.AZURE_CLIENT_ID }}
71+
72+ - name : Get KV Secrets
73+ id : get-kv-secrets
74+ uses : bitwarden/gh-actions/get-keyvault-secrets@main
75+ with :
76+ keyvault : gh-directory-connector
77+ secrets : " GOOGLE-ADMIN-USER,GOOGLE-CLIENT-EMAIL,GOOGLE-DOMAIN,GOOGLE-PRIVATE-KEY"
78+
79+ - name : Azure Logout
80+ uses : bitwarden/gh-actions/azure-logout@main
81+
82+ # Only run relevant tests depending on what files have changed.
83+ # This should be kept consistent with the workflow level triggers.
84+ # Note: docker-compose.yml is only used for ldap for now
85+ - name : Get changed files
86+ id : changed-files
87+ uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
88+ with :
89+ list-files : shell
90+ token : ${{ secrets.GITHUB_TOKEN }}
91+ # Add directory services here as we add test coverage
92+ filters : |
93+ common:
94+ - '.github/workflows/integration-test.yml'
95+ - 'utils/**'
96+ - 'package.json'
97+ - 'src/services/sync.service.ts'
98+ ldap:
99+ - 'docker-compose.yml'
100+ - 'src/services/directory-services/ldap-directory.service*'
101+ google:
102+ - 'src/services/directory-services/gsuite-directory.service*'
103+
104+ # LDAP
105+ - name : Setup LDAP integration tests
106+ if : steps.changed-files.outputs.common == 'true' || steps.changed-files.outputs.ldap == 'true'
54107 run : |
55108 sudo apt-get update
56109 sudo apt-get -y install mkcert
57-
58- - name : Setup LDAP integration tests
59- run : npm run test:integration:setup
110+ npm run test:integration:setup
60111
61112 - name : Run LDAP integration tests
62- run : npx jest ldap-directory.service.integration.spec.ts --coverage
113+ if : steps.changed-files.outputs.common == 'true' || steps.changed-files.outputs.ldap == 'true'
114+ env :
115+ JEST_JUNIT_UNIQUE_OUTPUT_NAME : " true" # avoids junit outputs from clashing
116+ run : npx jest ldap-directory.service.integration.spec.ts --coverage --coverageDirectory=coverage-ldap
117+
118+ # Google Workspace
119+ - name : Run Google Workspace integration tests
120+ if : steps.changed-files.outputs.common == 'true' || steps.changed-files.outputs.google == 'true'
121+ env :
122+ GOOGLE_DOMAIN : ${{ steps.get-kv-secrets.outputs.GOOGLE-DOMAIN }}
123+ GOOGLE_ADMIN_USER : ${{ steps.get-kv-secrets.outputs.GOOGLE-ADMIN-USER }}
124+ GOOGLE_CLIENT_EMAIL : ${{ steps.get-kv-secrets.outputs.GOOGLE-CLIENT-EMAIL }}
125+ GOOGLE_PRIVATE_KEY : ${{ steps.get-kv-secrets.outputs.GOOGLE-PRIVATE-KEY }}
126+ JEST_JUNIT_UNIQUE_OUTPUT_NAME : " true" # avoids junit outputs from clashing
127+ run : |
128+ npx jest gsuite-directory.service.integration.spec.ts --coverage --coverageDirectory=coverage-google
63129
64130 - name : Report test results
131+ id : report
65132 uses : dorny/test-reporter@dc3a92680fcc15842eef52e8c4606ea7ce6bd3f3 # v2.1.1
66- if : ${{ github.event.pull_request.head.repo.full_name == github.repository && !cancelled() }}
133+ if : github.event.pull_request.head.repo.full_name == github.repository && !cancelled()
67134 with :
68135 name : Test Results
69- path : " junit.xml"
136+ path : " junit.xml* "
70137 reporter : jest-junit
71138 fail-on-error : true
72139
0 commit comments