Skip to content

Commit

Permalink
feat: allow non root working dir in run (#157)
Browse files Browse the repository at this point in the history
* feat: allow non root working dir in run

* feat: allow non root working dir in run

* feat: allow non root working dir in run

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update
  • Loading branch information
ryan-timothy-albert authored Aug 24, 2024
1 parent 9b2a611 commit 83177e6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/sdk-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
required: false
description: "Internal use only"
type: string
working_directory:
description: "The working directory for running Speakeasy CLI commands in the action"
required: false
type: string
dotnet_version:
description: "The version of dotnet to use when compiling the C# SDK"
required: false
Expand Down Expand Up @@ -98,6 +102,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: "release"
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
- uses: ravsamhq/notify-slack-action@v2
if: always() && env.SLACK_WEBHOOK_URL != ''
Expand Down Expand Up @@ -159,6 +164,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.python_directory }}
registry_name: "pypi"
Expand Down Expand Up @@ -206,6 +212,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.typescript_directory }}
registry_name: "npm"
Expand Down Expand Up @@ -268,6 +275,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.java_directory }}
registry_name: "sonatype"
Expand Down Expand Up @@ -310,6 +318,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.php_directory }}
registry_name: "packagist"
Expand Down Expand Up @@ -352,6 +361,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.csharp_directory }}
registry_name: "nuget"
Expand Down Expand Up @@ -392,6 +402,7 @@ jobs:
with:
github_access_token: ${{ secrets.github_access_token }}
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
gpg_fingerprint: ${{ steps.import_gpg.outputs.fingerprint }}
action: "release"
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
Expand All @@ -404,6 +415,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.publish_terraform }}
registry_name: "terraform"
Expand Down Expand Up @@ -456,6 +468,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.release.outputs.ruby_directory }}
registry_name: "gems"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
description: "The targets to tag code samples for (comma or newline separated)"
required: false
type: string
working_directory:
description: "The working directory for running Speakeasy CLI commands in the action"
required: false
type: string
registry_tags:
description: "Multi-line or single-line string input of tags to apply to speakeasy registry builds"
required: false
Expand All @@ -36,6 +40,7 @@ jobs:
action: "tag"
sources: ${{ inputs.sources }}
code_samples: ${{ inputs.code_samples }}
working_directory: ${{ inputs.working_directory }}
registry_tags: ${{ inputs.registry_tags }}
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
github_access_token: ${{ secrets.github_access_token }}
13 changes: 13 additions & 0 deletions .github/workflows/workflow-executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ jobs:
with:
speakeasy_version: ${{ inputs.speakeasy_version }}
github_access_token: ${{ secrets.github_access_token }}
working_directory: ${{ inputs.working_directory }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
Expand Down Expand Up @@ -236,6 +237,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.run-workflow.outputs.python_directory }}
registry_name: "pypi"
Expand All @@ -261,6 +263,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
env:
GH_ACTION_RESULT: ${{ job.status }}
Expand Down Expand Up @@ -304,6 +307,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.run-workflow.outputs.typescript_directory }}
registry_name: "npm"
Expand All @@ -329,6 +333,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
env:
GH_ACTION_RESULT: ${{ job.status }}
Expand Down Expand Up @@ -388,6 +393,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.run-workflow.outputs.java_directory }}
registry_name: "sonatype"
Expand All @@ -413,6 +419,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
env:
GH_ACTION_RESULT: ${{ job.status }}
Expand Down Expand Up @@ -461,6 +468,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.run-workflow.outputs.ruby_directory }}
registry_name: "gems"
Expand All @@ -486,6 +494,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
env:
GH_ACTION_RESULT: ${{ job.status }}
Expand Down Expand Up @@ -524,6 +533,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.run-workflow.outputs.csharp_directory }}
registry_name: "nuget"
Expand All @@ -549,6 +559,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
env:
GH_ACTION_RESULT: ${{ job.status }}
Expand Down Expand Up @@ -585,6 +596,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: publish-event
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
target_directory: ${{ needs.run-workflow.outputs.php_directory }}
registry_name: "packagist"
Expand All @@ -610,6 +622,7 @@ jobs:
github_access_token: ${{ secrets.github_access_token }}
action: log-result
speakeasy_api_key: ${{ secrets.speakeasy_api_key }}
working_directory: ${{ inputs.working_directory }}
speakeasy_server_url: ${{ inputs.speakeasy_server_url }}
env:
GH_ACTION_RESULT: ${{ job.status }}
Expand Down
19 changes: 17 additions & 2 deletions internal/actions/utils.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package actions

