In this lab, you will build upon the `dry-run` command to override GitHub Actions Importer's default behavior and customize the converted workflow using "custom transformers." Custom transformers can be used to:
You will be performing a `dry-run` command to inspect the workflow that is converted by default. Run the following command within the codespace terminal:
The converted workflow above contains a `codecov_codecov_upload` step that was not automatically converted. Answer the following questions before writing a custom transformer:
- After some research, you have determined that the [Codecov action](https://github.com/marketplace/actions/codecov) in the marketplace will provide similar functionality:
Now you can begin to write the custom transformer. Custom transformers use a DSL built on top of Ruby and should be defined in a file with the `.rb` file extension. You can create this file by running the following command in your codespace terminal:
This method can use any valid Ruby syntax and should return a `Hash` that represents the YAML that should be generated for a given step. GitHub Actions Importer will use this method to convert a step with the provided identifier and will use the `item` parameter for the original values configured in CircleCI.
Now you can perform another `dry-run` command and use the `--custom-transformers` CLI option to provide this custom transformer. Run the following command within your codespace terminal:
The converted workflow that is generated by the above command will now use the custom logic for the `codecov_codecov_upload` step.
```diff
- # # This item has no matching transformer
- # - codecov_codecov_upload:
+ - name: upload coverage to Codecov
+ uses: codecov/codecov-action@v3
+ with:
+ token: "${{ secrets.CODECOV_TOKEN }}"
```
_Note_: If you were unsure what the data structure of `item` was, you could use the following code in the custom transformer to print `item` to the console:
You can use custom transformers to edit the values of environment variables in converted workflows. In this example, you will update the `COVERAGE_DIR` environment variable to be `$RUNNER_TEMP/cov` instead of `./tmp/cov`.
To do this, add the following code to the `transformers.rb` file.
```ruby
env "COVERAGE_DIR", "$RUNNER_TEMP/cov"
```
In this example, the first parameter to the `env` method is the environment variable name and the second is the updated value.
Now you can perform another `dry-run` command with the `--custom-transformers` CLI option. When you open the converted workflow the `COVERAGE_DIR` environment variable will be set to `$RUNNER_TEMP/cov`:
You can also use custom transformers to change the runner for a job that defines a `resource_class` attribute. In the example pipeline, the `setup` job uses a `resource_class` of `large` to dictate the machine used to execute the job. In this scenario, you may want to use this value to perform the `setup` job on a runner with the label of `some-large-runner` in Actions.
In this example, the first parameter to the `runner` method is the resource class value and the second is the label(s) of the runner to use in Actions.
Now you can perform another `dry-run` command with the `--custom-transformers` CLI option. When you open the converted workflow the `runs-on` will be set to `some-large-runner`:
```diff
setup:
runs-on:
- - self-hosted
- - large
+ - some-large-runner
```
At this point, the file contents of `transformers.rb` should match this: