From 82fd13509011193e4463c122a919e7b5653c6415 Mon Sep 17 00:00:00 2001 From: Mauricio Fierro Date: Fri, 8 Dec 2023 12:06:20 -0500 Subject: [PATCH] Add Deploy workflow - Extract tests from the CI workflow into a reusable workflow and call it from the original - Add a deploy workflow to automatically deploy to Fly.io - Call the reusable test workflow from the deploy workflow --- .github/workflows/ci.yml | 28 +++------------------------- .github/workflows/deploy.yml | 17 +++++++++++++++++ .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31b21fa..19c7d28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,27 +1,5 @@ name: CI -on: [push, pull_request] +on: pull_request jobs: - test: - runs-on: ubuntu-latest - services: - redis: - image: redis - ports: ['6379:6379'] - options: --entrypoint redis-server - steps: - - uses: actions/checkout@v4 - - name: Setup Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.2.2 - - name: Build and run tests - env: - REDIS_URL: redis://localhost:6379/0 - RAILS_ENV: test - run: | - sudo apt-get -yqq install libpq-dev - gem install bundler - bundle install --jobs 4 --retry 3 - bundle exec rails db:prepare - bundle exec rails test:all - bundle exec rspec + call-test: + uses: ./.github/workflows/test.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..13110c9 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,17 @@ +name: Deploy +on: + push: + branches: + - main +jobs: + call-test: + uses: ./.github/workflows/test.yml + deploy: + name: Deploy app + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: superfly/flyctl-actions/setup-flyctl@master + - run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..89a5179 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +on: workflow_call +jobs: + test: + runs-on: ubuntu-latest + services: + redis: + image: redis + ports: ['6379:6379'] + options: --entrypoint redis-server + steps: + - uses: actions/checkout@v4 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2.2 + - name: Build and run tests + env: + REDIS_URL: redis://localhost:6379/0 + RAILS_ENV: test + run: | + sudo apt-get -yqq install libpq-dev + gem install bundler + bundle install --jobs 4 --retry 3 + bundle exec rails db:prepare + bundle exec rails test:all + bundle exec rspec