-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: standalone testing check (#206)
* feat: standalone testing check * feat: standalone testing check * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: sdk testing for business type * feat: sdk testing for business type * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update * feat: update
- Loading branch information
1 parent
01b8600
commit 8cc4d70
Showing
9 changed files
with
306 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Speakeasy Test SDK | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
target: | ||
description: "The specific target to test" | ||
required: false | ||
type: string | ||
working_directory: | ||
description: "The working directory for running Speakeasy CLI commands in the action" | ||
required: false | ||
type: string | ||
secrets: | ||
github_access_token: | ||
description: A GitHub access token with read access to the repo | ||
required: true | ||
speakeasy_api_key: | ||
description: The API key to use to authenticate the Speakeasy CLI | ||
required: true | ||
jobs: | ||
test: | ||
name: Test SDK | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Tune GitHub-hosted runner network | ||
uses: smorimoto/tune-github-hosted-runner-network@v1 | ||
|
||
- name: Check commit message condition | ||
id: check_commit | ||
run: | | ||
# The default trigger for this action will be a PR event. | ||
# Sometimes we will also add a push event trigger to allow our Github app to run tests by making empty commits, a github token workaround. | ||
# This check allows us to ensure we aren't double running tests when normal PR updates are made. | ||
# The only time a push event should trigger tests is when it's a commit from our app with message "[run-tests]" | ||
if [[ "${{ github.event_name }}" != "push" ]]; then | ||
echo "Skipping commit message check since event is not push." | ||
echo "run_tests=true" >> $GITHUB_OUTPUT | ||
exit 0 | ||
fi | ||
COMMIT_MESSAGE="${{ github.event.head_commit.message }}" | ||
echo "Commit message: $COMMIT_MESSAGE" | ||
if [[ "$COMMIT_MESSAGE" == *"[run-tests]"* ]]; then | ||
echo "run_tests=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "run_tests=false" >> $GITHUB_OUTPUT | ||
fi | ||
- id: test | ||
name: Run Tests | ||
if: steps.check_commit.outputs.run_tests == 'true' | ||
uses: speakeasy-api/sdk-generation-action@v15 | ||
with: | ||
action: "test" | ||
working_directory: ${{ inputs.working_directory }} | ||
target: ${{ inputs.target }} | ||
speakeasy_api_key: ${{ secrets.speakeasy_api_key }} | ||
github_access_token: ${{ secrets.github_access_token }} | ||
|
||
|
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package actions | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
|
||
config "github.com/speakeasy-api/sdk-gen-config" | ||
"github.com/speakeasy-api/sdk-generation-action/internal/cli" | ||
"github.com/speakeasy-api/sdk-generation-action/internal/configuration" | ||
"github.com/speakeasy-api/sdk-generation-action/internal/environment" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func Test() error { | ||
g, err := initAction() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, err = cli.Download("latest", g); err != nil { | ||
return err | ||
} | ||
|
||
wf, err := configuration.GetWorkflowAndValidateLanguages(false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// This will only come in via workflow dispatch, we do accept 'all' as a special case | ||
var testedTargets []string | ||
if providedTargetName := environment.SpecifiedTarget(); providedTargetName != "" { | ||
testedTargets = append(testedTargets, providedTargetName) | ||
} | ||
|
||
if len(testedTargets) == 0 { | ||
// We look for all files modified in the PR or Branch to see what SDK targets have been modified | ||
files, err := g.GetChangedFilesForPRorBranch() | ||
if err != nil { | ||
fmt.Printf("Failed to get commited files: %s\n", err.Error()) | ||
} | ||
|
||
for _, file := range files { | ||
if strings.Contains(file, "gen.yaml") || strings.Contains(file, "gen.lock") { | ||
cfgDir := filepath.Dir(file) | ||
_, err := config.Load(filepath.Dir(file)) | ||
if err != nil { | ||
return fmt.Errorf("failed to load config: %w", err) | ||
} | ||
|
||
outDir, err := filepath.Abs(filepath.Dir(cfgDir)) | ||
if err != nil { | ||
return err | ||
} | ||
for name, target := range wf.Targets { | ||
targetOutput := "" | ||
if target.Output != nil { | ||
targetOutput = *target.Output | ||
} | ||
targetOutput, err := filepath.Abs(filepath.Join(environment.GetWorkingDirectory(), targetOutput)) | ||
if err != nil { | ||
return err | ||
} | ||
// If there are multiple SDKs in a workflow we ensure output path is unique | ||
if targetOutput == outDir && !slices.Contains(testedTargets, name) { | ||
testedTargets = append(testedTargets, name) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if len(testedTargets) == 0 { | ||
fmt.Println("No target was provided ... skipping tests") | ||
return nil | ||
} | ||
|
||
// we will pretty much never have a test action for multiple targets | ||
// but if a customer manually setup their triggers in this way, we will run test sequentially for clear output | ||
var errs []error | ||
for _, target := range testedTargets { | ||
// TODO: Once we have stable test reports we will probably want to use GH API to leave a PR comment/clean up old comments | ||
if err := cli.Test(target); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
if len(errs) > 0 { | ||
return fmt.Errorf("test failures occured: %w", errors.Join(errs...)) | ||
} | ||
|
||
return nil | ||
} |
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 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 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 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 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