Flagship Code Analyzer is a CLI and a docker image that can analyze your codebase and detect the usage of Flagship flags, in order to synchronize them with your Flag view in the platform.
export FLAGSHIP_TOKEN=your_token
export ENVIRONMENT_ID=your_env_id
export REPOSITORY_URL=https://gitlab.com/org/repo
export REPOSITORY_BRANCH=master
export DIRECTORY=./
./code-analyzer
docker run -v $(pwd)/your_repo:/your_repo -e FLAGSHIP_TOKEN=your_token -e ENVIRONMENT_ID=your_env_id -e REPOSITORY_URL=https://gitlab.com/org/repo -e REPOSITORY_BRANCH=master -e DIRECTORY=/your_repo flagshipio/code-analyzer
This environment variable contains the Flagship token necessary to send Flag infos to the Flagship Platform
- example :
FLAGSHIP_TOKEN=your_token
This environment variable contains the Flagship environment ID to synchronize flag usage for the matching environment
- example :
ENVIRONMENT_ID=your_flagship_env_id
This environment variable should be set to the root URL of your repository, and is used to track the links of the files where your flags are used
- example :
REPOSITORY_URL=https://gitlab.com/org/repo
- default value: ""
This environment variable should be set to the branch of the code you want to analyse, and is used to track the links of the files where your flags are used
- example :
REPOSITORY_BRANCH=master
- default value: ""
This environment variable should contain a comma separated list of glob to exclude
- example :
FILES_TO_EXCLUDE=".git/*,go.mod,go.sum,main.go,internal/*,example/*"
- default value: ""
This environment variable should contain the directory you want to analyse
- example :
DIRECTORY="."
- default value: "."
You can use the code analyzer to push flag references to your Flagship environment when code is pushed to a specific branch or tag
analyze_flag_references:
image: flagshipio/code-analyzer:master
stage: analyze
variables:
REPOSITORY_URL: $CI_PROJECT_URL
REPOSITORY_BRANCH: $CI_COMMIT_BRANCH
FLAGSHIP_TOKEN: YOUR_FLAGSHIP_TOKEN
ENVIRONMENT_ID: YOUR_ENVIRONMENT_ID
script:
- /root/code-analyser
only:
- master
This repository needs go v1.13+ to work
go mod download
- Go to the example directory, and copy paste a folder you want to analyse
- Create a .env file to customize your environment variable
- Run
go run .go
in the example folder to run the code