import (
"path/filepath"

"github.com/speakeasy-api/sdk-generation-action/internal/configuration"
"github.com/speakeasy-api/sdk-generation-action/internal/environment"
)

func getReleasesDir() (string, error) {
releasesDir := "."
if environment.GetWorkingDirectory() != "" {
releasesDir = environment.GetWorkingDirectory()
}
// Find releases file
wf, err := configuration.GetWorkflowAndValidateLanguages(false)
if err != nil {
Expand All @@ -16,14 +21,24 @@ func getReleasesDir() (string, error) {
// Checking for multiple targets ensures backward compatibility with the code below
if len(wf.Targets) > 1 && environment.SpecifiedTarget() != "" {
if target, ok := wf.Targets[environment.SpecifiedTarget()]; ok && target.Output != nil {
return *target.Output, nil
if releasesDir != "." {
releasesDir = filepath.Join(releasesDir, *target.Output)
} else {
releasesDir = *target.Output
}

return releasesDir, nil
}
}

for _, target := range wf.Targets {
// If we are only generating one language and its not in the root directory we assume this is a multi-sdk repo
if len(wf.Targets) == 1 && target.Output != nil && *target.Output != "." {
releasesDir = *target.Output
if releasesDir != "." {
releasesDir = filepath.Join(releasesDir, *target.Output)
} else {
releasesDir = *target.Output
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetWorkflowAndValidateLanguages(checkLangSupported bool) (*workflow.Workflo
func getWorkflow() (*workflow.Workflow, error) {
workspace := environment.GetWorkspace()

localPath := filepath.Join(workspace, "repo")
localPath := filepath.Join(workspace, "repo", environment.GetWorkingDirectory())

wf, _, err := workflow.Load(localPath)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/speakeasy-api/versioning-reports/versioning"
"net/url"
"os"
"os/exec"
Expand All @@ -17,6 +16,8 @@ import (
"strings"
"time"

"github.com/speakeasy-api/versioning-reports/versioning"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
Expand Down Expand Up @@ -759,7 +760,6 @@ func PRMetadata(m *versioning.MergedVersionReport, labelTypes map[string]github.
return strings.Join(builder, " "), labels
}


func (g *Git) CreateSuggestionPR(branchName, output string) (*int, string, error) {
body := fmt.Sprintf(`Generated OpenAPI Suggestions by Speakeasy CLI.
Outputs changes to *%s*.`, output)
Expand Down Expand Up @@ -1023,7 +1023,7 @@ func (g *Git) UpsertLabelTypes(ctx context.Context) map[string]github.Label {
desiredLabels := map[string]github.Label{}
addGitHubLabel := func(name, description string) {
desiredLabels[name] = github.Label{
Name: &name,
Name: &name,
Description: &description,
}
}
Expand All @@ -1041,7 +1041,6 @@ func (g *Git) UpsertLabelTypes(ctx context.Context) map[string]github.Label {
actualLabels[*label.Name] = *label
}


for _, label := range desiredLabels {
foundLabel, ok := actualLabels[*label.Name]
if ok {
Expand Down
1 change: 1 addition & 0 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func Run(g Git, pr *github.PullRequest, wf *workflow.Workflow) (*RunResult, map[
dir = *target.Output
}

dir = filepath.Join(environment.GetWorkingDirectory(), dir)
return dir, path.Join(workspace, "repo", dir)
}

Expand Down

0 comments on commit 83177e6

Please sign in to comment.