Skip to content

Commit

Permalink
feat: support label based versioning (#184)
Browse files Browse the repository at this point in the history
* feat: support label based versioning bumps

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update

* feat: update new format

* 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
ryan-timothy-albert authored Nov 11, 2024
1 parent 55aef2b commit 8173f33
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 161 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/workflow-executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,32 @@ jobs:
branch_name: ${{ steps.run-workflow.outputs.branch_name }}
resolved_speakeasy_version: ${{ steps.run-workflow.outputs.resolved_speakeasy_version }}
use_sonatype_legacy: ${{ steps.run-workflow.outputs.use_sonatype_legacy }}
short_circuit_label_trigger: ${{ steps.check-label.outputs.short_circuit_label_trigger }}
steps:
- name: Check Pull Request Label
if: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' }}
id: check-label
continue-on-error: true
run: |
label="${{ github.event.label.name }}"
tmpfile=$(mktemp)
echo "${{ github.event.pull_request.body }}" > "$tmpfile"
# Check if the label is a valid version bump and ensure the current PR isn't already on that version bump
# If either are true we short circuit the rest of the action
if [[ "$label" != "patch" && "$label" != "minor" && "$label" != "major" && "$label" != "graduate" ]] || grep -Fq "Version Bump Type: [$label]" "$tmpfile"; then
echo "No version bump label found in PR body. Short-circuiting."
echo "short_circuit_label_trigger=true" >> "$GITHUB_OUTPUT"
exit 0
else
echo "short_circuit_label_trigger=false" >> "$GITHUB_OUTPUT"
fi
- name: Tune GitHub-hosted runner network
if: ${{ steps.check-label.outputs.short_circuit_label_trigger != 'true' }}
uses: smorimoto/tune-github-hosted-runner-network@v1
- id: run-workflow
name: Run Generation Workflow
if: ${{ steps.check-label.outputs.short_circuit_label_trigger != 'true' }}
uses: speakeasy-api/sdk-generation-action@v15
with:
speakeasy_version: ${{ inputs.speakeasy_version }}
Expand All @@ -188,7 +209,7 @@ jobs:
cli_environment_variables: ${{ inputs.environment }}
pnpm_version: ${{ inputs.pnpm_version }}
- uses: ravsamhq/notify-slack-action@v2
if: always() && env.SLACK_WEBHOOK_URL != ''
if: ${{ steps.check-label.outputs.short_circuit_label_trigger != 'true' && env.SLACK_WEBHOOK_URL != '' }}
with:
status: ${{ job.status }}
token: ${{ secrets.github_access_token }}
Expand All @@ -201,7 +222,7 @@ jobs:
- id: log-result
name: Log Generation Output
uses: speakeasy-api/sdk-generation-action@v15
if: always()
if: ${{ steps.check-label.outputs.short_circuit_label_trigger != 'true'}}
with:
speakeasy_version: ${{ inputs.speakeasy_version }}
github_access_token: ${{ secrets.github_access_token }}
Expand Down
6 changes: 4 additions & 2 deletions internal/actions/runWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/google/go-github/v63/github"
"github.com/speakeasy-api/sdk-generation-action/internal/versionbumps"
"github.com/speakeasy-api/versioning-reports/versioning"

"github.com/speakeasy-api/sdk-generation-action/internal/configuration"
Expand Down Expand Up @@ -173,7 +174,7 @@ func RunWorkflow() error {
AnythingRegenerated: anythingRegenerated,
SourcesOnly: sourcesOnly,
Git: g,
VersioningReport: runRes.VersioningReport,
VersioningInfo: runRes.VersioningInfo,
LintingReportURL: runRes.LintingReportURL,
ChangesReportURL: runRes.ChangesReportURL,
OpenAPIChangeSummary: runRes.OpenAPIChangeSummary,
Expand Down Expand Up @@ -202,6 +203,7 @@ type finalizeInputs struct {
ChangesReportURL string
OpenAPIChangeSummary string
VersioningReport *versioning.MergedVersionReport
VersioningInfo versionbumps.VersioningInfo
currentRelease *releases.ReleasesInfo
}

Expand Down Expand Up @@ -240,7 +242,7 @@ func finalize(inputs finalizeInputs) error {
SourceGeneration: inputs.SourcesOnly,
LintingReportURL: inputs.LintingReportURL,
ChangesReportURL: inputs.ChangesReportURL,
VersioningReport: inputs.VersioningReport,
VersioningInfo: inputs.VersioningInfo,
OpenAPIChangeSummary: inputs.OpenAPIChangeSummary,
})

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func GetSupportedLanguages() []string {
return supportedTargets
}
}

return defaultSupportedTargets
}

Expand Down
12 changes: 9 additions & 3 deletions internal/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import (
"regexp"
"strings"

"github.com/speakeasy-api/sdk-generation-action/internal/registry"

"github.com/speakeasy-api/sdk-generation-action/internal/environment"
"github.com/speakeasy-api/sdk-generation-action/internal/registry"
"github.com/speakeasy-api/versioning-reports/versioning"
)

const BumpOverrideEnvVar = "SPEAKEASY_BUMP_OVERRIDE"

type RunResults struct {
LintingReportURL string
ChangesReportURL string
OpenAPIChangeSummary string
}

func Run(sourcesOnly bool, installationURLs map[string]string, repoURL string, repoSubdirectories map[string]string) (*RunResults, error) {
func Run(sourcesOnly bool, installationURLs map[string]string, repoURL string, repoSubdirectories map[string]string, manualVersionBump *versioning.BumpType) (*RunResults, error) {
args := []string{
"run",
}
Expand Down Expand Up @@ -64,6 +66,10 @@ func Run(sourcesOnly bool, installationURLs map[string]string, repoURL string, r
os.Setenv("SPEAKEASY_FORCE_GENERATION", "true")
}

if manualVersionBump != nil {
os.Setenv(BumpOverrideEnvVar, string(*manualVersionBump))
}

//if environment.ShouldOutputTests() {
// TODO: Add CLI flag for outputting tests
//}
Expand Down
8 changes: 8 additions & 0 deletions internal/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ func GetWorkflowEventPayloadPath() string {
return os.Getenv("GITHUB_EVENT_PATH")
}

func GetWorkflowEventLabelName() string {
return os.Getenv("GITHUB_EVENT_LABEL_NAME")
}

func GetBranchName() string {
return os.Getenv("INPUT_BRANCH_NAME")
}
Expand All @@ -234,6 +238,10 @@ func GetCliOutput() string {
}

func GetRef() string {
// handle pr based action triggers
if strings.Contains(os.Getenv("GITHUB_REF"), "refs/pull") || strings.Contains(os.Getenv("GITHUB_REF"), "refs/pulls") {
return os.Getenv("GITHUB_BASE_REF")
}
return os.Getenv("GITHUB_REF")
}

Expand Down
Loading

0 comments on commit 8173f33

Please sign in to comment.