From 694559e454409aa361969b30fbce6760ecc710e7 Mon Sep 17 00:00:00 2001 From: sau226 <32805612+sau226@users.noreply.github.com> Date: Wed, 14 Dec 2022 14:26:58 +0800 Subject: [PATCH] Migrate CI workflow from CircleCI --- .circleci/config.yml | 336 --------------------------------------- .github/workflows/ci.yml | 117 ++++++++++++++ 2 files changed, 117 insertions(+), 336 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/ci.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 3df3f5de9..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,336 +0,0 @@ -version: 2.1 -jobs: - test-ruby27: - docker: - - image: cimg/ruby:2.7-node - - image: cimg/mysql:8.0 - command: [--default-authentication-plugin=mysql_native_password] - environment: - MYSQL_ROOT_HOST: '%' - MYSQL_ROOT_PASSWORD: 'root' - MYSQL_DATABASE: 'qpixel_test' - - image: cimg/redis:7.0 - - working_directory: ~/qpixel - - steps: - - run: - name: Install packages - command: | - sudo apt-get --allow-releaseinfo-change -qq update - sudo apt-get -y install git libmariadb-dev libmagickwand-dev - - checkout - - restore_cache: - keys: - - qpixel-ruby27-{{ checksum "Gemfile.lock" }} - - qpixel-ruby27- - - run: - name: Install Bundler & gems - command: | - gem install bundler - bundle install --path=~/gems - - run: - name: Clean unnecessary gems - command: | - bundle clean --force - - save_cache: - key: qpixel-ruby27-{{ checksum "Gemfile.lock" }} - paths: - - ~/gems - - run: - name: Copy key - command: | - if [ -z "$MASTER_KEY" ]; then rm config/credentials.yml.enc; else echo "$MASTER_KEY" > config/master.key; fi - - run: - name: Prepare config & database - environment: - RAILS_ENV: test - command: | - cp config/database.sample.yml config/database.yml - cp config/storage.sample.yml config/storage.yml - bundle exec rails db:create - bundle exec rails db:schema:load - bundle exec rails db:migrate - bundle exec rails test:prepare - - run: - name: Current revision - command: | - git rev-parse $(git rev-parse --abbrev-ref HEAD) - - run: - name: Coveralls token - command: | - if [ -z "$COVERALLS_REPO_TOKEN" ]; then echo "Skipping coveralls"; else echo "repo_token: $COVERALLS_REPO_TOKEN" > .coveralls.yml; fi - - run: - name: Test - command: | - bundle exec rails test - - store_test_results: - path: "~/qpixel/test/reports" - system-test-ruby27: - docker: - - image: cimg/ruby:2.7-browsers - - image: cimg/mysql:8.0 - command: [--default-authentication-plugin=mysql_native_password] - environment: - MYSQL_ROOT_HOST: '%' - MYSQL_ROOT_PASSWORD: 'root' - MYSQL_DATABASE: 'qpixel_test' - - image: cimg/redis:7.0 - - working_directory: ~/qpixel - - steps: - - run: - name: Install packages - command: | - sudo apt-get --allow-releaseinfo-change -qq update - sudo apt-get -y install git libmariadb-dev libmagickwand-dev - - checkout - - restore_cache: - keys: - - qpixel-ruby27-{{ checksum "Gemfile.lock" }} - - qpixel-ruby27- - - run: - name: Install Bundler & gems - command: | - gem install bundler - bundle install --path=~/gems - - run: - name: Clean unnecessary gems - command: | - bundle clean --force - - save_cache: - key: qpixel-ruby27-{{ checksum "Gemfile.lock" }} - paths: - - ~/gems - - run: - name: Copy key - command: | - if [ -z "$MASTER_KEY" ]; then rm config/credentials.yml.enc; else echo "$MASTER_KEY" > config/master.key; fi - - run: - name: Prepare config & database - environment: - RAILS_ENV: test - command: | - cp config/database.sample.yml config/database.yml - cp config/storage.sample.yml config/storage.yml - bundle exec rails db:create - bundle exec rails db:schema:load - bundle exec rails db:migrate - bundle exec rails test:prepare - - run: - name: Current revision - command: | - git rev-parse $(git rev-parse --abbrev-ref HEAD) - - run: - name: Test - command: | - bundle exec rails test:system - - store_test_results: - path: "~/qpixel/test/reports" - - store_artifacts: - path: "~/qpixel/tmp/screenshots" - when: on_fail - - test-ruby31: - docker: - - image: cimg/ruby:3.1-node - - image: cimg/mysql:8.0 - command: [ --default-authentication-plugin=mysql_native_password ] - environment: - MYSQL_ROOT_HOST: '%' - MYSQL_ROOT_PASSWORD: 'root' - MYSQL_DATABASE: 'qpixel_test' - - image: cimg/redis:7.0 - - working_directory: ~/qpixel - - steps: - - run: - name: Install packages - command: | - sudo apt-get --allow-releaseinfo-change -qq update - sudo apt-get -y install git libmariadb-dev libmagickwand-dev - - checkout - - restore_cache: - keys: - - qpixel-ruby31-{{ checksum "Gemfile.lock" }} - - qpixel-ruby31- - - run: - name: Install Bundler & gems - command: | - gem install bundler - bundle install --path=~/gems - - run: - name: Clean unnecessary gems - command: | - bundle clean --force - - save_cache: - key: qpixel-ruby31-{{ checksum "Gemfile.lock" }} - paths: - - ~/gems - - run: - name: Copy key - command: | - if [ -z "$MASTER_KEY" ]; then rm config/credentials.yml.enc; else echo "$MASTER_KEY" > config/master.key; fi - - run: - name: Prepare config & database - environment: - RAILS_ENV: test - command: | - cp config/database.sample.yml config/database.yml - cp config/storage.sample.yml config/storage.yml - bundle exec rails db:create - bundle exec rails db:schema:load - bundle exec rails db:migrate - bundle exec rails test:prepare - - run: - name: Current revision - command: | - git rev-parse $(git rev-parse --abbrev-ref HEAD) - - run: - name: Coveralls token - command: | - if [ -z "$COVERALLS_REPO_TOKEN" ]; then echo "Skipping coveralls"; else echo "repo_token: $COVERALLS_REPO_TOKEN" > .coveralls.yml; fi - - run: - name: Test - command: | - bundle exec rails test - - store_test_results: - path: "~/qpixel/test/reports" - system-test-ruby31: - docker: - - image: cimg/ruby:3.1-browsers - - image: cimg/mysql:8.0 - command: [ --default-authentication-plugin=mysql_native_password ] - environment: - MYSQL_ROOT_HOST: '%' - MYSQL_ROOT_PASSWORD: 'root' - MYSQL_DATABASE: 'qpixel_test' - - image: cimg/redis:7.0 - - working_directory: ~/qpixel - - steps: - - run: - name: Install packages - command: | - sudo apt-get --allow-releaseinfo-change -qq update - sudo apt-get -y install git libmariadb-dev libmagickwand-dev - - checkout - - restore_cache: - keys: - - qpixel-ruby31-{{ checksum "Gemfile.lock" }} - - qpixel-ruby31- - - run: - name: Install Bundler & gems - command: | - gem install bundler - bundle install --path=~/gems - - run: - name: Clean unnecessary gems - command: | - bundle clean --force - - save_cache: - key: qpixel-ruby31-{{ checksum "Gemfile.lock" }} - paths: - - ~/gems - - run: - name: Copy key - command: | - if [ -z "$MASTER_KEY" ]; then rm config/credentials.yml.enc; else echo "$MASTER_KEY" > config/master.key; fi - - run: - name: Prepare config & database - environment: - RAILS_ENV: test - command: | - cp config/database.sample.yml config/database.yml - cp config/storage.sample.yml config/storage.yml - bundle exec rails db:create - bundle exec rails db:schema:load - bundle exec rails db:migrate - bundle exec rails test:prepare - - run: - name: Current revision - command: | - git rev-parse $(git rev-parse --abbrev-ref HEAD) - - run: - name: Test - command: | - bundle exec rails test:system - - store_test_results: - path: "~/qpixel/test/reports" - - store_artifacts: - path: "~/qpixel/tmp/screenshots" - when: on_fail - - rubocop: - docker: - - image: cimg/ruby:3.1-node - - working_directory: ~/qpixel - - steps: - - run: - name: Install packages - command: | - sudo apt-get --allow-releaseinfo-change -qq update - sudo apt-get -y install git libmariadb-dev libmagickwand-dev - - checkout - - restore_cache: - keys: - - qpixel-ruby31-{{ checksum "Gemfile.lock" }} - - qpixel-ruby31- - - run: - name: Install Bundler & gems - command: | - gem install bundler - bundle install --path=~/gems - - run: - name: Clean unnecessary gems - command: | - bundle clean --force - - save_cache: - key: qpixel-ruby31-{{ checksum "Gemfile.lock" }} - paths: - - ~/gems - - run: - name: Rubocop - command: | - bundle exec rubocop - - deploy: - docker: - - image: cimg/ruby:3.1-node - - working_directory: ~/qpixel - - steps: - - run: - name: Import SSH key - command: | - echo "$DEV_SSH_KEY" | base64 --decode > ~/deploy.key - chmod 0700 ~/deploy.key - - run: - name: Run deploy - command: | - ssh -o 'StrictHostKeyChecking no' "$SSH_USER"@"$SSH_IP" -p "$SSH_PORT" -i ~/deploy.key "sudo su -l qpixel /var/apps/deploy-dev" - -workflows: - test_lint: - jobs: - - test-ruby27 - - test-ruby31 - - system-test-ruby27 - - system-test-ruby31 - - rubocop - - deploy: - requires: - - test-ruby27 - - test-ruby31 - - system-test-ruby27 - - system-test-ruby31 - - rubocop - filters: - branches: - only: develop diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..ca1e07787 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,117 @@ +name: Test, lint and deploy +on: + push: + branches: + - develop +jobs: + test: + defaults: + run: + working-directory: "~/qpixel" + runs-on: ubuntu-latest + container: + image: cimg/ruby:2.7-node + services: + mysql: + image: cimg/mysql:8.0 + env: + MYSQL_ROOT_HOST: "%" + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: qpixel_test + options: " --default-authentication-plugin=mysql_native_password" + redis: + image: cimg/redis:7.0 + steps: + - name: Install packages + run: |- + sudo apt-get --allow-releaseinfo-change -qq update + sudo apt-get -y install git libmariadb-dev libmagickwand-dev + - uses: actions/checkout@v3.1.0 + - name: restore_cache + uses: actions/cache@v3 + with: + key: qpixel-{{ checksum "Gemfile" }} + restore-keys: |- + qpixel-{{ checksum "Gemfile" }} + qpixel- + path: "~/gems" + - name: Install Bundler & gems + run: |- + gem install bundler + bundle install --path=~/gems + - name: Copy key + env: + MASTER_KEY: ${{ secrets.MASTER_KEY }} + run: echo "$MASTER_KEY" > config/master.key + - name: Prepare config & database + run: |- + cp config/database.sample.yml config/database.yml + cp config/storage.sample.yml config/storage.yml + bundle exec rails db:create + bundle exec rails db:schema:load + bundle exec rails db:migrate + bundle exec rails test:prepare + env: + RAILS_ENV: test + - name: Current revision + run: git rev-parse $(git rev-parse --abbrev-ref HEAD) + - name: Coveralls token + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + run: 'echo "repo_token: $COVERALLS_REPO_TOKEN" > .coveralls.yml' + - name: Test + run: bundle exec rails test + - uses: actions/upload-artifact@v3.1.1 + with: + path: "~/qpixel/test/reports" + rubocop: + defaults: + run: + working-directory: "~/qpixel" + runs-on: ubuntu-latest + container: + image: cimg/ruby:2.7-node + steps: + - name: Install packages + run: |- + sudo apt-get --allow-releaseinfo-change -qq update + sudo apt-get -y install git libmariadb-dev libmagickwand-dev + - uses: actions/checkout@v3.1.0 + - name: restore_cache + uses: actions/cache@v3 + with: + key: qpixel-{{ checksum "Gemfile" }} + restore-keys: |- + qpixel-{{ checksum "Gemfile" }} + qpixel- + path: "~/gems" + - name: Install Bundler & gems + run: |- + gem install bundler + bundle install --path=~/gems + - name: Rubocop + run: bundle exec rubocop + deploy: + if: github.ref == 'refs/heads/develop' + defaults: + run: + working-directory: "~/qpixel" + runs-on: ubuntu-latest + container: + image: cimg/ruby:2.7-node + needs: + - test + - rubocop + steps: + - name: Import SSH key + env: + DEV_SSH_KEY: ${{ secrets.DEV_SSH_KEY }} + run: |- + echo "$DEV_SSH_KEY" | base64 --decode > ~/deploy.key + chmod 0700 ~/deploy.key + - name: Run deploy + env: + SSH_USER: ${{ secrets.SSH_USER }} + SSH_IP: ${{ secrets.SSH_IP }} + SSH_PORT: ${{ secrets.SSH_PORT }} + run: ssh -o 'StrictHostKeyChecking no' "$SSH_USER"@"$SSH_IP" -p "$SSH_PORT" -i ~/deploy.key "sudo su -l qpixel /var/apps/deploy-dev"