Skip to content

Commit 21cabaa

Browse files
committed
Improve testing
1 parent ca883e6 commit 21cabaa

4 files changed

Lines changed: 239 additions & 26 deletions

File tree

.github/workflows/test.yml

Lines changed: 179 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ on:
1414
jobs:
1515
test:
1616
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
test-scenario: [
20+
'valid-credentials',
21+
'invalid-api-key',
22+
'invalid-organization',
23+
'non-existent-application',
24+
'feature-branch',
25+
'tag-deployment'
26+
]
1727
steps:
1828
- uses: actions/checkout@v4
1929

@@ -34,25 +44,181 @@ jobs:
3444
ls -la dist/
3545
cat action.yml
3646
37-
- name: Test Quant Cloud Init Action
47+
- name: Test Valid Credentials
48+
if: matrix.test-scenario == 'valid-credentials'
3849
uses: ./
39-
id: init
50+
id: init-valid
4051
with:
4152
quant_api_key: ${{ secrets.QUANT_API_KEY }}
4253
quant_organization: 'quant'
4354
base_url: 'https://portal.stage.quantcdn.io/api/v3'
55+
continue-on-error: false
4456

45-
- name: Debug Outputs
57+
- name: Test Invalid API Key (Expected Failure)
58+
if: matrix.test-scenario == 'invalid-api-key'
59+
uses: ./
60+
id: init-invalid-key
61+
with:
62+
quant_api_key: 'invalid-key-12345'
63+
quant_organization: 'quant'
64+
base_url: 'https://portal.stage.quantcdn.io/api/v3'
65+
continue-on-error: true
66+
67+
- name: Test Invalid Organization (Expected Failure)
68+
if: matrix.test-scenario == 'invalid-organization'
69+
uses: ./
70+
id: init-invalid-org
71+
with:
72+
quant_api_key: ${{ secrets.QUANT_API_KEY }}
73+
quant_organization: 'non-existent-org-12345'
74+
base_url: 'https://portal.stage.quantcdn.io/api/v3'
75+
continue-on-error: true
76+
77+
- name: Test Non-Existent Application (Expected Warning)
78+
if: matrix.test-scenario == 'non-existent-application'
79+
uses: ./
80+
id: init-no-app
81+
with:
82+
quant_api_key: ${{ secrets.QUANT_API_KEY }}
83+
quant_organization: 'quant'
84+
quant_application: 'non-existent-app-12345'
85+
base_url: 'https://portal.stage.quantcdn.io/api/v3'
86+
continue-on-error: false
87+
88+
- name: Test Feature Branch Detection
89+
if: matrix.test-scenario == 'feature-branch'
90+
uses: ./
91+
id: init-feature
92+
with:
93+
quant_api_key: ${{ secrets.QUANT_API_KEY }}
94+
quant_organization: 'quant'
95+
base_url: 'https://portal.stage.quantcdn.io/api/v3'
96+
env:
97+
GITHUB_REF: 'refs/heads/feature/test-branch'
98+
GITHUB_REPOSITORY: 'quant/test-repo'
99+
continue-on-error: false
100+
101+
- name: Test Tag Deployment Detection
102+
if: matrix.test-scenario == 'tag-deployment'
103+
uses: ./
104+
id: init-tag
105+
with:
106+
quant_api_key: ${{ secrets.QUANT_API_KEY }}
107+
quant_organization: 'quant'
108+
base_url: 'https://portal.stage.quantcdn.io/api/v3'
109+
env:
110+
GITHUB_REF: 'refs/tags/v1.0.0'
111+
GITHUB_REPOSITORY: 'quant/test-repo'
112+
continue-on-error: false
113+
114+
- name: Validate Valid Credentials Outputs
115+
if: matrix.test-scenario == 'valid-credentials'
116+
run: |
117+
echo "=== VALID CREDENTIALS TEST RESULTS ==="
118+
echo "Project exists: ${{ steps.init-valid.outputs.project_exists }}"
119+
echo "Environment exists: ${{ steps.init-valid.outputs.environment_exists }}"
120+
echo "Application: ${{ steps.init-valid.outputs.quant_application }}"
121+
echo "Environment: ${{ steps.init-valid.outputs.environment_name }}"
122+
echo "Is production: ${{ steps.init-valid.outputs.is_production }}"
123+
echo "Stripped endpoint: ${{ steps.init-valid.outputs.stripped_endpoint }}"
124+
125+
# Validate expected values
126+
if [[ "${{ steps.init-valid.outputs.environment_name }}" != "production" ]]; then
127+
echo "❌ Expected environment 'production', got '${{ steps.init-valid.outputs.environment_name }}'"
128+
exit 1
129+
fi
130+
if [[ "${{ steps.init-valid.outputs.is_production }}" != "true" ]]; then
131+
echo "❌ Expected is_production 'true', got '${{ steps.init-valid.outputs.is_production }}'"
132+
exit 1
133+
fi
134+
echo "✅ Valid credentials test passed"
135+
136+
- name: Validate Invalid API Key Failure
137+
if: matrix.test-scenario == 'invalid-api-key'
138+
run: |
139+
echo "=== INVALID API KEY TEST RESULTS ==="
140+
if [[ "${{ steps.init-invalid-key.outcome }}" == "failure" ]]; then
141+
echo "✅ Invalid API key correctly failed as expected"
142+
else
143+
echo "❌ Invalid API key should have failed but didn't"
144+
exit 1
145+
fi
146+
147+
- name: Validate Invalid Organization Failure
148+
if: matrix.test-scenario == 'invalid-organization'
149+
run: |
150+
echo "=== INVALID ORGANIZATION TEST RESULTS ==="
151+
if [[ "${{ steps.init-invalid-org.outcome }}" == "failure" ]]; then
152+
echo "✅ Invalid organization correctly failed as expected"
153+
else
154+
echo "❌ Invalid organization should have failed but didn't"
155+
exit 1
156+
fi
157+
158+
- name: Validate Non-Existent Application Warning
159+
if: matrix.test-scenario == 'non-existent-application'
160+
run: |
161+
echo "=== NON-EXISTENT APPLICATION TEST RESULTS ==="
162+
echo "Project exists: ${{ steps.init-no-app.outputs.project_exists }}"
163+
echo "Application: ${{ steps.init-no-app.outputs.quant_application }}"
164+
165+
if [[ "${{ steps.init-no-app.outputs.project_exists }}" == "false" ]]; then
166+
echo "✅ Non-existent application correctly identified as not existing"
167+
else
168+
echo "❌ Non-existent application should show project_exists=false"
169+
exit 1
170+
fi
171+
if [[ "${{ steps.init-no-app.outputs.quant_application }}" == "non-existent-app-12345" ]]; then
172+
echo "✅ Application name correctly set to provided value"
173+
else
174+
echo "❌ Application name should match provided value"
175+
exit 1
176+
fi
177+
echo "✅ Non-existent application test passed"
178+
179+
- name: Validate Feature Branch Detection
180+
if: matrix.test-scenario == 'feature-branch'
181+
run: |
182+
echo "=== FEATURE BRANCH TEST RESULTS ==="
183+
echo "Environment: ${{ steps.init-feature.outputs.environment_name }}"
184+
echo "Is production: ${{ steps.init-feature.outputs.is_production }}"
185+
186+
if [[ "${{ steps.init-feature.outputs.environment_name }}" != "feature" ]]; then
187+
echo "❌ Expected environment 'feature', got '${{ steps.init-feature.outputs.environment_name }}'"
188+
exit 1
189+
fi
190+
if [[ "${{ steps.init-feature.outputs.is_production }}" != "false" ]]; then
191+
echo "❌ Expected is_production 'false', got '${{ steps.init-feature.outputs.is_production }}'"
192+
exit 1
193+
fi
194+
echo "✅ Feature branch detection test passed"
195+
196+
- name: Validate Tag Deployment Detection
197+
if: matrix.test-scenario == 'tag-deployment'
46198
run: |
47-
echo "Project exists: ${{ steps.init.outputs.project_exists }}"
48-
echo "Environment exists: ${{ steps.init.outputs.environment_exists }}"
49-
echo "Application: ${{ steps.init.outputs.quant_application }}"
50-
echo "Environment: ${{ steps.init.outputs.environment_name }}"
51-
echo "Is production: ${{ steps.init.outputs.is_production }}"
52-
echo "Stripped endpoint: ${{ steps.init.outputs.stripped_endpoint }}"
199+
echo "=== TAG DEPLOYMENT TEST RESULTS ==="
200+
echo "Environment: ${{ steps.init-tag.outputs.environment_name }}"
201+
echo "Is production: ${{ steps.init-tag.outputs.is_production }}"
202+
203+
if [[ "${{ steps.init-tag.outputs.environment_name }}" != "production" ]]; then
204+
echo "❌ Expected environment 'production', got '${{ steps.init-tag.outputs.environment_name }}'"
205+
exit 1
206+
fi
207+
if [[ "${{ steps.init-tag.outputs.is_production }}" != "true" ]]; then
208+
echo "❌ Expected is_production 'true', got '${{ steps.init-tag.outputs.is_production }}'"
209+
exit 1
210+
fi
211+
echo "✅ Tag deployment detection test passed"
53212
54-
- name: Verify Docker Login
213+
- name: Test Summary
55214
run: |
56-
echo "Testing if Docker is logged into the registry..."
57-
docker info
58-
echo "✅ Docker login verification completed"
215+
echo "=== TEST SUMMARY ==="
216+
echo "Test scenario: ${{ matrix.test-scenario }}"
217+
echo "Job status: ${{ job.status }}"
218+
echo "Step outcomes:"
219+
echo " - Valid credentials: ${{ steps.init-valid.outcome || 'N/A' }}"
220+
echo " - Invalid API key: ${{ steps.init-invalid-key.outcome || 'N/A' }}"
221+
echo " - Invalid org: ${{ steps.init-invalid-org.outcome || 'N/A' }}"
222+
echo " - Non-existent app: ${{ steps.init-no-app.outcome || 'N/A' }}"
223+
echo " - Feature branch: ${{ steps.init-feature.outcome || 'N/A' }}"
224+
echo " - Tag deployment: ${{ steps.init-tag.outcome || 'N/A' }}"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A GitHub Action for initializing Quant Cloud deployments with environment detect
66

77
- **Automatic Environment Detection**: Automatically determines environment names based on branch names
88
- **Registry Authentication**: Handles Quant Cloud Image Registry login and **automatically logs into Docker registry**
9-
- **Project Validation**: Validates organization and API key before proceeding
9+
- **Comprehensive Validation**: Validates organization, API key, and application existence in Quant Cloud
1010
- **Smart Branch Handling**: Supports main/master, develop, feature branches, and tags
1111
- **Flexible Configuration**: Allows overrides for application names, master branches, and environment names
1212
- **Seamless Integration**: No need for separate Docker login steps in your workflow

dist/index.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63535,12 +63535,7 @@ async function dockerLogin(endpoint, username, password) {
6353563535
*/
6353663536
async function run() {
6353763537
const apiKey = core.getInput('quant_api_key', { required: true });
63538-
// Handle both spellings for backward compatibility
63539-
let organization = core.getInput('quant_organization', { required: false });
63540-
if (!organization) {
63541-
organization = core.getInput('quant_organisation', { required: true });
63542-
core.info('Using quant_organisation (backward compatibility)');
63543-
}
63538+
const organization = core.getInput('quant_organization', { required: true });
6354463539
const applicationOverride = core.getInput('quant_application', { required: false });
6354563540
const masterBranchOverride = core.getInput('master_branch_override', { required: false });
6354663541
const environmentNameOverride = core.getInput('environment_name_override', { required: false });
@@ -63604,22 +63599,48 @@ async function run() {
6360463599
let environmentExists = false;
6360563600
try {
6360663601
core.info(`Validating organization and API key for ${organization}...`);
63602+
// First, check if the organization exists by trying to list applications
63603+
try {
63604+
core.info(`Checking if organization '${organization}' exists...`);
63605+
const applications = await applicationsClient.listApplications(organization);
63606+
core.info(`✅ Organization '${organization}' exists and is accessible`);
63607+
}
63608+
catch (orgError) {
63609+
const errorMessage = orgError instanceof Error ? orgError.message : 'Unknown error';
63610+
core.setFailed(`Organization '${organization}' does not exist or is not accessible: ${errorMessage}`);
63611+
return;
63612+
}
6360763613
// Try to get Quant Cloud Image Registry credentials as a validation step
63614+
core.info(`Attempting to get registry credentials for organization: ${organization}`);
6360863615
const registryToken = await applicationsClient.getEcrLoginCredentials(organization);
6360963616
if (registryToken.body && registryToken.body.password) {
63610-
projectExists = true;
63611-
core.info('✅ Organization and API key validation successful');
63617+
core.info('✅ Registry credentials retrieved successfully');
63618+
core.info(`Registry endpoint: ${registryToken.body.endpoint}`);
6361263619
}
6361363620
else {
6361463621
core.setFailed('No Quant Cloud Image Registry credentials found - organization may not exist or API key may be invalid');
6361563622
return;
6361663623
}
63624+
// Now check if the specific application exists
63625+
try {
63626+
core.info(`Checking if application '${applicationName}' exists in organization '${organization}'...`);
63627+
const application = await applicationsClient.getApplication(organization, applicationName);
63628+
projectExists = true;
63629+
core.info(`✅ Application '${applicationName}' exists in Quant Cloud`);
63630+
}
63631+
catch (appError) {
63632+
const errorMessage = appError instanceof Error ? appError.message : 'Unknown error';
63633+
core.warning(`Application '${applicationName}' does not exist yet in Quant Cloud - this is normal for new projects`);
63634+
core.info(`You can create this application in the Quant Cloud dashboard or it will be created automatically on first deployment`);
63635+
projectExists = false;
63636+
}
6361763637
// Check if environment exists (optional - won't fail if it doesn't)
6361863638
try {
6361963639
// This would need to be implemented based on your Quant Cloud API
6362063640
// For now, we'll assume it exists if we can get registry credentials
63641+
// Note: This is a simplified check - in reality, you'd want to validate against actual environments
6362163642
environmentExists = true;
63622-
core.info(`✅ Environment ${environmentName} validation successful`);
63643+
core.info(`✅ Environment ${environmentName} validation successful (simplified check)`);
6362363644
}
6362463645
catch (envError) {
6362563646
core.warning(`Environment ${environmentName} may not exist yet - this is normal for new projects`);

src/index.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,49 @@ async function run() {
179179
try {
180180
core.info(`Validating organization and API key for ${organization}...`);
181181

182+
// First, check if the organization exists by trying to list applications
183+
try {
184+
core.info(`Checking if organization '${organization}' exists...`);
185+
const applications = await applicationsClient.listApplications(organization);
186+
core.info(`✅ Organization '${organization}' exists and is accessible`);
187+
} catch (orgError) {
188+
const errorMessage = orgError instanceof Error ? orgError.message : 'Unknown error';
189+
core.setFailed(`Organization '${organization}' does not exist or is not accessible: ${errorMessage}`);
190+
return;
191+
}
192+
182193
// Try to get Quant Cloud Image Registry credentials as a validation step
194+
core.info(`Attempting to get registry credentials for organization: ${organization}`);
183195
const registryToken = await applicationsClient.getEcrLoginCredentials(organization);
184196

185197
if (registryToken.body && registryToken.body.password) {
186-
projectExists = true;
187-
core.info('✅ Organization and API key validation successful');
198+
core.info('✅ Registry credentials retrieved successfully');
199+
core.info(`Registry endpoint: ${registryToken.body.endpoint}`);
188200
} else {
189201
core.setFailed('No Quant Cloud Image Registry credentials found - organization may not exist or API key may be invalid');
190202
return;
191203
}
192204

205+
// Now check if the specific application exists
206+
try {
207+
core.info(`Checking if application '${applicationName}' exists in organization '${organization}'...`);
208+
const application = await applicationsClient.getApplication(organization, applicationName);
209+
projectExists = true;
210+
core.info(`✅ Application '${applicationName}' exists in Quant Cloud`);
211+
} catch (appError) {
212+
const errorMessage = appError instanceof Error ? appError.message : 'Unknown error';
213+
core.warning(`Application '${applicationName}' does not exist yet in Quant Cloud - this is normal for new projects`);
214+
core.info(`You can create this application in the Quant Cloud dashboard or it will be created automatically on first deployment`);
215+
projectExists = false;
216+
}
217+
193218
// Check if environment exists (optional - won't fail if it doesn't)
194219
try {
195220
// This would need to be implemented based on your Quant Cloud API
196221
// For now, we'll assume it exists if we can get registry credentials
222+
// Note: This is a simplified check - in reality, you'd want to validate against actual environments
197223
environmentExists = true;
198-
core.info(`✅ Environment ${environmentName} validation successful`);
224+
core.info(`✅ Environment ${environmentName} validation successful (simplified check)`);
199225
} catch (envError) {
200226
core.warning(`Environment ${environmentName} may not exist yet - this is normal for new projects`);
201227
environmentExists = false;

0 commit comments

Comments
 (0)