Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 4 additions & 40 deletions .github/actions/perform_smoke_test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,6 @@ runs:
--token ${{ inputs.staging-api-token }} \
--test-collection-id Gtnr7BWl # analytics-cli-repo-wide: https://app.trunk-staging.io/trunk-staging-org/flaky-tests/collections/Gtnr7BWl/monitors

- name: Upload to staging from a forked pull request
id: staging-upload-forked-pr
if: always() && steps.staging-test-run.outcome == 'success' && (inputs.environment-type == 'staging' || inputs.environment-type == 'both')
env:
TRUNK_PUBLIC_API_ADDRESS: https://api.trunk-staging.io
shell: bash
run: |
./${{ inputs.cli-binary-location }} upload \
--org-url-slug trunk-staging-org \
--junit-paths "${{ github.workspace }}/target/**/*junit.xml" \
--allow-forked-pr-uploads \
--use-uncloned-repo \
--repo-url https://github.com/trunk-io/flake-farm-staging-fork-prs.git \
--repo-head-sha ${{ github.sha }} \
--repo-head-branch refs/heads/main \
--repo-head-author-name "Trunk Smoke Test" \
--test-collection-id z2dzjLHm

Comment thread
acatxnamedvirtue marked this conversation as resolved.
Resolved
# upload with variant should fail because we treat variant as a separate test
- name: Upload to staging with variant
id: staging-upload-with-variant
Expand Down Expand Up @@ -171,9 +153,9 @@ runs:
shell: bash
run: |
if [ "${{ inputs.test-variants }}" == "true" ]; then
echo "staging-success=${{ (steps.staging-upload.outcome == 'success' && steps.staging-upload-repo-wide.outcome == 'success' && steps.staging-upload-forked-pr.outcome == 'success' && steps.staging-upload-with-variant.outcome == 'success' && (inputs.environment-type == 'staging' || inputs.environment-type == 'both')) || inputs.environment-type == 'production' }}" >> $GITHUB_OUTPUT
echo "staging-success=${{ (steps.staging-upload.outcome == 'success' && steps.staging-upload-repo-wide.outcome == 'success' && steps.staging-upload-with-variant.outcome == 'success' && (inputs.environment-type == 'staging' || inputs.environment-type == 'both')) || inputs.environment-type == 'production' }}" >> $GITHUB_OUTPUT
else
echo "staging-success=${{ (steps.staging-upload.outcome == 'success' && steps.staging-upload-repo-wide.outcome == 'success' && steps.staging-upload-forked-pr.outcome == 'success' && (inputs.environment-type == 'staging' || inputs.environment-type == 'both')) || inputs.environment-type == 'production' }}" >> $GITHUB_OUTPUT
echo "staging-success=${{ (steps.staging-upload.outcome == 'success' && steps.staging-upload-repo-wide.outcome == 'success' && (inputs.environment-type == 'staging' || inputs.environment-type == 'both')) || inputs.environment-type == 'production' }}" >> $GITHUB_OUTPUT
fi

- name: Run tests on production
Expand Down Expand Up @@ -230,24 +212,6 @@ runs:
--token ${{ inputs.production-api-token }} \
--test-collection-id 4B2wfoEU

- name: Upload to production from a forked pull request
id: production-upload-forked-pr
if: always() && steps.production-test-run.outcome == 'success' && (inputs.environment-type == 'production' || inputs.environment-type == 'both')
env:
TRUNK_PUBLIC_API_ADDRESS: https://api.trunk.io
shell: bash
run: |
./${{ inputs.cli-binary-location }} upload \
--org-url-slug trunk \
--junit-paths "${{ github.workspace }}/target/**/*junit.xml" \
--allow-forked-pr-uploads \
--use-uncloned-repo \
--repo-url https://github.com/trunk-io/flake-farm-staging-fork-prs.git \
--repo-head-sha ${{ github.sha }} \
--repo-head-branch refs/heads/main \
--repo-head-author-name "Trunk Smoke Test" \
--test-collection-id 4B2wfoEU

