From 8a15d7d17a5bd89cff1fbae2c3e385d67dc6f54f Mon Sep 17 00:00:00 2001 From: Hibariya Date: Tue, 24 Oct 2023 07:42:44 +0900 Subject: [PATCH] Renew the CI workflow Applied the same settings as: - https://github.com/stripe-samples/accept-a-payment/pull/1385 - https://github.com/stripe-samples/accept-a-payment/pull/1612 --- .github/workflows/automerge.yml | 29 ---- .github/workflows/ci.yml | 143 ++++++++++++++---- .../server/python/requirements.txt | 2 +- spec/capybara_support.rb | 5 +- .../server/python/requirements.txt | 2 +- 5 files changed, 119 insertions(+), 62 deletions(-) delete mode 100644 .github/workflows/automerge.yml diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml deleted file mode 100644 index 5f845b52..00000000 --- a/.github/workflows/automerge.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Dependabot auto-merge -on: pull_request - -permissions: - contents: write - pull-requests: write - -jobs: - dependabot: - runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - - name: Dependabot metadata - id: metadata - uses: dependabot/fetch-metadata@v1.1.1 - 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')) && - steps.metadata.outputs.update-type == 'version-update:semver-minor' - run: gh pr merge --auto --merge "$PR_URL" - env: - PR_URL: ${{github.event.pull_request.html_url}} - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f73c968..99ba5070 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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<> $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: @@ -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 @@ -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) @@ -89,7 +138,7 @@ 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 @@ -97,7 +146,8 @@ jobs: docker-compose logs web e2e_test: - runs-on: ubuntu-20.04 + needs: changed_files + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -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) @@ -143,7 +201,7 @@ 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 \ @@ -151,19 +209,46 @@ jobs: || $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/fetch-metadata@v1.1.1 + 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}} diff --git a/fixed-price-subscriptions/server/python/requirements.txt b/fixed-price-subscriptions/server/python/requirements.txt index 4e3e004d..41ab04e0 100644 --- a/fixed-price-subscriptions/server/python/requirements.txt +++ b/fixed-price-subscriptions/server/python/requirements.txt @@ -1,3 +1,3 @@ -Flask==2.2.3 +Flask==3.0.0 python-dotenv==1.0.0 stripe==5.5.0 diff --git a/spec/capybara_support.rb b/spec/capybara_support.rb index 35edd908..f152a5ea 100644 --- a/spec/capybara_support.rb +++ b/spec/capybara_support.rb @@ -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 @@ -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' diff --git a/usage-based-subscriptions/server/python/requirements.txt b/usage-based-subscriptions/server/python/requirements.txt index 4e3e004d..41ab04e0 100644 --- a/usage-based-subscriptions/server/python/requirements.txt +++ b/usage-based-subscriptions/server/python/requirements.txt @@ -1,3 +1,3 @@ -Flask==2.2.3 +Flask==3.0.0 python-dotenv==1.0.0 stripe==5.5.0