Skip to content

Commit

Permalink
Renew the CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hibariya committed Feb 12, 2024
1 parent 73cd403 commit 8a15d7d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 62 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/automerge.yml

This file was deleted.

143 changes: 114 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,62 @@
name: CI for stripe-samples/subscription-use-cases
name: CI
on:
push:
branches:
- fix-ci
- main
- 'main'
pull_request_target:

env:
STRIPE_PUBLISHABLE_KEY: ${{ secrets.TEST_STRIPE_PUBLISHABLE_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
PREMIUM: ${{ secrets.TEST_PREMIUM_PRICE }}
BASIC: ${{ secrets.TEST_BASIC_PRICE }}
MAINTAINERS: |
cecilphillip-stripe
charliegerard-stripe
dependabot[bot]
erinkavanaugh-stripe
hideokamoto-stripe
kevinpeters-stripe
paulasjes-stripe
concurrency:
group: ci-${{ github.ref }}
group: ci-${{ github.event.pull_request.head.ref || github.ref }}
cancel-in-progress: true

jobs:
require-permission:
runs-on: ubuntu-latest
steps:
- name: 'check if the triggering actor is one of the maintainers'
run: |
while read item; do
if [[ "$item" == "${{ github.triggering_actor }}" ]]; then
exit # safe to run tests with write permission
fi
done <<< "$MAINTAINERS"
echo 'CI have to be re-run by one of the $MAINTAINERS' >> $GITHUB_STEP_SUMMARY
exit 1
changed_files:
runs-on: ubuntu-latest
needs: require-permission
outputs:
files: ${{ steps.diff.outputs.files }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.after || github.event.pull_request.head.sha }}
fetch-depth: 0

- name: 'Collect changed files'
id: diff
run: |
echo 'files<<EOF' >> $GITHUB_OUTPUT
git diff --name-only --merge-base origin/main >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
server_test:
runs-on: ubuntu-20.04
needs: changed_files
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -32,7 +72,7 @@ jobs:
- server_type: python
server_image: python:latest
- server_type: python
server_image: python:3.7
server_image: python:3.8
- server_type: java
server_image: maven:latest
- server_type: java
Expand All @@ -58,24 +98,33 @@ jobs:
runtime:
server_type: php-slim
steps:
- id: if_running
run: |
prefix="${{ matrix.target.sample }}/server/${{ matrix.runtime.server_type }}"
if [[ "${{ github.event.pull_request.head.ref || github.ref }}" = "refs/heads/main" ]] || \
[[ $(echo "${{ needs.changed_files.outputs.files }}" | grep -E "^${prefix}") ]]
then echo 'running=true' >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
if: ${{ steps.if_running.outputs.running }}
with:
ref: ${{ github.event.after || github.event.pull_request.head.sha }}

- uses: actions/checkout@v3
if: ${{ steps.if_running.outputs.running }}
with:
repository: 'stripe-samples/sample-ci'
path: 'sample-ci'

- name: Setup dependencies
run: |
source sample-ci/helpers.sh
setup_dependencies
- name: Run tests
if: ${{ steps.if_running.outputs.running }}
run: |
rm -rf usage-based-subscriptions/server/dotnet/ReportUsage # causes "Program.cs(14,28): error CS0017: Program has more than one entry point defined."
source sample-ci/helpers.sh
setup_dependencies
install_docker_compose_settings
export STRIPE_WEBHOOK_SECRET=$(retrieve_webhook_secret)
Expand All @@ -89,15 +138,16 @@ jobs:
docker-compose exec -T runner bundle exec rspec spec/${{ matrix.target.tests }}
- name: Collect debug information
if: ${{ failure() }}
if: ${{ steps.if_running.outputs.running && failure() }}
run: |
cat .env
cat docker-compose.yml
docker-compose ps -a
docker-compose logs web
e2e_test:
runs-on: ubuntu-20.04
needs: changed_files
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
Expand All @@ -114,26 +164,34 @@ jobs:
env:
SERVER_URL: ${{ matrix.implementation.server_url }}
steps:
- id: if_running
run: |
prefix="${{ matrix.target.sample }}/client/${{ matrix.implementation.client_type }}"
if [[ "${{ github.event.pull_request.head.ref || github.ref }}" = "refs/heads/main" ]] || \
[[ $(echo "${{ needs.changed_files.outputs.files }}" | grep -E "^${prefix}") ]]
then echo 'running=true' >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v3
if: ${{ steps.if_running.outputs.running }}
with:
ref: ${{ github.event.after || github.event.pull_request.head.sha }}

- uses: actions/checkout@v3
if: ${{ steps.if_running.outputs.running }}
with:
repository: 'stripe-samples/sample-ci'
path: 'sample-ci'

- name: Setup dependencies
run: |
source sample-ci/helpers.sh
setup_dependencies
- name: Prepare tests
- name: Run tests
if: ${{ steps.if_running.outputs.running }}
run: |
echo "$(cat ${{ matrix.target.sample }}/client/react/package.json | jq '.proxy = "http://web:4242"')" > ${{ matrix.target.sample }}/client/react/package.json
echo "$(cat ${{ matrix.target.sample }}/client/${{ matrix.implementation.client_type }}/package.json | jq '.proxy = "http://web:4242"')" > ${{ matrix.target.sample }}/client/${{ matrix.implementation.client_type }}/package.json
ln -s react-cra sample-ci/docker/react
- name: Run tests
run: |
source sample-ci/helpers.sh
setup_dependencies
install_docker_compose_settings
export STRIPE_WEBHOOK_SECRET=$(retrieve_webhook_secret)
Expand All @@ -143,27 +201,54 @@ jobs:
PREMIUM=${{ secrets.TEST_PREMIUM_PRICE }}
EOF
configure_docker_compose_for_integration "${{ matrix.target.sample }}" node ../../client/${{ matrix.implementation.client_type }} node:14.17
configure_docker_compose_for_integration "${{ matrix.target.sample }}" node ../../client/${{ matrix.implementation.client_type }} node:lts
docker-compose --profile="${{ matrix.implementation.profile }}" up -d && wait_web_server
command="docker-compose exec -T runner bundle exec rspec spec/${{ matrix.target.tests }}"
$command \
|| $command --only-failures \
|| $command --only-failures --format RSpec::Github::Formatter --format progress
- name: Collect debug information
if: ${{ failure() }}
if: ${{ steps.if_running.outputs.running && failure() }}
run: |
cat .env
cat docker-compose.yml
docker-compose ps -a
docker-compose --profile="${{ matrix.implementation.profile }}" logs web
docker-compose --profile="${{ matrix.implementation.profile }}" logs web frontend
docker cp $(docker-compose ps -qa runner | head -1):/work/tmp .
- name: Upload capybara screenshots
if: ${{ failure() }}
if: ${{ steps.if_running.outputs.running && failure() }}
uses: actions/upload-artifact@v2
with:
name: screenshots
path: |
tmp/capybara
auto-merge-dependabot-prs:
if: ${{ github.event.pull_request && github.actor == 'dependabot[bot]' }}
needs:
- server_test
- e2e_test
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
- name: Enable auto-merge for Stripe SDKs
if: |
(contains(steps.metadata.outputs.dependency-names, 'github.com/stripe/stripe-go/v72') ||
contains(steps.metadata.outputs.dependency-names, 'Stripe.net') ||
contains(steps.metadata.outputs.dependency-names, 'com.stripe:stripe-java') ||
contains(steps.metadata.outputs.dependency-names, 'stripe/stripe-php') ||
contains(steps.metadata.outputs.dependency-names, 'stripe'))
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion fixed-price-subscriptions/server/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==2.2.3
Flask==3.0.0
python-dotenv==1.0.0
stripe==5.5.0
5 changes: 3 additions & 2 deletions spec/capybara_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Capybara.server_host = Socket.ip_address_list.detect(&:ipv4_private?).ip_address

Capybara.register_driver :chrome do |app|
opts = {browser: :chrome, url: ENV.fetch('SELENIUM_URL', 'http://selenium:4444/wd/hub')}
browser_options = Selenium::WebDriver::Chrome::Options.new
opts = {browser: :remote, options: browser_options, url: ENV.fetch('SELENIUM_URL', 'http://selenium:4444/wd/hub')}
Capybara::Selenium::Driver.new(app, **opts)
end

Expand All @@ -15,7 +16,7 @@

Capybara.javascript_driver = :chrome
Capybara.default_driver = :chrome
Capybara.default_max_wait_time = 20
Capybara.default_max_wait_time = 25
Capybara.enable_aria_label = true
Capybara.save_path = 'tmp/capybara'

Expand Down
2 changes: 1 addition & 1 deletion usage-based-subscriptions/server/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Flask==2.2.3
Flask==3.0.0
python-dotenv==1.0.0
stripe==5.5.0

0 comments on commit 8a15d7d

Please sign in to comment.