Create a Github Action
This is a nice to have feature.
Problem
I would like to run stripe cli in a Github Action environment. My project is not using Docker, therefore I cannot use the docker image.
Feature
Create an action to run Stripe on Github Action with composite run step Publish it to Github Marketplace
Examples
- name: Setup Stripe CLI
uses: stripe/action
env:
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEVICE_NAME: ${{ secrets.STRIPE_DEVICE_NAME }}
Hi @GrandSchtroumpf,
Could you please give a bit more details of what you are trying to do? You should be able to add a step in your GH action to download/install the stripe cli and use it directly, so I'm trying to understand what you would expect from a "stripe cli action".
Thanks
Hi @pepin-stripe, maybe I'm missing an example then. But I'm not sure how I can achieve that in GitHub action with a windows system for instance.
@GrandSchtroumpf, from the GH Action docs here, you can run any shell script you want, including downloading, installing and running binaries such as the Stripe CLI.
Ok I see. Then this is what I would expect from a GitHub action built by stripe. An existing script that would download, install and run the binary with the secret variables given in env and the arguments provided in with.
I agree that it would be convenient. I'll keep that issue open so we can keep track of it.
it would also be great for the action to inject the webhook signing secret into the environment somehow for stripe listen
Is this feature abandoned? I am trying to build a CI pipeline at the moment to do some end-to-end testing and the stripe CLI is quite difficult for integrating. There is no github action. Unless I am missing something, it seems like the webhook secret is returned only when running the listen command. This makes it kind of difficult to parse and then feed into our API's config.
Agreed! Browser testing using Laravel Dusk in a GH action is quite difficult as of now. Here is how I ended up solving it. This will install Stripe CLI in your Github action and then use stripe listen in the Dusk test. You can (should) probably also add Stripe CLI to the path globally to enable reuse in multiple steps.
#.github/workflows/dusk.yml
- name: Download Stripe CLI
run: |
# Download linux version as per Stripe documentation
curl -L https://github.com/stripe/stripe-cli/releases/download/v1.13.5/stripe_1.13.5_linux_x86_64.tar.gz --output stripe.tar.gz
# Unzip
tar -xvf stripe.tar.gz
- name: Run Dusk Tests
run: |
# Add Stripe CLI to PATH (needs to be done in same step)
export PATH=$PATH:/path/to/working/directory
# Run Dusk tests
php artisan dusk
//tests/Browser/DuskTest.php
private $process;
protected function setUp(): void
{
parent::setUp();
$this->process = new Process(['stripe', 'listen', '--api-key', env('STRIPE_SECRET'), '--forward-to', sprintf('%s/stripe/responses', env('APP_URL'))]);
$this->process->start()
}
protected function tearDown(): void
{
parent::tearDown();
$this->process->stop();
}
For Django I stole the above
- name: Download Stripe CLI
run: |
# Download linux version as per Stripe documentation
curl -L https://github.com/stripe/stripe-cli/releases/download/v1.13.8/stripe_1.13.8_linux_x86_64.tar.gz --output stripe.tar.gz
# Unzip
tar -xvf stripe.tar.gz
and added this to my pytest conftest.py file. You have to make sure the paths are setup correctly
@pytest.fixture
def stripe_cli(live_server):
"""Start the stripe cli with a listen command pointed at our live test server. This allows us to react
to webhooks in our tests. This fixture is function scoped so that the stripe cli is started new at the
beginning of each test. This keeps us from getting unnecessary webhooks during testing."""
stripe_cli = Popen(
["stripe", "listen", f"--api-key={settings.STRIPE_API_KEY}", "--print-secret"],
stdout=PIPE,
stderr=PIPE,
)
stdout, stderr = stripe_cli.communicate(timeout=15)
assert stderr == b""
settings.STRIPE_WEBHOOK_SECRET = stdout.decode().strip()
stripe_cli = Popen(
[
"stripe",
"listen",
"--forward-to",
f"{live_server.url}/api/stripe/webhook/",
f"--api-key={settings.STRIPE_API_KEY}",
"--events=checkout.session.completed,customer.subscription.deleted,customer.subscription.trial_will_end,customer.subscription.updated,invoice.created,invoice.paid,invoice.payment_succeeded",
],
stdout=PIPE,
stderr=PIPE,
)
assert stripe_cli
yield stripe_cli
stripe_cli.terminate()
run: |
PATH=..:$PATH
python manage.py collectstatic --noinput --settings=dubclub.settings.test
pytest -n4 --disable-warnings --durations=20 -m "not only_unmarked"