From e429100522a489e371262bbd9cd761d5e7d3e655 Mon Sep 17 00:00:00 2001 From: stephanie rousset Date: Mon, 16 Dec 2024 15:05:20 +0100 Subject: [PATCH] ci: setup CI --- .github/workflows/build_app.yml | 66 +++++++++++ .../ci_additional_authorization_handler.yml | 80 ++++--------- .github/workflows/test_app.yml | 108 ++++++++++++++++++ 3 files changed, 198 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/build_app.yml create mode 100644 .github/workflows/test_app.yml diff --git a/.github/workflows/build_app.yml b/.github/workflows/build_app.yml new file mode 100644 index 0000000..db908ff --- /dev/null +++ b/.github/workflows/build_app.yml @@ -0,0 +1,66 @@ +on: + workflow_call: + inputs: + ruby_version: + description: 'Ruby Version' + default: "3.2.2" + type: string + required: false + node_version: + description: 'Node version' + default: '18.17.1' + required: false + type: string +jobs: + build_app: + name: Build app + runs-on: ubuntu-22.04 + if: "!startsWith(github.head_ref, 'chore/l10n')" + timeout-minutes: 60 + env: + DATABASE_USERNAME: postgres + DATABASE_PASSWORD: postgres + DATABASE_HOST: localhost + RUBYOPT: '-W:no-deprecated' + services: + postgres: + image: postgres:14 + ports: ["5432:5432"] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_PASSWORD: postgres + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ inputs.ruby_version }} + bundler-cache: true + - uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + cache: 'npm' + cache-dependency-path: ./package-lock.json + - uses: actions/cache@v4 + id: app-cache + with: + path: ./spec/decidim_dummy_app/ + key: app-${{ github.sha }} + restore-keys: app-${{ github.sha }} + - run: bundle exec rake test_app + name: Create test app + shell: "bash" + - run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots + name: Create the screenshots folder + shell: "bash" + - run: RAILS_ENV=test bundle exec rails shakapacker:compile + name: Precompile assets + working-directory: ./spec/decidim_dummy_app/ + shell: "bash" + env: + NODE_ENV: "test" diff --git a/.github/workflows/ci_additional_authorization_handler.yml b/.github/workflows/ci_additional_authorization_handler.yml index d41abdf..f2e2613 100644 --- a/.github/workflows/ci_additional_authorization_handler.yml +++ b/.github/workflows/ci_additional_authorization_handler.yml @@ -8,6 +8,9 @@ on: pull_request: branches-ignore: - "chore/l10n*" + paths: + - "*" + - ".github/**" env: CI: "true" @@ -15,63 +18,28 @@ env: NODE_VERSION: 18.17.1 concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: + build_app: + uses: ./.github/workflows/build_app.yml + secrets: inherit + name: Build test application + main: - name: Tests - runs-on: ubuntu-latest - timeout-minutes: 30 - services: - postgres: - image: postgres:14 - ports: ["5432:5432"] - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: - POSTGRES_PASSWORD: postgres - env: - DATABASE_USERNAME: postgres - DATABASE_PASSWORD: postgres - DATABASE_HOST: localhost - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - - name: Get npm cache directory path - id: npm-cache-dir-path - run: echo "dir=$(npm get cache)-additional_authorization_handler" >> $GITHUB_OUTPUT - - uses: actions/cache@v4 - id: npm-cache - with: - path: ${{ steps.npm-cache-dir-path.outputs.dir }} - key: npm-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - npm- - - run: bundle exec rake test_app - name: Create test app - - run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots - name: Create the screenshots folder - - uses: nanasess/setup-chromedriver@v2 - - run: RAILS_ENV=test bundle exec rails shakapacker:compile - name: Precompile assets - working-directory: ./spec/decidim_dummy_app/ - - run: bundle exec rspec - name: RSpec - - uses: codecov/codecov-action@v4 - - uses: actions/upload-artifact@v4 - if: always() - with: - name: screenshots - path: ./spec/decidim_dummy_app/tmp/screenshots - if-no-files-found: ignore + strategy: + fail-fast: false + matrix: + test: + - command: bundle exec parallel_test --type rspec --pattern spec/ --exclude-pattern spec/system + name: "Unit tests" + - command: bundle exec parallel_test --type rspec --pattern spec/system --exclude-pattern spec/system/admin + name: "System tests" + needs: build_app + name: ${{ matrix.test.name }} + uses: ./.github/workflows/test_app.yml + secrets: inherit + with: + working-directory: "decidim-module-addtional_authorization_handler" + test_command: ${{ matrix.test.command }} diff --git a/.github/workflows/test_app.yml b/.github/workflows/test_app.yml new file mode 100644 index 0000000..3aeda34 --- /dev/null +++ b/.github/workflows/test_app.yml @@ -0,0 +1,108 @@ +on: + workflow_call: + inputs: + ruby_version: + description: 'Ruby Version' + default: "3.2.2" + required: false + type: string + working-directory: + required: true + type: string + test_command: + description: 'The testing command to be ran' + required: true + type: string + chrome_version: + description: 'Chrome & Chromedriver version' + required: false + default: "126.0.6478.182" + type: string + +jobs: + build_app: + name: Test + runs-on: ubuntu-latest + if: "!startsWith(github.head_ref, 'chore/l10n')" + timeout-minutes: 60 + env: + DATABASE_USERNAME: postgres + DATABASE_PASSWORD: postgres + DATABASE_HOST: localhost + RUBYOPT: '-W:no-deprecated' + services: + validator: + image: ghcr.io/validator/validator:latest + ports: ["8888:8888"] + postgres: + image: postgres:14 + ports: ["5432:5432"] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_PASSWORD: postgres + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ inputs.ruby_version }} + - run: | + sudo apt update + sudo apt install libu2f-udev + wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_${{inputs.chrome_version}}-1_amd64.deb + sudo dpkg -i /tmp/chrome.deb + rm /tmp/chrome.deb + - uses: nanasess/setup-chromedriver@v2 + with: + chromedriver-version: ${{inputs.chrome_version}} + name: Install Chrome version ${{inputs.chrome_version}} + - uses: actions/cache@v4 + id: app-cache + with: + path: ./spec/decidim_dummy_app/ + key: app-${{ github.sha }} + restore-keys: app-${{ github.sha }} + - run: | + bundle install + bundle exec rake parallel:create parallel:load_schema + name: Parallel tests + shell: "bash" + working-directory: ./spec/decidim_dummy_app/ + - run: | + sudo Xvfb -ac $DISPLAY -screen 0 1920x1084x24 > /dev/null 2>&1 & # optional + ${{ inputs.test_command }} + name: RSpec + working-directory: ${{ inputs.working-directory }} + env: + VALIDATOR_HTML_URI: http://localhost:8888/ + RUBY_VERSION: ${{ inputs.ruby_version }} + DECIDIM_MODULE: ${{ inputs.working-directory }} + DISPLAY: ":99" + CI: "true" + SIMPLECOV: "true" + SHAKAPACKER_RUNTIME_COMPILE: "false" + NODE_ENV: "test" + - uses: codecov/codecov-action@v3 + name: Upload coverage + with: + name: ${{ inputs.working-directory }} + flags: ${{ inputs.working-directory }} + - uses: actions/upload-artifact@v4 + if: always() + with: + name: screenshots + path: ./spec/decidim_dummy_app/tmp/screenshots + if-no-files-found: ignore + overwrite: true