Advanced Workflow Customization
  • 5 Minutes to read
  • Dark
    Light
  • PDF

Advanced Workflow Customization

  • Dark
    Light
  • PDF

Article summary

Advanced Workflow Customization for AllSpice Actions

In this documentation, we dive into some of the more sophisticated techniques for customizing workflows in AllSpice Actions. These techniques cover reusable workflows, optimizing performance, creating custom event triggers, and improving the workflow user experience (UX). Implementing these strategies will help your team streamline processes, manage resources more effectively, and maintain a high level of control and visibility across your projects.

Reusable Workflows and Templates

Add-on templates

Check out our documentation on how AllSpice creates parameterized Action Add-ons. You can follow this template to create your own Actions with customizable input. Add-ons

AllSpice Add-ons work like Chip Datasheets in hardware.

Just as an IC datasheet defines the functions of each pin, an Add-on specifies the inputs and outputs of an Action.

This makes Add-ons reusable, modular components—just like the chips you work with in hardware development.

Creating Reusable Workflow Templates

Modularizing frequently used workflows into reusable templates allows you to reduce redundancy and standardize operations across multiple teams or projects. By creating centralized workflows that can be referenced in multiple repositories, you improve efficiency and ensure consistency in your processes.

  • Reusable Workflows: Define common workflows in a central repository and reference them in other projects using the uses keyword.

    Example:

    jobs:
      Post-files-to-release:
        uses: org-name/repo-name/.allspice/workflows/post-files-to-release.yml@main
    

    In this example, the Post-files-to-release job references a reusable workflow from another repository. This approach lets you apply updates or changes to one workflow, and have it reflect across multiple repositories.

Reusable Action Blocks

Reusable action blocks are pieces of code (actions) that can be shared across different workflows and repositories. These blocks can encapsulate specific steps or sequences that need to be run repeatedly, such as testing, deployment, or linting actions.

  • Creating Reusable Actions: Store common actions in a dedicated repository or shared environment. For example, you can create a custom action that lints code, runs tests, or deploys artifacts.

    Example:

    uses: org-name/repo-name/.github/actions/lint-workflows@v1
    

Here, the lint-workflows is a reusable block that can be shared and referenced across different projects, saving time and effort.

Linting is software jargon for automagic code cleaning

Linting is software jargon for automagic code cleaning.

Linters check your code for common syntax errors and save you time by "shifting left" and finding the errors before running a bunch of workflows.

Parameterizing Workflows

To make workflows adaptable and reusable across different environments or contexts, you can parameterize them by defining inputs and outputs. Parameterization allows teams to reuse workflows for different purposes, such as building for multiple environments or supporting product variants, by changing inputs dynamically.

  • Inputs and Outputs: Define inputs and outputs to customize a workflow for different cases.

    Example:

    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Generate BOM
            run: |
              python --env ${{ inputs.environment }}
            with:
              environment: production
    

    In this example, the workflow is parameterized to accept different environment inputs, allowing the same build job to handle DVT, EVT, or release differently.

Environment variables

Using Environment Variables

Environment variables can be defined at different levels: workflow-wide, job-specific, or step-specific.

Workflow-Wide Environment Variables:

env:
  DATABASE: 'production_db'

Job-Specific Environment Variables:

jobs:
  build:
    env:
      NODE_ENV: 'production'

Step-Specific Environment Variables:

steps:
  - name: Print environment
    run: env
    env:
      DEBUG: 'true'

Optimizing Workflow Performance

Hosting images

If you are loading something that is taking a long time, reach out to us to see about hosting images. For example we have a KiCad image that lets you perform CLI using KiCad. If you can do it manually, you can automate it with this image. Check out our demo.

Handling Long-Running Jobs

When dealing with large builds or extensive testing workflows, you may encounter long-running jobs. It’s essential to handle these jobs efficiently to avoid unnecessary resource usage and delays.

  • Best Practices:
    • Break long-running jobs into smaller, more manageable steps.
    • Ensure that jobs that can be parallelized are set up to do so.

Concurrency Control

To prevent workflows from overloading system resources or running too many jobs simultaneously, you can implement concurrency control. This ensures that only a specified number of workflows or jobs run at a time, improving resource management.

  • Example: Concurrency Control

    concurrency:
      group: ${{ allspice.workflow }}
      cancel-in-progress: true
    

    This example groups workflows by their names, ensuring only one workflow of a specific type runs at any time, and cancels in-progress runs when a new run is triggered.


Expressions and Contexts

Expressions allow you to access variables, contexts, and functions in your workflow.

Example of Using Expressions:

- name: Conditional Step
  if: ${{ success() && allspice.ref == 'refs/heads/main' }}
  run: echo "This runs only on the main branch after a successful previous step."

Advanced Webhook Usage

Webhooks provide an advanced mechanism to trigger workflows based on external systems. For example, you can integrate monitoring systems or third-party services to trigger builds or tests based on specific conditions. Many companies integrate their messaging tool like Slack, Teams, and Teamcenter.

Customizing Workflow UX

Using Annotations

Annotations provide detailed feedback within workflow logs and outputs, helping your team understand what happened during a workflow run and improving overall readability.

  • Annotations: You can use annotations to provide additional information, such as highlighting important messages, successes, or errors.

    Example:

    steps:
      - name: Annotate Results
        run: echo "::notice::Build completed successfully."
    

Custom Dashboards

By integrating your workflows with external tools or custom scripts, you can create dashboards that give real-time insights into the status and performance of your workflows. These dashboards can be tailored to specific team needs, offering a higher level of visibility into key metrics and workflow health.

  • Custom Dashboards: Integrate with tools like Grafana or custom-built dashboards to visualize workflow metrics and statuses in real time.

Advanced Workflow Visualization

To better manage complex workflows, advanced visualization tools can help track dependencies, outcomes, and the overall flow of execution. These visualizations provide clarity when dealing with multi-step, multi-job workflows and make it easier to identify bottlenecks or areas for improvement.

  • Example: Use visual workflow dashboards or graphical tools to map out workflows and their dependencies, providing team members with clear insight into the workflow process.

Conclusion

By leveraging these advanced workflow customization techniques, you can create more powerful, flexible, and efficient workflows for your team. Reusable workflows and templates allow you to standardize processes, while performance optimization techniques ensure faster, more resource-efficient operations. Custom event triggers enable workflows to respond dynamically to external systems, and enhancing the user experience with annotations and dashboards provides greater visibility and control.

With these tools at your disposal, you can ensure that your AllSpice Actions workflows are fully optimized to meet the needs of your team and projects.


Was this article helpful?