GitHub Actions

GitHub Actions provides a convenient way to automate the obfuscation process for your code by allowing you to specify obfuscation tasks as part of your build and deployment pipeline

This example features a basic WebApi application that showcases how to integrate Babel Obfuscator with GitHub Actions seamlessly. The purpose of this integration is to demonstrate how easily Babel Obfuscator can be added to your project using the NuGet package and how to access the license file through GitHub secrets securely.

In addition, this example provides valuable insights on how to configure NuGet to directly access the GitHub package store and install the Babel Obfuscator NuGet package dependency in your project. By following the step-by-step instructions, you can easily implement Babel Obfuscator in your project and benefit from its powerful obfuscation capabilities.

To help you get started, the sample source code is readily available on our GitHub repository, allowing you to explore the integration process in greater detail.

git clone https://github.com/babelfornet/webapi-actions-example.git

Integrating Babel Obfuscator with GitHub Actions requires adding a reference to the Babel Obfuscator NuGet package in your project. This package enables Babel Obfuscator to become part of your build process and obfuscate the target assembly. The package can be downloaded and installed directly from the private GitHub NuGet feed.

To set up the Babel Obfuscator NuGet package in the GitHub package store, you'll need to create an access token with enough privileges to publish, install, and delete NuGet packages from the GitHub package store (see GitHub documentation). You can then use the dotnet CLI tool to push the Babel Obfuscator NuGet package.

dotnet nuget push .\Babel.Obfuscator.nupkg --api-key TOKEN --source https://nuget.pkg.github.com/USERNAME/index.json

In the above command:

  • TOKEN is your personal access token with enough privileges to publish packages.

  • USERNAME with the name of your personal account on GitHub.

To install the Babel Obfuscator NuGet package from the GitHub package store, add the following XML configuration file to your project:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget" value="https://www.nuget.org/api/v2" />
    <add key="github" value="https://nuget.pkg.github.com/USERNAME/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSourceCredentials>
    <github>
      <add key="Username" value="babelfornet" />
      <add key="ClearTextPassword" value="%PACKAGES_TOKEN%" />
    </github>
  </packageSourceCredentials>
</configuration>

In the XML configuration file above:

  • PACKAGES_TOKEN is the environment variable containing your personal access token with privileges to read from the store

  • USERNAME with the name of your personal account on GitHub.

Once you've installed the Babel Obfuscator NuGet package, you can configure GitHub Actions to use it in your continuous integration (CI) workflow. This can be achieved by creating a YAML file in your repository that defines your workflow. The YAML file specifies the steps that will be executed during the CI process, including the build step.

Here's an example YAML file:

name: dotnet package

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet-version: [ '8.0.x' ]

    steps:
      - uses: actions/checkout@v3
      - name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: ${{ matrix.dotnet-version }}
      - name: Install dependencies
        run: dotnet restore
        env:
          PACKAGES_TOKEN: ${{ secrets.PACKAGES_TOKEN }}        
      - name: Build
        run: dotnet build --configuration Release --no-restore
        env:
          BABEL_LICENSE: ${{ secrets.BABEL_LICENSE_SECRET }}

In addition to the package reference, you will also need to set the BABEL_LICENSE environment variable to the path of your license file in your CI workflow. You can do this by adding the following line to your workflow file under the envsection:

BABEL_LICENSE: ${{ secrets.BABEL_LICENSE_SECRET }}

Where the secret BABEL_LICENSE_SECRET contains the license key, which is passed to Babel Obfuscator during the build process by setting the following property in the project file.

<PropertyGroup>
  <BabelLicense>$(BABEL_LICENSE)</BabelLicense>
</PropertyGroup>

You can create the BABEL_LICENSE_SECRET in GitHub repository Settings, under the Security section.

Update the BABEL_LICENSE_SECRET variable to store the received license type.

Floating License

Set the BABEL_LICENSE_SECRET to the floating license key as follow:

BABEL_LICENSE_SECRET=floating:UAZK7-GTO0E-98KR1-CKPUJ

File License

Set the BABEL_LICENSE_SECRET to the path of the license file, for example:

BABEL_LICENSE_SECRET=./Babel/babel.licenses

Overall, this example demonstrates how to integrate Babel Obfuscator with GitHub Actions and highlights the importance of securing access to sensitive information such as license keys.

Last updated