Comment thread
acatxnamedvirtue marked this conversation as resolved.
Resolved
# upload with variant should fail because we treat variant as a separate test
- name: Upload to production with variant
id: production-upload-with-variant
Expand Down Expand Up @@ -278,7 +242,7 @@ runs:
shell: bash
run: |
if [ "${{ inputs.test-variants }}" == "true" ]; then
echo "production-success=${{ (steps.production-upload.outcome == 'success' && steps.production-upload-forked-pr.outcome == 'success' && steps.production-upload-with-variant.outcome == 'success' && (inputs.environment-type == 'production' || inputs.environment-type == 'both')) || inputs.environment-type == 'staging' }}" >> $GITHUB_OUTPUT
echo "production-success=${{ (steps.production-upload.outcome == 'success' && steps.production-upload-with-variant.outcome == 'success' && (inputs.environment-type == 'production' || inputs.environment-type == 'both')) || inputs.environment-type == 'staging' }}" >> $GITHUB_OUTPUT
else
echo "production-success=${{ (steps.production-upload.outcome == 'success' && steps.production-upload-forked-pr.outcome == 'success' && (inputs.environment-type == 'production' || inputs.environment-type == 'both')) || inputs.environment-type == 'staging' }}" >> $GITHUB_OUTPUT
echo "production-success=${{ (steps.production-upload.outcome == 'success' && (inputs.environment-type == 'production' || inputs.environment-type == 'both')) || inputs.environment-type == 'staging' }}" >> $GITHUB_OUTPUT
fi
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ You can generate sample junit files by running
cargo run --bin junit-mock .
```

You can change the API endpoint by setting `TRUNK_PUBLIC_API_ADDRESS=https://api.trunk.io`. To use localhost, you should use `TRUNK_PUBLIC_API_ADDRESS=http://localhost:9010 DEBUG_STRIP_VERSION_PREFIX=true`
You can change the API endpoint by setting `TRUNK_PUBLIC_API_ADDRESS=https://api.trunk.io`. The CLI calls only the Trunk API v2 routes under it (`/v2/test-collections/...`). To use localhost, use `TRUNK_PUBLIC_API_ADDRESS=http://localhost:9010`.

## Test

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions api/src/call_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use http::StatusCode;
use tokio::time::{self, Instant};
use tokio_retry::{Action, strategy::ExponentialBackoff};

use crate::client::{NOT_FOUND_CONTEXT, UNAUTHORIZED_CONTEXT};
use crate::client::UNAUTHORIZED_CONTEXT;

// Tokio-retry uses base ^ retry * factor formula.
// This will give us 2s, 4s, 8s, 16s, 32s
Expand Down Expand Up @@ -104,7 +104,6 @@ impl AbortableRetry for anyhow::Error {
fn should_retry(&self) -> bool {
let self_text = format!("{self}");
!self_text.contains(UNAUTHORIZED_CONTEXT)
&& !self_text.contains(NOT_FOUND_CONTEXT)
&& self.chain().fold(true, |acc: bool, cause| {
let cause_should_retry =
if let Some(reqwest_error) = cause.downcast_ref::<reqwest::Error>() {
Expand Down Expand Up @@ -280,7 +279,7 @@ mod tests {
RETRY_COUNT_DEFAULT, retry_with_deadline,
};
use crate::client::{
CheckNotFound, CheckUnauthorized, ClientErrorExplanation, StatusCodeHelp, status_code_help,
CheckUnauthorized, ClientErrorExplanation, StatusCodeHelp, status_code_help,
};
#[derive(Debug, Serialize, Clone, Deserialize, PartialEq, Eq)]
struct EmptyResponse {}
Expand Down Expand Up @@ -476,7 +475,6 @@ mod tests {
response,
StatusCodeHelp {
check_unauthorized: CheckUnauthorized::DoNotCheck,
check_not_found: CheckNotFound::Check,
create_error_message: |_e| String::from("Test message"),
api_host: "mock_host",
org_url_slug: "mock_url_slug",
Expand All @@ -503,7 +501,6 @@ mod tests {
Response::from(http_response),
StatusCodeHelp {
check_unauthorized: CheckUnauthorized::Check,
check_not_found: CheckNotFound::Check,
create_error_message: |_e| String::from("Test message"),
api_host: "mock_host",
org_url_slug: "mock_url_slug",
Expand All @@ -519,7 +516,7 @@ mod tests {

#[tokio::test]
async fn carries_the_api_client_error_message() {
let body = json!({"code": "SOME_CODE", "message": "Pass --test-collection-id."});
let body = json!({"error": {"code": "SOME_CODE", "message": "Pass --test-collection-id."}});
let error = status_code_help_for(400, body.to_string()).await;

assert_eq!(error.to_string(), "Pass --test-collection-id.");
Expand All @@ -543,8 +540,8 @@ mod tests {
#[tokio::test]
async fn names_the_code_when_the_api_sends_no_message() {
for body in [
json!({"code": "SOME_CODE"}),
json!({"code": "SOME_CODE", "message": " "}),
json!({"error": {"code": "SOME_CODE"}}),
json!({"error": {"code": "SOME_CODE", "message": " "}}),
] {
let error = status_code_help_for(400, body.to_string()).await;

Expand All @@ -564,7 +561,7 @@ mod tests {

#[tokio::test]
async fn truncates_an_overlong_client_error_message() {
let body = json!({"code": "SOME_CODE", "message": "é".repeat(3000)});
let body = json!({"error": {"code": "SOME_CODE", "message": "é".repeat(3000)}});
let error = status_code_help_for(400, body.to_string()).await;

assert_eq!(error.to_string(), format!("{}…", "é".repeat(2048)));
Expand All @@ -574,7 +571,8 @@ mod tests {
async fn leaves_a_body_without_a_code_or_message_unexplained() {
for body in [
json!({}).to_string(),
json!({"code": " ", "message": ""}).to_string(),
json!({"error": {"code": " ", "message": ""}}).to_string(),
json!({"code": "SOME_CODE", "message": "Not the envelope."}).to_string(),
String::from("Bad Request"),
String::new(),
] {
Expand Down
Loading
Loading