Skip to content

Conversation

@nxtcoder17
Copy link
Owner

@nxtcoder17 nxtcoder17 commented Oct 20, 2024

Closes #15

Summary by Sourcery

Implement support for global environment variables in tasks, enabling tasks to utilize and override global environment settings. Add comprehensive tests to ensure the correct behavior of global environment variables in various scenarios.

New Features:

  • Add support for global environment variables in tasks, allowing tasks to access and override global environment settings.

Tests:

  • Introduce tests to verify the functionality of global environment variables, including key-value pairs, shell values, default values, task-level overrides, and required variables.

@nxtcoder17 nxtcoder17 self-assigned this Oct 20, 2024
@sourcery-ai sourcery-ai bot changed the title @sourcery-ai Add support for global environment variables in tasks Oct 20, 2024
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 20, 2024

Reviewer's Guide by Sourcery

This pull request adds support for global environment variables in tasks. It modifies the task parsing logic to include global environment variables and updates the Runfile structure to accommodate these changes.

Sequence diagram for task parsing with global environment variables

sequenceDiagram
    participant Ctx as Context
    participant RF as Runfile
    participant TP as TaskParser
    participant PT as ParsedTask
    Ctx->>TP: ParseTask(ctx, rf, task)
    TP->>RF: Check Env
    alt Env exists
        TP->>TP: parseEnvVars(ctx, rf.Env)
        TP->>TP: Merge globalEnv
    end
    TP->>TP: resolveDotEnvFiles()
    TP->>TP: parseDotEnvFiles()
    TP->>TP: parseEnvVars(ctx, task.Env)
    TP->>PT: Return ParsedTask with merged Env
Loading

Class diagram for updated Runfile structure

classDiagram
    class Runfile {
        +string Version
        +map Includes
        +EnvVar Env
        +string[] DotEnv
        +map Tasks
    }
    class EnvVar
    Runfile --> EnvVar : Env
    Runfile --> string : DotEnv
    Runfile --> map : Includes
    Runfile --> map : Tasks
Loading

File-Level Changes

Change Details Files
Add support for global environment variables
  • Introduce a new 'Env' field in the Runfile struct to store global environment variables
  • Modify the ParseTask function to parse and include global environment variables
  • Update the environment variable merging logic to include global variables
  • Add a new 'DotEnv' field to the Runfile struct for global .env files
pkg/runfile/runfile.go
pkg/runfile/task-parser.go
Update test cases to cover global environment variables
  • Add new test cases for global environment variables with different scenarios
  • Include tests for key-value pairs, shell commands, default values, and required variables
  • Test overriding global environment variables at the task level
pkg/runfile/task-parser_test.go
Update example Runfile to demonstrate global environment variables
  • Add a global environment variable 'global_k1' with value 'v1' to the example Runfile
examples/Runfile.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#15 Add support for global environment variables

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@nxtcoder17 nxtcoder17 changed the title Add support for global environment variables in tasks Adds support for global env-vars Oct 20, 2024
@nxtcoder17 nxtcoder17 merged commit 138ff91 into master Oct 20, 2024
@nxtcoder17 nxtcoder17 deleted the feat/global-env branch October 20, 2024 02:52
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nxtcoder17 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.


Version string `json:"version,omitempty"`
Includes map[string]IncludeSpec `json:"includes"`
Env EnvVar `json:"env,omitempty"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add comment explaining global vs task-specific Env and DotEnv

Consider adding a comment to explain the difference between these global Env and DotEnv settings and their task-specific counterparts. This can help prevent confusion for future maintainers.

// Env defines global environment variables for all tasks.
// Task-specific Env settings override these global values.
Env      EnvVar                 `json:"env,omitempty"`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[✨ FEAT] global env variables

2 participants