Skip to content

Commit

Permalink
feat: populate code samples in the registry (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbx9da4 authored Jun 7, 2024
1 parent 8471c68 commit 5afb27f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/workflow-executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ on:
description: "Multi-line or single-line string input of tags to apply to speakeasy registry builds"
required: false
type: string
push_code_samples_only:
description: "This will generate code samples, tag them with the `main` branch name, and push them to the registry. It will not create a pull request or commit any code. This is useful for pushing up some code samples to the registry the first time when there are no code samples in the registry."
required: false
type: boolean
secrets:
github_access_token:
description: A GitHub access token with write access to the repo
Expand Down Expand Up @@ -143,6 +147,7 @@ jobs:
openapi_doc_auth_token: ${{ secrets.openapi_doc_auth_token }}
target: ${{ inputs.target }}
registry_tags: ${{ inputs.registry_tags }}
push_code_samples_only: ${{ inputs.push_code_samples }}
- uses: ravsamhq/notify-slack-action@v2
if: always() && env.SLACK_WEBHOOK_URL != ''
with:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ test-direct-mode-multi-sdk:
test-pr-mode:
./testing/test.sh ./testing/pr-mode.env

test-push-code-samples-only:
./testing/test.sh ./testing/push-code-samples-only.env

test-release-mode:
./testing/test.sh ./testing/release-mode.env

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ inputs:
gpg_fingerprint:
description: "The GPG fingerprint to sign the release with"
required: false
push_code_samples_only:
description: "This will generate code samples, tag them with the `main` branch name, and push them to the registry. It will not create a pull request or commit any code. This is useful for pushing up some code samples to the registry the first time when there are no code samples in the registry."
required: false
outputs:
publish_python:
description: "Whether the Python SDK will be published to PyPi"
Expand Down
14 changes: 11 additions & 3 deletions internal/actions/runWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ func RunWorkflow() error {
}
}

branchName, err = g.FindOrCreateBranch(branchName, environment.ActionRunWorkflow)
if err != nil {
return err
// We want to stay on main if we're pushing code samples because we want to tag the code samples with `main`
if !environment.PushCodeSamplesOnly() {
branchName, err = g.FindOrCreateBranch(branchName, environment.ActionRunWorkflow)
if err != nil {
return err
}
}

success := false
Expand Down Expand Up @@ -119,6 +122,11 @@ func RunWorkflow() error {
}
}

if environment.PushCodeSamplesOnly() {
// If we're just pushing code samples we don't want to raise a PR
return nil
}

releasesDir, err := getReleasesDir()
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func ForceGeneration() bool {
return os.Getenv("INPUT_FORCE") == "true"
}

func PushCodeSamplesOnly() bool {
return os.Getenv("INPUT_PUSH_CODE_SAMPLES_ONLY") == "true"
}

func RegistryTags() string {
return os.Getenv("INPUT_REGISTRY_TAGS")
}
Expand Down
7 changes: 7 additions & 0 deletions testing/push-code-samples-only.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INPUT_MODE="pr"
INPUT_ACTION="generate"
INPUT_LANGUAGES="- go"
GITHUB_REPOSITORY="speakeasy-api/sdk-generation-action-test-repo"
INPUT_FORCE=true
INPUT_PUSH_CODE_SAMPLES_ONLY=true
RUN_FINALIZE=true

0 comments on commit 5afb27f

Please sign in to comment.