Lädt...


🔧 Cargo Actions: An efficient tool for managing and creating GitHub Actions workflow templates


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

In software development, continuous integration and continuous deployment (CI/CD) are crucial processes. To simplify this process, I developed Cargo Actions, a command-line tool based on the Rust language, which provides efficient workflow template management and creation functionality for GitHub Actions.

The main functions of Cargo Actions include:

  1. User authentication and login: Securely integrate with GitHub via the OAuth 2.0 protocol, allowing users to log in to Cargo Actions using their GitHub accounts.
  2. Workflow initialization: Support for initializing a workflow from a GitHub repository or template ID, providing a flexible way to integrate GitHub Actions workflows.
  3. Template upload and sharing: Users can upload their own created workflow templates to the Cargo Actions platform and share them with other users.
  4. Personalized template management: Allow users to manage their uploaded and favorite templates, facilitating the quick launch of familiar or commonly used workflow configurations.

Installation

Run the following command in the terminal:

cargo install cargo-actions

Usage

Initialization

Create a project using the GitHub repository URL, and you can omit the https://github.com/ prefix. By default, the workflow template in https://github.com/yexiyue/cargo-actions will be used.

Using the abbreviated form, the rule (User/Repo) is:

cargo actions init yexiyue/cargo-actions

Using the URL form:

cargo actions init https://github.com/yexiyue/cargo-actions.git

Using the SSH form:

cargo actions init [email protected]:yexiyue/cargo-actions.git

init command

You can also use the workflow on the Cargo Actions platform.

Copy the favorite workflow template to the terminal. For example:

cargo actions init 1 -i

Upload Template

If you want to upload your own workflow to the Cargo Actions platform, please log in first.

cargo actions login

Then prepare a workflow template.

A standard workflow template should have the following files:

  • cargo-action.json: Configuration file used to prompt the user for input
  • Template name.yaml.hbs: Template file
  • README.md (optional)

cargo-action.json configuration field description

Field Name Type Description
name string Template name
description string Short description of the template
path string Template file path, default ${name}.yaml.hbs
prompts Prompt[] Defines the command-line interactive input items
success_message string Success message after template creation

Prompt configuration instructions

There are 4 types of prompts:

  1. type: "input"
Field Name Type Description
field string Field name (corresponding to the variable name in the template)
prompt string Input prompt
default string Default value
  1. type: "confirm"
Field Name Type Description
field string Field name (corresponding to the variable name in the template)
prompt string Input prompt
default bool Default value
  1. type: "select"
Field Name Type Description
field string Field name (corresponding to the variable name in the template)
prompt string Input prompt
default number Index value of the default option
options {value: any, label: string}[] Option list, where label is the prompt value and value is the value used in the template at the end
  1. type: "multiselect"
Field Name Type Description
field string Field name (corresponding to the variable name in the template)
prompt string Input prompt
default number[] Array of index values of default options
options {value: any, label: string}[] Option list, where label is the prompt value and value is the value used in the template at the end

Example:

{
  "name": "web-deploy",
  "description": "Build a web application to Github Pages",
  "prompts": [
    {
      "type": "select",
      "field": "toolchain",
      "prompt": "Please select a package management tool",
      "default": 0,
      "options": [
        {
          "label": "npm",
          "value": "npm"
        },
        {
          "label": "yarn",
          "value": "yarn"
        },
        {
          "label": "pnpm",
          "value": "pnpm"
        }
      ]
    },
    {
      "type": "confirm",
      "field": "enable_cache",
      "prompt": "Enable caching",
      "default": true
    },
    {
      "type": "input",
      "field": "node_version",
      "prompt": "Please enter the node version number",
      "default": "node"
    },
    {
      "type": "input",
      "field": "folder",
      "prompt": "Web project path",
      "default": "."
    },
    {
      "type": "input",
      "prompt": "Build artifact directory (relative to the web project path)",
      "field": "target_dir",
      "default": "dist"
    },
    {
      "type": "confirm",
      "prompt": "Copy index.html to 404.html to support spa",
      "field": "copy_index",
      "default": false
    }
  ]
}

The template file is rendered using handlebars, and the template syntax can be referred to Handlebars (handlebarsjs.com).

Template file example:

