The following sections describe the tasks you need to complete to set up a CI/CD process for a Python project with GitHub, GitHub Actions, and the ActiveState Platform. For information specific to Perl, see the blog post.
Before you begin:
state auth
command, in order to run the command to retrieve the API key, and to access your private.key
file if you are using secrets.The State Tool will use the following environment variables if they are defined:
You can obtain an API key by opening a command prompt and running the following State Tool command:
state export new-api-key APIKeyForCI
Example response:
Note that this key is not stored by ActiveState. Please store the value for later use as you cannot retrieve it again.
XYZjMmMwYTgtZWRkOS00ZGRiLThmMWEtNDM4NjlhNzE0MTI0IkNlUnZpQmlQXYZYXYZ
In this example, you would copy the token value on the second line to use as the ACTIVESTATE_API_KEY environment variable in your CI/CD application.
You can find the private key value at <configdir>/activestate/cli-release/private.key
.
The configdir varies per platform, but in most cases will be at one of:
%HOME%\AppData\Roaming\activestate\cli-release\
~/config/activestate/cli-release/
~/Library/Application\ Support/activestate/cli-release/
The private key environment variable expects the contents of the private.key
file, not the filepath.
The ACTIVESTATE_API_KEY is used to authenticate the State Tool automatically whenever required by the CI/CD build steps.
If you’re adding the ACTIVESTATE_PRIVATE_KEY environment variable, you need to open the private.key
file and copy the contents.
-----BEGIN RSA PRIVATE KEY-----
...
3W5OE+S83fcBz1u7pNzgE4UtXJOADW0PtGt7dLnxqxWJbg38mKYMmqwDoD3/HkfH
...
-----END RSA PRIVATE KEY-----
You can use either the Dashboard or the State Tool to create a new project and add the language, platforms, and packages your project requires. Set up your project by:
After you create an ActiveState project, complete the following steps to activate your project and add the configuration file to your code repository, so that the CI/CD has access to it.
state activate <owner/project_name>
. For example: state activate acmetech/python-3-6-6
.activestate.yaml
configuration file to the root directory of your code repository.activestate.yaml
to add any scripts, variables, or secrets you want CI/CD to run or have access to.activestate.yaml
to the repository and check in your changes.Click the Actions tab.
Click Set up a workflow yourself.
Replace the default script with State Tool specific configuration settings. The following example demonstrates how to install the State Tool on both Linux and Windows, and how to run scripts for linting the code and for tests using the State Tool.
# This is a basic workflow to help you get started with GitHub CI using ActivePython
name: ActivePython application on GitHub CI
# Setting up Cache directory and ActiveState Platform API key
env:
ACTIVESTATE_CLI_CACHEDIR: ${{ github.workspace }}/.cache
ACTIVESTATE_API_KEY: ${{ secrets.ACTIVESTATE_API_KEY }}
# Controls when the action will run. Triggers the workflow on push events on the default branch
on: [push]
# A CI workflow is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on (this one is a matrix build)
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Building on both Windows and Linux(Ubuntu) simultaneously
os: [windows-latest, ubuntu-latest]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Installing State Tool on Windows via Powershell
- name: Install State Tool (Windows)
if: matrix.os == 'windows-latest'
run: |
(New-Object Net.WebClient).DownloadFile('https://platform.activestate.com/dl/cli/install.ps1', 'install.ps1');
Invoke-Expression -Command "$Env:GITHUB_WORKSPACE\install.ps1 -n -t $Env:GITHUB_WORKSPACE"
echo "::add-path::$Env:GITHUB_WORKSPACE"
# Installing State Tool on Linux with default shell behavior
- name: Install State Tool (Linux)
if: matrix.os != 'windows-latest'
run: sh <(curl -q https://platform.activestate.com/dl/cli/install.sh) -n
# Checking ActiveState Platform for project updates
- name: Update project
run: state pull
# Caching downloaded build using GitHub CI cache
- name: Cache state tool cache
uses: actions/cache@v1
env:
cache-name: cache-platform-build
with:
path: ${{ env.ACTIVESTATE_CLI_CACHEDIR }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('activestate.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}
# Execute linting of the project on ActivePython
- name: Lint with flake8
run: state run lints
# Running project tests using pytest on ActivePython
- name: Test with pytest
run: state run tests
This setup should work for most Python projects with slight modifications. The YAML elements that could be tweaked include:
activestate.yaml
file.Click Start a Commit and commit the Action configuration file to your repository. Each time you push changes to your code repository the CI/CD process install and launch the State Tool activated environment and run the scripts you have specified.
You can view details for each time the workflow runs in GitHub by clicking the Actions tab, selecting the workflow, and then choosing clicking the title of the event to view. The logs for that event are then displayed.