A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://help.github.com/en/actions/reference/github-actions-importer/custom-transformers below:

Extending GitHub Actions Importer with custom transformers

GitHub Actions Importer offers the ability to extend its built-in mapping.

About custom transformers

GitHub Actions Importer offers the ability to extend its built-in mapping by creating custom transformers. Custom transformers can be used to:

Using custom transformers with GitHub Actions Importer

A custom transformer contains mapping logic that GitHub Actions Importer can use to transform your plugins, tasks, runner labels, or environment variables to work with GitHub Actions. Custom transformers are written with a domain-specific language (DSL) built on top of Ruby, and are defined within a file with the .rb file extension.

You can use the --custom-transformers CLI option to specify which custom transformer files to use with the audit, dry-run, and migrate commands.

For example, if custom transformers are defined in a file named transformers.rb, you can use the following command to use them with GitHub Actions Importer:

gh actions-importer ... --custom-transformers transformers.rb

Alternatively, you can use the glob pattern syntax to specify multiple custom transformer files. For example, if multiple custom transformer files are within a directory named transformers, you can provide them all to GitHub Actions Importer with the following command:

gh actions-importer ... --custom-transformers transformers/*.rb

Note

When you use custom transformers, the custom transformer files must reside in the same directory, or in subdirectories, from where the gh actions-importer command is run.

Creating custom transformers for items

You can create custom transformers that GitHub Actions Importer will use when converting existing build steps or triggers to their equivalent in GitHub Actions. This is especially useful when:

GitHub Actions Importer uses custom transformers that are defined using a DSL built on top of Ruby. In order to create custom transformers for build steps and triggers:

Example custom transformer for a build step

The following example converts a build step that uses the "buildJavaScriptApp" identifier to run various npm commands:

Ruby
transform "buildJavaScriptApp" do |item|
  command = ["build", "package", "deploy"].map do |script|
    "npm run #{script}"
  end

  {
    name: "build javascript app",
    run: command.join("\n")
  }
end
transform "buildJavaScriptApp" do |item|
  command = ["build", "package", "deploy"].map do |script|
    "npm run #{script}"
  end

  {
    name: "build javascript app",
    run: command.join("\n")
  }
end

The above example results in the following GitHub Actions workflow step. It is comprised of converted build steps that had a buildJavaScriptApp identifier:

- name: build javascript app
  run: |
    npm run build
    npm run package
    npm run deploy

The transform method uses the identifier of the build step from your source CI/CD instance in an argument. In this example, the identifier is buildJavaScriptLibrary. You can also use comma-separated values to pass multiple identifiers to the transform method. For example, transform "buildJavaScriptApp", "buildTypeScriptApp" { |item| ... }.

Note

The data structure of item will be different depending on the CI/CD platform and the type of item being converted.

Creating custom transformers for runners

You can customize the mapping between runners in your source CI/CD instance and their equivalent GitHub Actions runners.

GitHub Actions Importer uses custom transformers that are defined using a DSL built on top of Ruby. To create custom transformers for runners:

Example custom transformers for runners

The following example shows a runner method that converts one runner label to one GitHub Actions runner label in the resulting workflow.

Ruby
runner "linux", "ubuntu-latest"
runner "linux", "ubuntu-latest"

You can also use the runner method to convert one runner label to multiple GitHub Actions runner labels in the resulting workflow.

Ruby
runner "big-agent", ["self-hosted", "xl", "linux"]
runner "big-agent", ["self-hosted", "xl", "linux"]

GitHub Actions Importer attempts to map the runner label as best it can. In cases where it cannot do this, the ubuntu-latest runner label is used as a default. You can use a special keyword with the runner method to control this default value. For example, the following custom transformer instructs GitHub Actions Importer to use macos-latest as the default runner instead of ubuntu-latest.

Ruby
runner :default, "macos-latest"
runner :default, "macos-latest"
Creating custom transformers for environment variables

You can customize the mapping between environment variables in your source CI/CD pipelines to their values in GitHub Actions.

GitHub Actions Importer uses custom transformers that are defined using a DSL built on top of Ruby. To create custom transformers for environment variables:

Example custom transformers for environment variables

There are several ways you can set up custom transformers to map your environment variables.

Legal notice

Portions have been adapted from https://github.com/github/gh-actions-importer/ under the MIT license:

MIT License

Copyright (c) 2022 GitHub

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4