diff --git a/.github/workflows/deploy_to_aws.yml b/.github/workflows/deploy_to_aws.yml new file mode 100644 index 0000000000..05220b88ff --- /dev/null +++ b/.github/workflows/deploy_to_aws.yml @@ -0,0 +1,86 @@ +name: "Deploy latest code to AWS" + +on: + push: + branches: + - develop + - master + - preview + - production + +jobs: + determine-environment: + runs-on: ubuntu-latest + outputs: + env_name: ${{ steps.determine_environment.outputs.env_name }} + steps: + - name: Determine the environment to deploy to + id: determine_environment + run: | + echo "Running on branch ${{ github.ref }}" + if [ "${{ github.ref }}" = "refs/heads/master" ]; then + echo "::set-output name=env_name::CMPDEV" + elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then + echo "::set-output name=env_name::Sandbox" + elif [ "${{ github.ref }}" = "refs/heads/preview" ]; then + echo "::set-output name=env_name::Preview" + elif [ "${{ github.ref }}" = "refs/heads/production" ]; then + echo "::set-output name=env_name::Production" + else + echo "::set-output name=env_name::FAIL" + fi + + - name: Fail if not an environment + run: | + echo "ERROR: No environment found" + exit 1 + if: steps.determine_environment.outputs.env_name == 'FAIL' + + - name: Show where we are deploying to + run: echo "We will deploy to ${{ steps.determine_environment.outputs.env_name }}" + + run-unit-tests: + needs: + - determine-environment + uses: ./.github/workflows/unit_tests.yaml + + run-feature-tests: + needs: + - determine-environment + uses: ./.github/workflows/feature_tests.yaml + with: + run_all_feature_tests: true + + deploy-to-application: + runs-on: ubuntu-latest + needs: + - determine-environment + - run-unit-tests + - run-feature-tests + environment: + name: ${{ needs.determine-environment.outputs.env_name }} + steps: + - name: Trigger AWS CodePipeline - main container + uses: tim-s-ccs/aws-codepipeline-action@v0.1.1 + with: + aws-region: ${{ secrets.AWS_PIPELINE_REGION }} + aws-access-key: ${{ secrets.AWS_PIPELINE_ACCESS_KEY }} + aws-secret-key: ${{ secrets.AWS_PIPELINE_SECRET_KEY }} + pipeline-name: ${{ secrets.AWS_PIPELINE_MAIN_NAME }} + + deploy-to-sidekiq: + runs-on: ubuntu-latest + needs: + - determine-environment + - run-unit-tests + - run-feature-tests + environment: + name: ${{ needs.determine-environment.outputs.env_name }} + steps: + - name: Trigger AWS CodePipeline - sidekiq container + uses: tim-s-ccs/aws-codepipeline-action@v0.1.1 + with: + aws-region: ${{ secrets.AWS_PIPELINE_REGION }} + aws-access-key: ${{ secrets.AWS_PIPELINE_ACCESS_KEY }} + aws-secret-key: ${{ secrets.AWS_PIPELINE_SECRET_KEY }} + pipeline-name: ${{ secrets.AWS_PIPELINE_SIDEKIQ_NAME }} diff --git a/.github/workflows/feature_tests.yaml b/.github/workflows/feature_tests.yaml new file mode 100644 index 0000000000..db4de766b2 --- /dev/null +++ b/.github/workflows/feature_tests.yaml @@ -0,0 +1,56 @@ +on: + workflow_call: + inputs: + run_all_feature_tests: + description: 'A trigger to run all the feature tests instead of a subset' + default: false + required: false + type: boolean + +jobs: + feature-test: + runs-on: ubuntu-20.04 + + services: + postgres: + image: postgis/postgis:11-2.5 + ports: + - "5432:5432" + env: + POSTGRES_DB: rails_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + + env: + RAILS_ENV: test + DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test" + CUCUMBER_FORMAT: progress + + steps: + - name: Setup Gecko driver + uses: browser-actions/setup-geckodriver@latest + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1.101.0 + with: + bundler-cache: true + + - name: Set up database schema + run: bin/rails db:test:prepare + + - name: Compile assets + run: bin/rails assets:precompile + + - name: Seed DB with test data + run: bin/rails db:static + + - name: Run feature tests + run: bin/rails cucumber:pipeline + if: ${{ !inputs.run_all_feature_tests }} + + - name: Run all feature tests + run: bin/rails cucumber:ok + if: ${{ inputs.run_all_feature_tests }} diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index affcdc4b16..fb6bc703ac 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -1,95 +1,19 @@ name: "Ruby on Rails CI" on: - - push - - pull_request + push: + branches-ignore: + - develop + - master + - preview + - production + pull_request: jobs: - unit-test: - runs-on: ubuntu-18.04 + run-unit-tests: + uses: ./.github/workflows/unit_tests.yaml - services: - postgres: - image: postgis/postgis:11-2.5 - ports: - - "5432:5432" - env: - POSTGRES_DB: rails_test - POSTGRES_USER: rails - POSTGRES_PASSWORD: password - - env: - RAILS_ENV: test - DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test" - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Install Ruby and gems - uses: ruby/setup-ruby@v1.101.0 - with: - bundler-cache: true - - - name: Set up database schema - run: bin/rails db:test:prepare - - - name: Compile assets - run: bin/rails assets:precompile - - - name: Run unit tests - run: bin/rake - - - name: publish code coverage - uses: paambaati/codeclimate-action@v3.0.0 - with: - debug: true - if: github.event_name == 'pull_request' - - feature-test: - runs-on: ubuntu-18.04 - - services: - postgres: - image: postgis/postgis:11-2.5 - ports: - - "5432:5432" - env: - POSTGRES_DB: rails_test - POSTGRES_USER: rails - POSTGRES_PASSWORD: password - - env: - RAILS_ENV: test - DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test" - CUCUMBER_FORMAT: progress - - steps: - - name: Setup Gecko driver - uses: browser-actions/setup-geckodriver@latest - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Install Ruby and gems - uses: ruby/setup-ruby@v1.101.0 - with: - bundler-cache: true - - - name: Set up database schema - run: bin/rails db:test:prepare - - - name: Compile assets - run: bin/rails assets:precompile - - - name: Seed DB with test data - run: bin/rails db:static - - - name: Run feature tests - run: bin/rails cucumber:pipeline - if: github.event.pull_request.base.ref != 'preview' && github.event.pull_request.base.ref != 'production' - - - name: Run all feature tests - run: bin/rails cucumber:ok - if: github.event.pull_request.base.ref == 'preview' || github.event.pull_request.base.ref == 'production' + run-feature-tests: + uses: ./.github/workflows/feature_tests.yaml + with: + run_all_feature_tests: ${{ github.event.pull_request.base.ref == 'preview' || github.event.pull_request.base.ref == 'production' }} diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml new file mode 100644 index 0000000000..1027de3030 --- /dev/null +++ b/.github/workflows/unit_tests.yaml @@ -0,0 +1,45 @@ +on: + - workflow_call + +jobs: + unit-test: + runs-on: ubuntu-20.04 + + services: + postgres: + image: postgis/postgis:11-2.5 + ports: + - "5432:5432" + env: + POSTGRES_DB: rails_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + + env: + RAILS_ENV: test + DATABASE_URL: "postgis://rails:password@localhost:5432/rails_test" + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1.101.0 + with: + bundler-cache: true + + - name: Set up database schema + run: bin/rails db:test:prepare + + - name: Compile assets + run: bin/rails assets:precompile + + - name: Run unit tests + run: bin/rake + + - name: publish code coverage + uses: paambaati/codeclimate-action@v3.0.0 + with: + debug: true + if: github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master' diff --git a/pipeline_pre_build_tests.sh b/pipeline_pre_build_tests.sh deleted file mode 100644 index ccea373654..0000000000 --- a/pipeline_pre_build_tests.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - -sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' -apt-get update -apt-get install -y build-essential - -apt-get -y install postgis postgresql-10-postgis-2.4 -service postgresql start 10 - -sudo -u postgres createuser --superuser root -sudo -u postgres createdb root - -curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - -curl -sL https://deb.nodesource.com/setup_14.x | bash - -apt-get install -y nodejs -alias node=nodejs -curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - -sh -c 'echo "deb https://dl.yarnpkg.com/debian/ stable main" >> /etc/apt/sources.list.d/yarn.list' -apt-get update -apt-get install -y --no-install-recommends yarn - -PHANTOM_JS="phantomjs-2.1.1-linux-x86_64" -curl -OLk https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 -wget --quiet https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 -tar xvjf $PHANTOM_JS.tar.bz2 -mv $PHANTOM_JS /usr/local/share -ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin -rm -rf $PHANTOM_JS \ No newline at end of file diff --git a/pipeline_run_build_tests.sh b/pipeline_run_build_tests.sh deleted file mode 100644 index ce7110a259..0000000000 --- a/pipeline_run_build_tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -export RAILS_ENV=test -bundle install -yarn install -bundle exec rake db:test:prepare -bundle exec rake assets:precompile -bundle exec rake