Skip to content

Commit 938569f

Browse files
authored
Merge pull request #21 from PostHog/haacked/set-up-some-scripts
2 parents c1b3c01 + 9407cb1 commit 938569f

File tree

14 files changed

+298
-3
lines changed

14 files changed

+298
-3
lines changed

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
label-version-bump:
99
name: Bump version based on PR label
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
if: |
1212
github.event.pull_request.merged
1313
&& (

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
test:
1010
name: Build and test
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212

1313
strategy:
1414
matrix:

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ posthog-*.tar
2424

2525

2626
# Ignore .env used for local development
27-
.env
27+
.env
28+
29+
# Ignore .DS_Store
30+
.DS_Store

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Posthog.feature_flags("user_123",
137137

138138
## Local Development
139139

140+
Run `bin/setup` to install development dependencies or run the following commands manually:
141+
140142
We recommend using `asdf` to manage Elixir and Erlang versions:
141143

142144
```sh
@@ -148,6 +150,14 @@ mix deps.get
148150
mix compile
149151
```
150152

153+
Run tests:
154+
155+
```sh
156+
bin/test
157+
```
158+
159+
(This runs `mix test`).
160+
151161
### Troubleshooting
152162

153163
If you encounter WX library issues during Erlang installation:
@@ -160,6 +170,10 @@ asdf install
160170

161171
To persist this setting, add it to your shell configuration file (`~/.bashrc`, `~/.zshrc`, or `~/.profile`).
162172

173+
## Examples
174+
175+
There's an example console project in `examples/feature_flag_demo` that shows how to use the client. Follow the instructions in [the README](examples/feature_flag_demo/README.md) to run it.
176+
163177
## Contributing
164178

165179
Contributions are welcome! Please feel free to submit a Pull Request.

bin/helpers/_utils.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error() {
2+
echo "$@" >&2
3+
}
4+
5+
fatal() {
6+
error "$@"
7+
exit 1
8+
}
9+
10+
set_source_and_root_dir() {
11+
{ set +x; } 2>/dev/null
12+
source_dir="$( cd -P "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
13+
root_dir=$(cd $source_dir && cd ../ && pwd)
14+
cd $root_dir
15+
}

bin/setup

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: bin/setup
3+
#/ Description: Sets up the dependencies needed to develop this project
4+
source bin/helpers/_utils.sh
5+
set_source_and_root_dir
6+
7+
if ! command -v asdf &> /dev/null; then
8+
brew install asdf
9+
fi
10+
11+
asdf plugin add erlang
12+
asdf plugin add elixir
13+
asdf install
14+
15+
mix deps.get
16+
mix compile

bin/test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
#/ Usage: bin/test
3+
#/ Description: Runs all the unit tests for this project
4+
source bin/helpers/_utils.sh
5+
set_source_and_root_dir
6+
7+
mix test

examples/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
**/_build/
4+
5+
# If you run "mix test --cover", coverage assets end up here.
6+
**/cover/
7+
8+
# The directory Mix downloads your dependencies sources to.
9+
**/deps/
10+
11+
# Where third-party dependencies like ExDoc output generated docs.
12+
**/doc/
13+
14+
# Ignore .fetch files in case you like to edit your project deps locally.
15+
**/.fetch
16+
17+
# If the VM crashes, it generates a dump, let's ignore it too.
18+
erl_crash.dump
19+
20+
# Also ignore archive artifacts (built via "mix archive.build").
21+
*.ez
22+
23+
# Ignore package tarball (built via "mix hex.build").
24+
**/*.tar
25+
26+
27+
# Ignore .env used for local development
28+
.env
29+
30+
# Ignore .DS_Store
31+
.DS_Store
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# PostHog Feature Flag Demo
2+
3+
A simple console application that demonstrates how to use PostHog's feature flag functionality.
4+
5+
## Setup
6+
7+
1. Make sure you have the required environment variables set:
8+
9+
```bash
10+
export POSTHOG_API_KEY="your_project_api_key"
11+
export POSTHOG_API_URL="https://app.posthog.com" # or your self-hosted instance
12+
```
13+
14+
2. Install dependencies:
15+
16+
```bash
17+
mix deps.get
18+
```
19+
20+
## Usage
21+
22+
Basic usage:
23+
24+
```bash
25+
mix run run.exs --flag "your-feature-flag" --distinct-id "user123"
26+
```
27+
28+
With group properties:
29+
30+
```bash
31+
mix run run.exs --flag "your-feature-flag" --distinct-id "user123" \
32+
--groups '{"company": "company123"}' \
33+
--group_properties '{"company": {"industry": "tech"}}' \
34+
--person_properties '{"email": "user@example.com"}'
35+
```
36+
37+
## Example Output
38+
39+
If the feature flag is enabled:
40+
41+
```bash
42+
Feature flag 'your-feature-flag' is ENABLED
43+
Value: true
44+
```
45+
46+
If the feature flag is disabled:
47+
48+
```bash
49+
Feature flag 'your-feature-flag' is DISABLED
50+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Config
2+
3+
# Remove trailing slash from API URL if present
4+
api_url = System.get_env("POSTHOG_API_URL", "https://app.posthog.com")
5+
api_url = if String.ends_with?(api_url, "/"), do: String.slice(api_url, 0..-2), else: api_url
6+
7+
config :posthog,
8+
api_url: api_url,
9+
api_key: System.get_env("POSTHOG_API_KEY")

0 commit comments

Comments
 (0)