name: web on: push: branches: - "master" workflow_dispatch: jobs: deploy:
runs-on: ubuntu-latest permissions: contents: write concurrency: group:
{{#raw}}$\{{ github.workflow }}-$\{{ github.ref }}{{/raw}}
steps: - name: Checkout repository uses: actions/checkout@v4
{{#if (eq toolchain "pnpm")}}
  - name: Install pnpm run: npm install -g pnpm
{{/if}}
- name: Sync node version and setup cache uses: actions/setup-node@v4 with:
node-version: "{{node_version}}"
{{#if enable_cache}}
  {{#if (eq toolchain "pnpm")}}
    cache: "{{folder}}/pnpm-lock.yaml"
  {{/if}}
  {{#if (eq toolchain "npm")}}
    cache: "{{folder}}/package-lock.json"
  {{/if}}
  {{#if (eq toolchain "yarn")}}
    cache: "{{folder}}/yarn.lock"
  {{/if}}
{{/if}}
- name: Install dependencies run: | cd
{{folder}}
{{toolchain}}
install - name: Build run: | cd
{{folder}}
{{toolchain}}
build
{{#if copy_index}}
  cp
  {{target_dir}}/index.html
  {{target_dir}}/404.html
{{/if}}
- name: Deploy uses: peaceiris/actions-gh-pages@v4 with:
{{#raw}}github_token: $\{{ secrets.GITHUB_TOKEN }}{{/raw}}
publish_dir:
{{folder}}/{{target_dir}}

Note:

Expressions in {{{{raw}}}} {{{{/raw}}}} will not be escaped.

Before uploading, you can use the check command to verify if the workflow template is working properly.

cargo actions check

Then use the upload command to upload the workflow template.

cargo actions upload

Using the created template

You can quickly use your own created workflow template with the following command, note that you need to log in.

cargo actions mine

You can also view the workflow template you created in the Cargo Actions platform Personal Center.

Using the favorite template

cargo actions favorite

This command is similar to the mine command, and allows you to select a workflow from the templates you favorited on the Cargo Actions platform for initialization.

View more usage with the following command

cargo actions --help

Conclusion

If you are interested in Cargo Actions, welcome to visit my GitHub repository for more information.

At the same time, if you find this tool helpful, don't forget to give it a like! Your support is the driving force for me to continuously update and improve.

...

🔧 Cargo Actions: An efficient tool for managing and creating GitHub Actions workflow templates


📈 109.16 Punkte
🔧 Programmierung

🔧 TIL: You can create your own GitHub Actions workflow templates


📈 41.7 Punkte
🔧 Programmierung

🎥 Creating a workload identity and linking it to a GitHub Actions deployment workflow


📈 39.45 Punkte
🎥 Video | Youtube

📰 Mystery of the Cargo Ships That Sink When Their Cargo Suddenly Liquefies


📈 36.54 Punkte
📰 IT Security Nachrichten

🕵️ CVE-2022-36113 | Cargo up to 1.62.x ~/.cargo path traversal (GHSA-rfj2-q3h3-hm5j)


📈 36.54 Punkte
🕵️ Sicherheitslücken

🔧 Creating a data pipeline using Dataproc workflow templates and cloud Schedule


📈 36.13 Punkte
🔧 Programmierung

🔧 Creating and Managing Users and Groups on Linux with Bash Scripts: An Efficient Guide 🚀🐧


📈 36.06 Punkte
🔧 Programmierung

🔧 Managing Community Health Files and Templates with a .github Repository


📈 33.7 Punkte
🔧 Programmierung

🐧 Gitea is working on a built-in CI/CD tool called Gitea Actions (compatible with GitHub Actions syntax)


📈 31.3 Punkte
🐧 Linux Tipps

🔧 Deploying a Vite app on GitHub Pages using GitHub Actions with GitHub Secrets


📈 30.55 Punkte
🔧 Programmierung

🔧 Github Actions: Let's Understand and Create an Interesting Workflow for our Projects


📈 30.2 Punkte
🔧 Programmierung

🔧 Create a CI Workflow with Minimal Boilerplate Using Nx, Docker, and GitHub Actions


📈 30.2 Punkte
🔧 Programmierung

🔧 Continuous integration workflow template for .NET Core desktop apps with GitHub Actions


📈 28.53 Punkte
🔧 Programmierung

🎥 Learn Live - Build your first Bicep deployment workflow by using GitHub Actions


📈 28.53 Punkte
🎥 Video | Youtube

🔧 GitHub Actions Workflow


📈 28.53 Punkte
🔧 Programmierung

🔧 Hello World in GitHub Actions: A Beginner's Guide to Your First Workflow


📈 28.53 Punkte
🔧 Programmierung

🔧 My Github Actions workflow for deploying web projects


📈 28.53 Punkte
🔧 Programmierung

🔧 GitHub Actions Secrets: Enhancing Workflow Security


📈 28.53 Punkte
🔧 Programmierung

🔧 Mask multiple lines text in GitHub Actions Workflow


📈 28.53 Punkte
🔧 Programmierung

🔧 Boost Your Dev Workflow: Automate with GitHub Actions


📈 28.53 Punkte
🔧 Programmierung

🔧 Simple YAML Linter/Validator Workflow for GitHub Actions


📈 28.53 Punkte
🔧 Programmierung

🔧 Streamlining Development Workflow: Automating Tasks with GitHub Actions


📈 28.53 Punkte
🔧 Programmierung

🔧 Streamline Your Workflow: Automate Frontend Deployment with GitHub Actions


📈 28.53 Punkte
🔧 Programmierung

🎥 Actions Project - Actions Builder & Actions SDK


📈 28.41 Punkte
🎥 Videos

🎥 Conversational Actions overview - Actions Builder & Actions SDK


📈 28.41 Punkte
🎥 Videos

🔧 Efficiently Managing Multi-Directory Repositories with GitHub Actions CI/CD Pipeline


📈 28.32 Punkte
🔧 Programmierung

🎥 Creating an Action for the Google Assistant with Actions Builder (Behind the Actions, Ep. 7)


📈 28.18 Punkte
🎥 Videos

🎥 Creating an Action for the Google Assistant with Actions SDK (Behind the Actions, Ep. 8)


📈 28.18 Punkte
🎥 Videos

🔧 Enhance Your Coding Workflow with Our GitHub and GitHub Copilot Learn Plan


📈 27.76 Punkte
🔧 Programmierung

📰 Amazon To Build $1.5 Billion Air Cargo Hub In Kentucky, Creating Around 2,000 New Jobs


📈 27.52 Punkte
📰 IT Security Nachrichten

🔧 Creating an Automated Documentation Pipeline in PHP with Autodocs and GitHub Actions


📈 27.41 Punkte
🔧 Programmierung

🔧 Creating an Automated Profile README using Nodejs and GitHub Actions


📈 27.41 Punkte
🔧 Programmierung

matomo